/* Colordle — mobile-first. Every size below is tuned for a phone held one-handed;
   the desktop layout is a max-width column of the same thing. */

:root {
  --bg: #0b0d12;
  --bg-raised: #151922;
  --bg-input: #1d2230;
  --line: #272d3d;
  --text: #eef1f7;
  --muted: #8e97ad;
  --accent: #7c8cff;
  --win: #45c07a;

  --radius: 14px;
  --tap: 44px; /* Apple/Google minimum touch target */

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-raised: #ffffff;
    --bg-input: #eef0f6;
    --line: #dfe3ed;
    --text: #131722;
    --muted: #616b82;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* Kills the ~300ms double-tap-to-zoom delay on taps without taking
     pinch-zoom away the way user-scalable=no would. */
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none; /* no pull-to-refresh mid-guess */
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ------------------------------------------------------------------ shell */

/* dvh, not vh: on mobile Safari/Chrome the URL bar collapses on scroll and vh
   does not follow, which leaves the composer stranded below the fold. */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding-top: var(--safe-t);
}

/* ----------------------------------------------------------------- header */

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 4px;
  flex: none;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.brand span {
  background: linear-gradient(92deg, #ff7a59, #ffc75f 28%, #6ee7b7 55%, #7c8cff 80%, #d67cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.day {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-raised);
  white-space: nowrap;
}

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:active {
  background: var(--bg-raised);
  color: var(--text);
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------ stage */

.stage {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 14px 6px;
}

.wheel-wrap {
  position: relative;
  width: min(52vw, 210px);
  aspect-ratio: 1;
  transition: width 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* When the soft keyboard is up there is no room for a decorative wheel; shrink
   it rather than letting it push the guess list off screen. */
.app.compact .wheel-wrap {
  width: min(30vw, 104px);
}

.wheel {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* inset 32% => radius 36 in the wheel's 200-unit viewBox. Kept in step with
   DOT_MIN in app.js: any larger and it hides the guess dots behind it. */
.mystery {
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(20px, 7vw, 30px);
  font-weight: 700;
  color: var(--muted);
  background: var(--bg-raised);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.5s ease, color 0.3s, box-shadow 0.3s;
}

.mystery.solved {
  color: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 34px -6px currentColor;
  animation: pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
  0% { transform: scale(0.72); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* thermometer ------------------------------------------------------------ */

.meter {
  width: 100%;
  max-width: 320px;
  margin-top: 10px;
}

.meter-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-raised);
  overflow: hidden;
}

/* Single accent, not a hue ramp: this bar sits directly under the wheel, and a
   blue-to-red gradient there competes with the color being guessed. */
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #a3adff);
  transition: width 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.meter-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}

.meter-label b {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ guess list */

.guesses {
  flex: 1 1 auto;
  min-height: 0; /* required or flex children refuse to scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 4px 14px 8px;
  display: flex;
  /* Plain top-down order: the row sequence is chosen in JS (newest first, then
     ranked by closeness), so the DOM order is already the reading order. */
  flex-direction: column;
  gap: 7px;
  justify-content: flex-start;
}

/* The whole chip is the guessed color. A 38px swatch had to compete with the
   wheel, the suggestion list and the meter for attention; at full width the
   color is unambiguous and the list doubles as a palette of where you have
   been. Text color is computed per row from the swatch's luminance. */
.guess {
  position: relative;
  overflow: hidden; /* clips the latest-marker to the rounded corners */
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 10px 15px;
  border-radius: var(--radius);
  /* Keeps very dark and very light guesses from dissolving into the page. */
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.3);
}

/* Only the incoming row animates. Re-sorting rebuilds the list on every guess,
   and animating all of them made the whole board flash. */
.guess.newest {
  animation: slide-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* Marks the pinned row. Without it, a bad guess landing above a much better
   score reads as a broken sort rather than "this is the one you just made".
   currentColor means it works on any swatch without picking a hue of its own. */
.guess.newest::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: currentColor;
  opacity: 0.5;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(9px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Only the suggestion list uses a swatch now; guess rows are the color. */
.swatch {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.28);
}

.guess-body {
  flex: 1;
  min-width: 0;
}

.guess-name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The day's color, named on the winning row when you got there via a different
   but indistinguishable name. */
.answer {
  display: block;
  margin-top: 1px;
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0.72;
}

.guess-score {
  flex: none;
  text-align: right;
}

/* Both inherit the row's contrast color rather than carrying one of their own:
   nothing in the score should encode closeness as a hue. */
.pct {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.delta {
  display: block;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
}

/* The winning row is the answer's own color, so it gets a ring rather than a
   fill to mark it. */
.guess.is-win {
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.3), 0 0 0 2px var(--win);
}

/* -------------------------------------------------------------- composer */

.composer {
  flex: none;
  position: relative;
  padding: 8px 14px calc(8px + var(--safe-b));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

/* Suggestions open upward: the input is pinned to the bottom of the screen and
   anything below it would be under the keyboard. */
.suggestions {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(100% - 8px);
  /* Real cap is set in JS from the space actually left above the composer; a
     viewport-relative value would still overlap the header once the soft
     keyboard has taken half the screen. */
  max-height: 46dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 -14px 40px -12px rgba(0, 0, 0, 0.55);
  display: none;
}

/* column-reverse puts the best match at the *bottom*, right above the input and
   under the thumb, while the DOM keeps best-first order for screen readers and
   for the keyboard cursor. It also anchors scrolling to the bottom for free. */
.suggestions.open {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
}

.suggestion {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: var(--tap);
  padding: 6px 8px;
  border-radius: 10px;
  text-align: left;
}

.suggestion[aria-selected="true"] {
  background: var(--bg-input);
}

.suggestion-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion mark {
  background: none;
  color: var(--accent);
  font-weight: 700;
}

.suggestion .used {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  flex: none;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 5px 5px 5px 12px;
}

.input-row:focus-within {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Live preview of whatever name is currently resolvable — instant feedback that
   the thing you typed is a real color, before you commit a guess. */
.preview {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
  background: var(--bg-raised);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.2s;
}

#field {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text);
  /* 16px minimum or iOS Safari zooms the whole page on focus. */
  font-size: 16px;
  padding: 10px 0;
}

#field::placeholder {
  color: var(--muted);
}

.go {
  flex: none;
  min-width: 68px;
  height: var(--tap);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  transition: opacity 0.15s, transform 0.1s;
}

.go:disabled {
  opacity: 0.35;
}

.go:not(:disabled):active {
  transform: scale(0.96);
}

.composer.done .input-row,
.composer.done .suggestions {
  display: none;
}

.after {
  display: none;
  gap: 8px;
}

.composer.done .after {
  display: flex;
}

.after button {
  flex: 1;
  height: var(--tap);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
  background: var(--bg-raised);
}

.after .primary {
  background: var(--win);
  color: #06210f;
}

/* ---------------------------------------------------------------- dialogs */

dialog {
  border: 0;
  padding: 0;
  background: none;
  max-height: 100dvh;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.sheet {
  width: min(94vw, 460px);
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px calc(20px + var(--safe-b));
  border-radius: 20px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
}

/* Full-width bottom sheet on phones — reachable with a thumb.
   The width/max-width reset is required: the UA stylesheet caps dialogs at
   calc(100% - 6px - 2em), which clips a 100vw sheet and takes the close button
   off screen with it. */
@media (max-width: 520px) {
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
  }
  .sheet {
    width: 100%;
    border-radius: 20px 20px 0 0;
  }
  dialog[open] .sheet {
    animation: rise 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  @keyframes rise {
    from { transform: translateY(18px); opacity: 0.5; }
  }
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.sheet p {
  color: var(--muted);
  font-size: 14.5px;
  margin: 0 0 14px;
}

.sheet .close {
  position: sticky;
  top: 0;
  float: right;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-input);
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
}

.rules {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 13px;
}

.rules li {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  font-size: 14.5px;
}

.rules .n {
  flex: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-input);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.rules b {
  display: block;
}

.rules small {
  color: var(--muted);
  font-size: 13.5px;
}

/* stats ------------------------------------------------------------------ */

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.stat {
  text-align: center;
  padding: 10px 2px;
  border-radius: 12px;
  background: var(--bg-input);
}

.stat b {
  display: block;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dist {
  display: grid;
  gap: 5px;
}

.dist-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.dist-bar {
  height: 21px;
  min-width: 26px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 7px;
  transition: width 0.4s;
}

.dist-row.here .dist-bar {
  background: var(--win);
  color: #06210f;
}

/* win sheet -------------------------------------------------------------- */

.reveal {
  height: 104px;
  border-radius: 16px;
  margin-bottom: 14px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.25);
}

.reveal b {
  font-size: 21px;
  font-weight: 800;
  padding: 7px 15px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  backdrop-filter: blur(4px);
}

.rank {
  text-align: center;
  font-size: 15px;
  margin-bottom: 14px;
  color: var(--muted);
}

.rank b {
  color: var(--text);
}

/* toast ------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* confetti --------------------------------------------------------------- */

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.confetti i {
  position: absolute;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes fall {
  from { transform: translateY(-8vh) rotate(0deg); opacity: 1; }
  to { transform: translateY(104vh) rotate(720deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .confetti { display: none; }
}

/* Landscape phones have almost no vertical room; drop the wheel entirely. */
@media (max-height: 460px) {
  .wheel-wrap { display: none; }
  .stage { padding-top: 0; }
}
