:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --page-color: #1b8e2d;
  --text: #111;
  --muted: #686868;
  --line: rgba(17, 17, 17, 0.1);
  --panel-scale: 1;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.24);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--page-color);
  color: var(--text);
  transition: background-color 0.22s ease;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button,
.picker-button,
.swatch,
.saved-swatch {
  touch-action: manipulation;
}

button {
  color: inherit;
}

a {
  color: inherit;
}

.site-brand {
  position: fixed;
  z-index: 3;
  top: calc(10px + var(--safe-top));
  left: calc(14px + var(--safe-left));
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(255, 255, 255, 0.94);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.24);
}

.brand-mark {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.15);
  font-family: "Space Mono", monospace;
}

.page-shell {
  width: 100%;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    calc(45px + var(--safe-top))
    calc(12px + var(--safe-right))
    calc(42px + var(--safe-bottom))
    calc(12px + var(--safe-left));
  overflow: hidden;
}

.color-panel {
  width: min(610px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
  padding: clamp(20px, 3.6vw, 36px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.8));
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(135%);
  -webkit-backdrop-filter: blur(24px) saturate(135%);
  overflow: visible;
  transform: scale(var(--panel-scale));
  transform-origin: center;
  will-change: transform;
  transition: transform 0.14s ease;
}

.panel-topline,
.section-heading,
.action-row,
.adjustment-row,
.dialog-header {
  display: flex;
  align-items: center;
}

.panel-topline,
.section-heading,
.dialog-header {
  justify-content: space-between;
}

.icon-actions {
  display: flex;
  gap: 7px;
}

.eyebrow,
.info-label,
.section-note,
.ad-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  transition: transform 0.14s ease, background-color 0.14s ease;
}

.icon-button:hover {
  background: #fff;
}

#randomButton:hover {
  transform: rotate(18deg);
}

.color-heading {
  display: flex;
  align-items: baseline;
  margin-top: 14px;
  font-family: "Space Mono", monospace;
  font-size: clamp(2.65rem, 9vw, 5.15rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.08em;
}

.hash {
  opacity: 0.32;
  margin-right: 0.05em;
}

.hex-input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-transform: uppercase;
  caret-color: var(--page-color);
}

.url-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.url-hint code {
  color: #222;
  font-family: "Space Mono", monospace;
}

.action-row,
.adjustment-row {
  gap: 8px;
  margin-top: 18px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

.primary-button {
  background: #111;
  color: #fff;
  border-color: #111;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.56);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.09);
}

.picker-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.picker-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.save-button[aria-pressed="true"] {
  background: #111;
  color: #fff;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.info-card {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.48);
}

.info-label {
  display: block;
  margin-bottom: 6px;
}

.info-value,
.copy-value {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-family: "Space Mono", monospace;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copy-value {
  cursor: pointer;
}

.contrast-section,
.palette-section {
  margin-top: 20px;
}

.section-heading h2,
.section-heading h3 {
  margin: 0;
  font-size: 0.9rem;
}

.section-link {
  border: 0;
  padding: 2px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.contrast-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.contrast-chip {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px;
  border-radius: 13px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.8rem;
  font-weight: 700;
}

.contrast-chip strong {
  font-family: "Space Mono", monospace;
  font-size: 0.95rem;
}

.contrast-white {
  background: #fff;
  color: #111;
}

.contrast-black {
  background: #111;
  color: #fff;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.swatch {
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 11px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.13s ease;
}

.swatch:hover,
.swatch:focus-visible {
  transform: translateY(-3px);
}

.swatch::after {
  content: attr(data-label);
  position: absolute;
  inset: auto 4px 4px;
  color: var(--swatch-text);
  font-family: "Space Mono", monospace;
  font-size: 0.5rem;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
}

.adjustment-row {
  justify-content: space-between;
}

.adjustment-row .secondary-button {
  flex: 1;
  padding-inline: 9px;
  font-size: 0.78rem;
}

.toast {
  min-height: 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.site-footer {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: calc(9px + var(--safe-bottom));
  display: flex;
  gap: 13px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.site-footer a {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.7rem;
  font-weight: 600;
  text-decoration: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.3);
}

.site-footer a:hover {
  text-decoration: underline;
}

.tools-dialog {
  width: min(620px, calc(100vw - 24px));
  max-height: min(88dvh, 820px);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  background: rgba(250, 250, 250, 0.96);
  color: var(--text);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.tools-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.dialog-shell {
  max-height: min(88dvh, 820px);
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.dialog-header {
  position: sticky;
  z-index: 2;
  top: -24px;
  margin: -24px -24px 0;
  padding: 22px 24px 14px;
  background: rgba(250, 250, 250, 0.96);
  backdrop-filter: blur(12px);
}

.dialog-header h2 {
  margin: 4px 0 0;
  font-size: 1.4rem;
}

.dialog-section {
  margin-top: 24px;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 10px;
}

.advanced-card {
  min-width: 0;
  min-height: 74px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  white-space: pre-line;
}

.advanced-card::first-line {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.accessibility-table {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
}

.accessibility-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 13px;
  background: #fff;
  font-size: 0.82rem;
}

.accessibility-row + .accessibility-row {
  border-top: 1px solid var(--line);
}

.pass {
  color: #176b2c;
  font-weight: 700;
}

.fail {
  color: #9d2727;
  font-weight: 700;
}

.code-block {
  margin: 10px 0;
  padding: 14px;
  border-radius: 13px;
  background: #111;
  color: #fff;
  font-family: "Space Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.wide-button {
  width: 100%;
}

.saved-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.saved-swatch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px 5px 6px;
  background: #fff;
  cursor: pointer;
  font-family: "Space Mono", monospace;
  font-size: 0.73rem;
  font-weight: 700;
}

.saved-swatch-dot {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 50%;
  background: var(--saved-color);
}

.empty-state {
  color: var(--muted);
  font-size: 0.82rem;
}

.ads-active-mobile .page-shell {
  padding-bottom: calc(108px + var(--safe-bottom));
}

.ads-active-mobile .site-footer {
  bottom: calc(74px + var(--safe-bottom));
}

.ad-slot {
  z-index: 2;
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.76);
  text-align: center;
  backdrop-filter: blur(8px);
}

.ad-slot[hidden] {
  display: none !important;
}

.ad-label {
  display: block;
  margin-bottom: 5px;
  color: inherit;
  font-size: 0.55rem;
}

.ad-rail {
  position: fixed;
  top: 50%;
  right: max(18px, calc((100vw - 1030px) / 2));
  width: 160px;
  min-height: 600px;
  padding: 8px;
  border-radius: 12px;
  transform: translateY(-50%);
}

.ad-mobile {
  position: fixed;
  right: calc(8px + var(--safe-right));
  bottom: calc(34px + var(--safe-bottom));
  left: calc(8px + var(--safe-left));
  min-height: 56px;
  padding: 5px;
  border-radius: 10px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1080px) {
  .ad-rail {
    display: none !important;
  }
}

@media (min-width: 1081px) {
  .ad-mobile {
    display: none !important;
  }
}

@media (max-width: 560px) {
  .page-shell {
    padding-right: calc(8px + var(--safe-right));
    padding-left: calc(8px + var(--safe-left));
  }

  .color-panel {
    width: min(100%, 610px);
    border-radius: 22px;
  }

  .site-brand {
    font-size: 0.78rem;
  }

  .action-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .action-row .primary-button,
  .action-row .secondary-button {
    min-width: 0;
    padding-inline: 5px;
    font-size: 0.75rem;
  }

  .dialog-shell {
    padding: 18px;
  }

  .dialog-header {
    top: -18px;
    margin: -18px -18px 0;
    padding: 17px 18px 12px;
  }
}

@media (max-height: 850px) {
  .color-panel {
    padding-block: 21px;
  }

  .color-heading {
    margin-top: 9px;
    font-size: clamp(2.4rem, 7.8vw, 4.25rem);
  }

  .url-hint {
    margin-top: 7px;
  }

  .action-row,
  .adjustment-row {
    margin-top: 12px;
  }

  .info-grid {
    margin-top: 13px;
  }

  .info-card {
    padding-block: 10px;
  }

  .contrast-section,
  .palette-section {
    margin-top: 14px;
  }

  .contrast-chip {
    min-height: 52px;
    padding-block: 9px;
  }

  .toast {
    margin-top: 6px;
  }
}

@media (max-height: 690px) {
  .page-shell {
    padding-top: calc(37px + var(--safe-top));
    padding-bottom: calc(30px + var(--safe-bottom));
  }

  .site-footer {
    display: none;
  }

  .eyebrow,
  .info-label,
  .section-note {
    font-size: 0.63rem;
  }

  .color-panel {
    padding-block: 15px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
  }

  .color-heading {
    margin-top: 5px;
    font-size: clamp(2.15rem, 6.8vw, 3.55rem);
  }

  .url-hint {
    font-size: 0.7rem;
  }

  .primary-button,
  .secondary-button {
    min-height: 36px;
  }

  .info-grid,
  .contrast-grid,
  .palette {
    gap: 6px;
  }

  .info-grid {
    margin-top: 9px;
  }

  .info-card {
    padding: 8px 10px;
  }

  .contrast-section,
  .palette-section {
    margin-top: 9px;
  }

  .contrast-grid,
  .palette {
    margin-top: 5px;
  }

  .contrast-chip {
    min-height: 43px;
    padding: 7px 10px;
  }

  .swatch {
    border-radius: 8px;
  }

  .adjustment-row {
    margin-top: 9px;
  }

  .toast {
    min-height: 14px;
    font-size: 0.68rem;
  }
}

@media (max-height: 590px) {
  .url-hint {
    display: none;
  }

  .color-heading {
    margin-top: 3px;
  }

  .action-row {
    margin-top: 7px;
  }

  .info-grid {
    margin-top: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
