:root {
  --bg: #FFFFFF;
  --surface: #F5F4F2;
  --ink: #23212B;
  --muted: #8A8592;
  --faint: #B9B4BE;
  --line: #E8E6E3;
  --select: rgba(35, 33, 43, .10);
  --bad: #B5534B;

  /* Speed colors. Match the share-card squares. */
  /* Deep enough to carry white letters. */
  --t-purple: #8854C1;
  --brand: #8854C1;
  --dot: #986ACE;
  --t-orange: #DC7A2B;
  --t-red: #CF4A3F;

  --title: 'Rubik', 'Prompt', ui-sans-serif, system-ui, sans-serif;
  --display: 'Rubik', 'Prompt', ui-sans-serif, system-ui, sans-serif;
  --font: 'Prompt', ui-sans-serif, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

/* Dark tokens apply for Auto when the device is dark, or when Dark is chosen in settings. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18171C;
    --surface: #212026;
    --ink: #EDEAE4;
    --muted: #8E8A96;
    --faint: #5A5662;
    --line: #2E2C34;
    --select: rgba(237, 234, 228, .12);
    --brand: #A980DB;
    --dot: #A980DB;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18171C;
  --surface: #212026;
  --ink: #EDEAE4;
  --muted: #8E8A96;
  --faint: #5A5662;
  --line: #2E2C34;
  --select: rgba(237, 234, 228, .12);
  --brand: #A980DB;
  --dot: #A980DB;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; overscroll-behavior: none; }

button { font: inherit; color: inherit; cursor: pointer; }

.app {
  max-width: 440px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 20px calc(env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.top {
  transition: border-color .4s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  opacity: .75;
  transition: opacity .15s, background .15s;
}
.icon-btn:hover, .icon-btn:active { opacity: 1; background: var(--select); }
.icon-btn svg { width: 21px; height: 21px; }

.logo {
  border: 0;
  background: none;
  padding: 4px;
  color: var(--ink);
  font-family: var(--title);
  font-weight: 800;
  font-size: 23px;
  letter-spacing: 0;
  line-height: 1;
  transition: transform .35s cubic-bezier(.2, .8, .3, 1), opacity .3s ease-out;
}

/* The dot on the i in the Six Words title is purple. The color change sits in the gap between dot and stem. */
.i-dot {
  background: linear-gradient(var(--dot) 33%, var(--ink) 33%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- welcome ---------- */

.welcome { display: none; }
.app.welcoming { min-height: 100dvh; }
.app.welcoming .top { border-bottom-color: transparent; }
/* The big title does the job here, so the header one slides up out of view, and back down on Play. */
.app.welcoming .logo {
  transform: translateY(-80px);
  opacity: 0;
  pointer-events: none;
  transition: transform .4s cubic-bezier(.5, 0, .9, .4), opacity .3s ease-in;
}
.app.welcoming > :is(.theme, .hud, .board, .bank, .actions) { display: none; }
.app.welcoming .welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-bottom: 12vh; /* sit a little above true center */
}
.welcome .kicker { margin-bottom: 10px; }
.welcome-title {
  margin: 0 0 14px;
  color: var(--ink);
  font-family: var(--title);
  font-weight: 800;
  font-size: clamp(44px, 14vw, 58px);
  line-height: 1;
}
.welcome-line {
  margin: 0 0 24px;
  max-width: 270px;
  font-size: 18px;
  line-height: 1.4;
}
.welcome-theme { margin-bottom: 28px; }
.welcome-theme-label { font-size: 14px; color: var(--muted); margin-bottom: 2px; }
.welcome-theme-name { font-family: var(--display); font-size: 22px; font-weight: 500; line-height: 1.2; }
.welcome .btn { padding: 13px 56px; font-size: 16px; }
.welcome-time { margin-top: 16px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.welcome-help {
  margin-top: 6px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
/* Everything arrives one piece at a time, with an easy little settle. */
.welcome > * { animation: rise .7s cubic-bezier(.25, 1.25, .45, 1) backwards; }
.welcome > :nth-child(1) { animation-delay: .05s; }
.welcome > :nth-child(2) { animation-delay: .13s; }
.welcome > :nth-child(3) { animation-delay: .21s; }
.welcome > :nth-child(4) { animation-delay: .29s; }
.welcome > :nth-child(5) { animation-delay: .37s; }
.welcome > :nth-child(6) { animation-delay: .45s; }
.welcome > :nth-child(7) { animation-delay: .53s; }
.app.welcoming .icon-btn { animation: fade .7s ease-out .4s backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.96); } }

/* Tapping Play: the welcome pieces drift away, then the game's pieces rise in around the board. */
.app.leaving .welcome { pointer-events: none; }
.app.leaving .welcome > * { animation: leave .24s ease-in forwards; }
@keyframes leave { to { opacity: 0; transform: translateY(-10px); } }
.app.entering > :is(.theme, .hud, .bank, .actions) { animation: rise .55s cubic-bezier(.25, 1.25, .45, 1) backwards; }
.app.entering > .hud { animation-delay: .06s; }
.app.entering > .bank { animation-delay: .14s; }
.app.entering > .actions { animation-delay: .2s; }

/* ---------- theme strip ---------- */

.theme { text-align: center; }
.kicker {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.theme h1 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 22px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0;
}

/* ---------- hud ---------- */

.hud { display: flex; justify-content: center; }
.timer {
  font-size: 22px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
.timer.penalty { animation: penalty .8s; }
@keyframes penalty { 30% { color: var(--bad); } }


/* ---------- board ---------- */

.board {
  position: relative;
  /* Extra touch area around the grid without moving it: edge taps snap to the nearest letter. */
  padding: 14px;
  margin: -14px;
}
.board.live, .board.live .grid { touch-action: none; }
.board.shake { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
}

.grid {
  position: relative;
  aspect-ratio: 1;
  user-select: none;
  -webkit-user-select: none;
}

.ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* Sticks blend where they cross, like highlighter ink. Isolating the group keeps the
   blend between sticks only, so the board color never bleeds in (works in dark mode). */
#ink-found { isolation: isolate; }
.ink .filled { mix-blend-mode: multiply; }
/* A new find wipes in from the first letter to the last. */
.ink .filled.fresh { transform-box: fill-box; transform-origin: left center; animation: wipe .16s cubic-bezier(.25, .46, .45, .94) both; /* ease-out quad */ }
@keyframes wipe { from { transform: scaleX(0); } }
.ink .sel { fill: var(--select); }
.ink .anchor { fill: var(--select); }
.ink .t-purple { fill: var(--t-purple); }
.ink .t-orange { fill: var(--t-orange); } .ink .t-red { fill: var(--t-red); }

.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--size, 8), 1fr);
  grid-template-rows: repeat(var(--size, 8), 1fr);
}
.cell {
  display: grid;
  place-items: center;
  font-family: var(--font);
  font-weight: 400;
  font-size: clamp(15px, 4.6vw, 19px);
  line-height: 1;
  pointer-events: none;
  position: relative;
}
.cell span { position: relative; transition: color .4s; }
.cell.got span { color: #FFFFFF; font-weight: 500; transition: color .15s var(--wipe-delay, 0s); }
/* Letters spin in together when a game starts: fast, with a little overshoot. */
.grid.spin-in .cell span { animation: spinIn .52s cubic-bezier(.3, 1.3, .5, 1) backwards; }
@keyframes spinIn { from { opacity: 0; transform: rotate(-270deg) scale(.5); } }
.cell.pop span { animation: pop .4s ease-out both; }
@keyframes pop { 40% { transform: scale(1.18); } }
.cell.hint::before {
  content: '';
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  animation: hint .7s ease-in-out 3;
}
@keyframes hint { 50% { transform: scale(1.2); opacity: .2; } }

.grid.veiled .cell span { visibility: hidden; }
.grid.veiled .cell::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--line);
}

/* ---------- cover (start / pause) ---------- */

.cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
}
.cover[hidden] { display: none; }
.cover .card { max-width: 270px; }
.cover .big-emoji { font-size: 34px; line-height: 1; margin-bottom: 14px; }
.cover h2 { margin: 0 0 8px; font-family: var(--display); font-size: 22px; font-weight: 500; }
.cover p {
  margin: 0 0 22px;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.4;
  color: var(--ink);
}
.cover .fine { margin-top: 14px; font-size: 12px; letter-spacing: .04em; color: var(--muted); }

/* ---------- word bank ---------- */

.bank {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 10px;
}
.chip {
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .12em;
  line-height: 1.2;
  min-height: 30px; /* room for the split, so finding a word doesn't shift the layout */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.chip .split { font-size: 11px; font-weight: 400; letter-spacing: .02em; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.todo { color: var(--ink); }
.chip.got { color: var(--muted); }
.chip.got .word { text-decoration: line-through; text-decoration-thickness: 2px; }
.chip.got.fresh { animation: fadeIn .5s ease-out; }
@keyframes fadeIn { from { opacity: .3; } }
.chip.t-purple .word { text-decoration-color: var(--t-purple); }
.chip.t-orange .word { text-decoration-color: var(--t-orange); }
.chip.t-red .word { text-decoration-color: var(--t-red); }
.blanks { display: flex; gap: 4px; }
.blanks i { width: 7px; height: 1.5px; background: var(--faint); }

/* ---------- actions ---------- */

.actions { display: flex; justify-content: center; gap: 10px; min-height: 46px; }

.btn {
  font-family: var(--font);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: .02em;
  padding: 12px 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.98); opacity: .85; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.accent { background: var(--t-purple); color: #FFFFFF; border-color: var(--t-purple); }
.btn.quiet { background: none; color: var(--muted); }
.btn.wide { width: 100%; }
.share-btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 34px; }
.share-btn svg { width: 18px; height: 18px; margin-top: -2px; }
.btn small { font-weight: 400; opacity: .7; font-size: 13px; margin-left: 4px; }
.cover .btn.primary { padding: 13px 44px; font-size: 16px; }

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

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 14px);
  transform: translate(-50%, -12px);
  opacity: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .10), 0 0 0 1px var(--line);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
  z-index: 50;
  transition: transform .3s ease, opacity .3s ease;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast b { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 4px; }
.toast.bad { color: var(--bad); }

/* ---------- sheets ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 26, .32);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  animation: fade .25s;
}
.sheet-backdrop[hidden] { display: none; }
/* While a sheet is up, swipes stay in the sheet and never move the page behind it. */
html.sheet-open, html.sheet-open body { overflow: hidden; }
.sheet-backdrop { touch-action: none; }
.sheet { touch-action: pan-y; overscroll-behavior: contain; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  overflow: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 30px 24px calc(env(safe-area-inset-bottom) + 28px);
  animation: up .35s cubic-bezier(.2, .8, .3, 1);
}
@keyframes up { from { transform: translateY(30%); opacity: .6; } }
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .18); }
}
.sheet-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.sheet h2 { margin: 0 0 14px; font-family: var(--display); font-size: 25px; font-weight: 500; line-height: 1.2; }
.sheet p { line-height: 1.55; margin: 0 0 12px; font-size: 15px; }
.sheet .fine { font-size: 12px; color: var(--muted); }

.how { padding-left: 18px; margin: 0 0 16px; line-height: 1.55; font-size: 15px; }
.how li { margin-bottom: 8px; padding-left: 4px; }
.how li::marker { font-family: var(--font); color: var(--muted); }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.sheet h2 + .setting { border-top: 1px solid var(--line); }
.setting + .btn { margin-top: 22px; }
.setting > span { display: flex; flex-direction: column; gap: 3px; }
.setting b { font-weight: 500; }
.setting .fine { line-height: 1.4; }
.setting.locked { opacity: .55; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .2s;
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(18px); }

.segmented {
  display: flex;
  flex: none;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 6px 13px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.segmented input:checked + span { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }
.sheet .btn + .btn { margin-top: 10px; }

/* results */
.res { text-align: center; }
.res .rank { font-size: 30px; margin: 10px 0 14px; line-height: 1.15; }
.res-time { font-family: var(--font); font-size: 54px; font-weight: 400; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.res-sub { color: var(--muted); font-size: 13px; margin: 8px 0 22px; }
.splits { list-style: none; margin: 0 0 20px; padding: 0; text-align: left; border-top: 1px solid var(--line); }
.splits li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.splits .tier { font-size: 15px; text-align: center; }
.splits .word { font-weight: 500; letter-spacing: .1em; font-size: 13px; }
.splits .t { font-variant-numeric: tabular-nums; color: var(--muted); }
.next { margin-top: 16px; color: var(--muted); font-size: 13px; }
.next b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }

/* stats */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 24px; text-align: center; }
.stat-row b { display: block; font-family: var(--font); font-size: 30px; font-weight: 400; }
.stat-row span { font-size: 10px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.dist { display: grid; gap: 7px; margin-bottom: 12px; }
.dist-row { display: grid; grid-template-columns: 128px 1fr; gap: 10px; align-items: center; font-size: 13px; }
.dist-bar {
  background: var(--ink);
  color: var(--bg);
  border-radius: 3px;
  padding: 2px 7px;
  text-align: right;
  min-width: 22px;
  font-size: 11px;
}
.dist-bar.zero { background: var(--line); color: var(--muted); }

/* archive */
.arch { list-style: none; margin: 0 0 12px; padding: 0; border-top: 1px solid var(--line); }
.arch a {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
.arch a.current { background: var(--surface); border-radius: 10px; }
.arch .e { font-size: 20px; text-align: center; }
.arch .t { font-family: var(--font); font-size: 17px; font-weight: 500; line-height: 1.2; }
.arch .d { font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.arch .r { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

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

@media (max-height: 700px) {
  .app { gap: 11px; }
  .theme h1 { font-size: 20px; }
  .chip { min-height: 38px; padding: 5px 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .welcome > *, .app.welcoming .icon-btn, .app.entering > *, .grid.spin-in .cell span { animation: none; }
  .app.leaving .welcome > * { animation: none; opacity: 0; }
}
