:root {
  --bg: #ffffff;
  --fg: #231d12;          /* ink, a touch of propolis brown */
  --muted: #7a6f5c;
  --line: #e4dccb;
  --cell: #efe9dc;        /* beeswax */
  --cell-hover: #e5dcc8;
  --center: #f5c518;      /* honey */
  --center-fg: #231d12;
  --panel: #faf7f0;
  --toast-bg: #231d12;
  --toast-fg: #ffffff;
  --pangram: #b88a00;
  --display: "Rubik", "Helvetica Neue", Arial, sans-serif;
  --text: "Source Sans 3", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1910;        /* the hive at night */
    --fg: #f3ecdc;
    --muted: #a89d86;
    --line: #3d3526;
    --cell: #352e20;
    --cell-hover: #43392a;
    --panel: #241f15;
    --toast-bg: #f3ecdc;
    --toast-fg: #1d1910;
    --pangram: #f5c518;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 26px; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 14px;
}
.pill:hover { background: var(--cell); }
.pill.icon { width: 34px; padding: 6px 0; font-weight: 700; }
.script-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.script-switch button {
  background: none; border: none; border-radius: 999px; padding: 4px 10px; font-size: 14px; color: var(--muted);
}
.script-switch button[aria-pressed="true"] { background: var(--cell); color: var(--fg); font-weight: 600; }
button:focus-visible { outline: 2px solid var(--pangram); outline-offset: 2px; }
.subtitle {
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline;
  margin: 10px 16px 0; color: var(--muted); font-size: 14px;
}
.back-today { color: var(--fg); font-weight: 600; }
.back-today[hidden] { display: none; }

/* ---------- Layout ---------- */
.game {
  display: flex; gap: 40px; justify-content: center; align-items: flex-start;
  max-width: 1040px; margin: 0 auto; padding: 24px 16px;
}
.play { flex: 0 0 auto; width: 340px; display: flex; flex-direction: column; align-items: center; position: relative; }
.side { flex: 1 1 auto; max-width: 560px; min-width: 0; }
@media (max-width: 760px) {
  .game { flex-direction: column-reverse; align-items: stretch; gap: 16px; padding-top: 12px; }
  .play { width: 100%; }
  .side { max-width: none; }
}

/* ---------- Toast ---------- */
.toast {
  height: 34px; display: flex; align-items: center; justify-content: center;
}
.toast span {
  background: var(--toast-bg); color: var(--toast-fg);
  padding: 7px 12px; border-radius: 4px; font-size: 14px; font-weight: 600;
  animation: toast-in .15s ease-out;
}
.toast span.pangram { background: var(--center); color: var(--center-fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Input ---------- */
.input {
  min-height: 44px; font-family: var(--display); font-size: 30px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; display: flex; align-items: center; justify-content: center;
  margin: 6px 0 18px; max-width: 100%; overflow: hidden;
}
.input .c { color: var(--pangram); }
.input .bad { color: var(--line); }
.caret {
  display: inline-block; width: 2px; height: 32px; background: var(--center); margin-left: 2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.input.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---------- Hive ---------- */
.hive { position: relative; width: 270px; height: 270px; }
.cell {
  position: absolute; width: 90px; height: 78px; border: none; padding: 0;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: var(--cell); font-family: var(--display); font-size: 28px; font-weight: 600; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s;
}
.cell:hover { background: var(--cell-hover); }
.cell:active { transform: scale(.92); }
.cell.center { background: var(--center); color: var(--center-fg); }
.cell .l { transition: opacity .2s; }
.hive.shuffling .cell:not(.center) .l { opacity: 0; }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 10px; margin-top: 22px; }
.ctrl {
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  height: 52px; min-width: 96px; padding: 0 18px; font-size: 16px;
}
.ctrl:hover { background: var(--cell); }
.ctrl.round { min-width: 52px; width: 52px; padding: 0; font-size: 22px; }

/* ---------- Rank ---------- */
.rank { display: flex; align-items: center; gap: 14px; }
.rank-name {
  background: none; border: none; padding: 0; font-family: var(--display); font-weight: 600;
  font-size: 16px; min-width: 116px; text-align: left;
}
.rank-track { position: relative; flex: 1; height: 52px; margin: 0 10px 0 24px; }
.rank-track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 17px; height: 2px; background: var(--line); border-radius: 2px;
}
.rank-fill {
  position: absolute; left: 0; top: 17px; height: 2px; background: var(--center); border-radius: 2px;
  transition: width .4s cubic-bezier(.2, .8, .2, 1);
}
.rank-step { position: absolute; top: 18px; width: 0; height: 0; }
.rank-step::before {
  content: ""; position: absolute; left: -6px; top: -6px; width: 12px; height: 11px; background: var(--line);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
.rank-step.done::before { background: var(--center); }
.rank-step.next::before { background: var(--muted); }
.rank-step.last::before { left: -8px; top: -8px; width: 16px; height: 15px; }
.rank-step b {
  position: absolute; top: 19px; left: 0; transform: translateX(-50%);
  font-size: 11px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.rank-step.done b { color: var(--fg); font-weight: 400; }
.rank-step.next b { color: var(--fg); font-weight: 700; }
.rank-score {
  position: absolute; top: 18px; width: 38px; height: 33px; transform: translate(-50%, -50%);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: var(--center); color: var(--center-fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  transition: left .4s cubic-bezier(.2, .8, .2, 1);
}
.share {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
}
.share:hover { background: var(--cell); }
.rank-next { margin: 2px 0 14px; font-size: 14px; color: var(--muted); min-height: 20px; }

/* ---------- Found words ---------- */
.found { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; min-height: 120px; }
.found-head {
  display: flex; width: 100%; justify-content: space-between; align-items: center;
  background: none; border: none; padding: 0; margin-bottom: 10px; font-size: 15px; text-align: left; cursor: default;
}
.found-head .chev { display: none; color: var(--muted); transition: transform .2s; }
.found-list {
  list-style: none; margin: 0; padding: 0;
  columns: 3 120px; column-gap: 20px;
}
.found-list li {
  border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 15px;
  text-transform: capitalize; break-inside: avoid;
}
.found-list li.pg { font-weight: 700; }
@media (max-width: 760px) { .found-list { columns: 2 110px; } }

/* ---------- Modal ---------- */
dialog {
  border: none; border-radius: 10px; padding: 28px 24px 22px; max-width: min(520px, calc(100vw - 32px));
  max-height: 85vh; background: var(--bg); color: var(--fg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%;
  background: none; border: none; display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--cell); }
.modal-close .ico { width: 20px; height: 20px; }
.muted { color: var(--muted); }
dialog h2 { margin: 0 0 12px; font-family: var(--display); font-weight: 700; }
dialog h3 { margin: 18px 0 6px; font-size: 15px; }
dialog p, dialog li { line-height: 1.5; font-size: 15px; }
dialog ul { padding-left: 20px; }
.rank-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.rank-table td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.rank-table td:last-child { text-align: right; }
.rank-table tr.current td { font-weight: 700; }
.mini-hive { display: flex; gap: 4px; margin: 6px 0 12px; }
.mini-hive span {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: var(--cell); border-radius: 4px; font-weight: 700; text-transform: uppercase; font-size: 14px;
}
.mini-hive span.center { background: var(--center); color: var(--center-fg); }
.answers { columns: 2; column-gap: 20px; list-style: none; padding: 0 !important; }
.answers li { text-transform: capitalize; }
.answers li.got { color: var(--muted); text-decoration: line-through; }
.answers li.pg { font-weight: 700; }

/* ---------- Ad slot ---------- */
.ad-slot { margin-top: 20px; min-height: 100px; text-align: center; }
.ad-slot:empty { display: none; }

/* ---------- Phone tweaks ---------- */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 8px; }
  .topbar h1 { font-size: 22px; }
  .topbar-actions { gap: 6px; }
  .pill { padding: 4px 8px; font-size: 12.5px; }
  .script-switch button { padding: 2px 7px; font-size: 12.5px; }
  .pill.icon { width: 27px; }
  .subtitle { margin-top: 8px; font-size: 13px; }
  .found { min-height: 0; padding: 10px 14px; }
  .found-head { margin: 0; cursor: pointer; }
  .found-head .chev { display: block; }
  .found.open .found-head { margin-bottom: 10px; }
  .found.open .found-head .chev { transform: rotate(180deg); }
  .found:not(.open) .found-list { display: none; }
  .rank { gap: 10px; }
  .rank-name { min-width: 0; font-size: 15px; }
  .rank-step b { font-size: 10px; }
  .hive { transform: scale(.95); }
}

/* ---------- Small animations (all switched off by prefers-reduced-motion above) ---------- */
.hive .cell { animation: cell-in .35s cubic-bezier(.3, 1.4, .5, 1) both; animation-delay: calc(var(--i) * 40ms); }
@keyframes cell-in { from { transform: scale(.4); opacity: 0; } }
.hive .cell.pressed { animation: cell-press .18s ease-out; }
@keyframes cell-press { 50% { transform: scale(.9); } }
.hive.ripple .cell { animation: cell-ripple .5s ease-in-out both; animation-delay: calc(var(--i) * 60ms); }
@keyframes cell-ripple { 40% { transform: scale(1.12); } }
.input .pop { display: inline-block; animation: letter-pop .15s ease-out; }
@keyframes letter-pop { from { transform: translateY(6px) scale(.7); opacity: 0; } }
.rank-score.bump { animation: bump .4s ease-out; }
@keyframes bump { 40% { transform: translate(-50%, -50%) scale(1.2); } }
.found-list li.new { animation: word-new 1.2s ease-out; }
@keyframes word-new { from { background: var(--center); color: var(--center-fg); } }

/* ---------- Footer ---------- */
.site-footer { text-align: center; padding: 8px 16px 24px; font-size: 13px; }
.site-footer a { color: var(--muted); }
.site-footer > a + a { margin-left: 16px; }
.site-footer .credit { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- Icons ---------- */
.ico {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.pill { display: inline-flex; align-items: center; gap: 6px; }
.pill.icon { justify-content: center; }
.ctrl.round { display: inline-flex; align-items: center; justify-content: center; }
.ctrl.round .ico { width: 22px; height: 22px; }

/* ---------- Archive ---------- */
.arch-random { margin: 4px 0 14px; }
dialog details { border-top: 1px solid var(--line); }
dialog summary {
  padding: 10px 0; font-weight: 600; cursor: pointer; text-transform: capitalize; list-style-position: inside;
}
.arch-list { list-style: none; padding: 0 !important; margin: 0 0 10px; }
.arch-row {
  display: grid; grid-template-columns: 3.2em 1fr auto; gap: 10px; align-items: baseline;
  width: 100%; padding: 8px 6px; background: none; border: none; border-radius: 6px; text-align: left; font-size: 15px;
}
.arch-row:hover { background: var(--cell); }
.arch-row.current { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.arch-day { font-weight: 600; font-variant-numeric: tabular-nums; }
.arch-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.arch-state { font-size: 13px; color: var(--muted); }
.arch-state.started { color: var(--fg); font-weight: 600; }

/* ---------- Browser surfaces ---------- */
html { scrollbar-color: var(--line) transparent; accent-color: var(--center); }
::selection { background: var(--center); color: var(--center-fg); }
a { text-underline-offset: 3px; text-decoration-thickness: 1px; }
.found-list li.rare { color: var(--muted); font-style: italic; }
