:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #dcdcdc;
  --hex: #e6e6e6;
  --hex-active: #cfcfcf;
  --honey: #f2c230;
  --honey-dark: #d9a90f;
  --accent: #cf142b;
  --panel: #f6f6f6;
  --toast-bg: #1a1a1a;
  --toast-text: #ffffff;
  /* The hive shrinks on short screens so the Enter button never falls below the fold. */
  --hive-size: min(82vw, 340px, max(200px, calc(100vh - 370px)));
  --hive-size: min(82vw, 340px, max(200px, calc(100dvh - 370px)));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #f0f0f0;
    --muted: #a0a0a0;
    --line: #333333;
    --hex: #2c2c2c;
    --hex-active: #3d3d3d;
    --panel: #1c1c1c;
    --toast-bg: #f0f0f0;
    --toast-text: #121212;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom when tapping quickly */
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.logo {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.logo span { color: var(--honey-dark); }

.topbar-info {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-info .num { font-weight: 700; color: var(--text); }

@media (max-width: 480px) {
  .topbar { gap: 10px; padding: 8px 12px 8px 16px; }
  .logo { font-size: 1.3rem; }
  .topbar-info .year { display: none; }
}

.topbar-buttons { display: flex; gap: 6px; }

.icon-btn, .lang-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: transparent;
  font-weight: 700;
}
.lang-btn { padding: 0 10px; font-size: 0.8rem; }

/* ---------- Ads ---------- */

.ad-slot {
  width: 100%;
  max-width: 970px;
  margin: 8px auto;
  text-align: center;
  overflow: hidden;
}
.ad-slot[hidden] { display: none; }
.ad-slot .adsbygoogle { display: block; width: 100%; height: 60px; }
.ad-slot.placeholder {
  height: 60px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-bottom { margin-top: 24px; }
.ad-bottom .adsbygoogle, .ad-bottom.placeholder { height: 100px; }

@media (min-width: 768px) {
  .ad-slot .adsbygoogle, .ad-slot.placeholder { height: 90px; }
}

/* ---------- Layout ---------- */

.game {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 900px) {
  .game {
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 40px;
    padding-top: 16px;
  }
  .game .status, .game .play { flex: 1; }
}

/* ---------- Your 5 words ---------- */

.score-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0 6px;
  font-weight: 700;
}
.score-head .words-left { flex: 1; color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.score-head strong { font-size: 1.1rem; color: var(--honey-dark); }

.slots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slot {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.slot.empty { border-style: dashed; }
.slot .n { color: var(--muted); font-size: 0.8rem; width: 1em; }
.slot .word { flex: 1; font-weight: 700; text-transform: capitalize; }
.slot .word small {
  display: block;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: none;
}
.slot .pts {
  min-width: 32px;
  height: 26px;
  padding: 0 8px;
  border-radius: 13px;
  background: var(--honey);
  color: #1a1a1a;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot[data-tr] { cursor: pointer; }

@media (max-width: 899px) {
  /* Phones: the 5 slots become a row of compact chips so the hive fits on screen.
     Tapping a word shows its translation. */
  .game { gap: 6px; }
  .score-head { padding: 6px 0 6px; }
  .slots { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .slot { min-height: 34px; padding: 3px 4px 3px 12px; border-radius: 17px; gap: 8px; }
  .slot .n, .slot .word small { display: none; }
  .slot .word { flex: none; }
  .slot .pts { height: 26px; min-width: 26px; padding: 0 7px; }
  .slot.empty { width: 34px; padding: 0; justify-content: center; }
  .slot.empty .n { display: block; width: auto; }
}

/* ---------- Finished ---------- */

.done {
  width: 100%;
  max-width: 420px;
  margin: 16px auto;
  text-align: center;
}
.done h2 { margin: 8px 0 4px; font-size: 1.6rem; }
.done p { margin: 4px 0; }
.done-score { font-size: 2.2rem; font-weight: 800; color: var(--honey-dark); margin: 12px 0 0 !important; }
.done-best { color: var(--muted); font-size: 0.9rem; margin-bottom: 18px !important; }
.done .secondary {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: none;
}
.done .next { margin-top: 18px !important; color: var(--muted); }
.done .next strong { color: var(--text); font-variant-numeric: tabular-nums; }
.dev-reset {
  margin-top: 16px;
  padding: 6px 14px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
}
.dev-reset[hidden] { display: none; }

/* ---------- Word input ---------- */

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.play-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-user-select: none; /* long-pressing a letter shouldn't select text */
  user-select: none;
}
.play-area[hidden], .done[hidden] { display: none; }

.input {
  min-height: 44px;
  margin: 6px 0 2px;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 100%;
}
.input .c { color: var(--honey-dark); }
.input .bad { color: var(--muted); }
.caret {
  width: 2px;
  height: 1.8rem;
  margin-left: 2px;
  background: var(--honey);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.input.shake { animation: shake 0.35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Pinned near the top of the screen so it never covers the word being typed. */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}
.toast.show { opacity: 1; }

/* ---------- Hive ---------- */

.hive {
  position: relative;
  width: var(--hive-size);
  aspect-ratio: 2.5 / 2.598;
  margin: 8px auto;
}

.cell {
  position: absolute;
  width: 40%;
  height: 33.333%;
  padding: 0;
  border: 0;
  background: none;
  transform: scale(0.94);
  transition: transform 0.1s;
  touch-action: manipulation;
}
.cell .hex {
  position: absolute;
  inset: 0;
  background: var(--hex);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  transition: background 0.1s;
}
.cell .letter {
  position: relative;
  font-size: calc(var(--hive-size) * 0.1);
  font-weight: 700;
  text-transform: uppercase;
}
.cell.center .hex { background: var(--honey); }
.cell.center .letter { color: #1a1a1a; }
.cell .value {
  position: absolute;
  right: 27%;
  bottom: 14%;
  font-size: calc(var(--hive-size) * 0.035);
  font-weight: 700;
  color: var(--muted);
}
.cell.center .value { color: #1a1a1a; opacity: 0.6; }
.cell:active { transform: scale(0.88); }
.cell:active .hex { background: var(--hex-active); }
.cell.center:active .hex { background: var(--honey-dark); }
.cell.fade .letter { opacity: 0; }
.cell .letter { transition: opacity 0.15s; }

/* flat-top hexagon positions: centre plus six neighbours */
.cell:nth-child(1) { left: 30%; top: 33.333%; }
.cell:nth-child(2) { left: 30%; top: 0; }
.cell:nth-child(3) { left: 60%; top: 16.667%; }
.cell:nth-child(4) { left: 60%; top: 50%; }
.cell:nth-child(5) { left: 30%; top: 66.667%; }
.cell:nth-child(6) { left: 0; top: 50%; }
.cell:nth-child(7) { left: 0; top: 16.667%; }

/* ---------- Controls ---------- */

.controls {
  display: flex;
  gap: 12px;
  margin: 4px 0 8px;
}
.controls button {
  min-width: 96px;
  height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg);
  font-size: 1rem;
}
.controls button:active { background: var(--panel); }
.controls .round { min-width: 48px; width: 48px; padding: 0; font-size: 1.3rem; }

/* ---------- Footer ---------- */

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 12px 16px 0;
}
.footer p { margin: 4px 0; }
.footer a { color: inherit; }

.load-error {
  width: 100%;
  margin: 48px 0;
  text-align: center;
  color: var(--muted);
}

.intro {
  max-width: 680px;
  margin: 20px auto 0;
  padding: 16px 16px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}
.intro p { margin: 0 0 10px; }
.intro a { color: inherit; }

/* ---------- Dialogs ---------- */

dialog {
  width: min(92vw, 520px);
  max-height: 85dvh;
  border: 0;
  border-radius: 12px;
  padding: 20px 20px 24px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin-top: 0; }
dialog .close {
  float: right;
  border: 0;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
}
dialog ul { padding-left: 20px; }
dialog li { margin: 6px 0; }
dialog .lang-block + .lang-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.rank-table { width: 100%; border-collapse: collapse; margin: 12px 0 18px; }
.rank-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.rank-table td:last-child { text-align: right; color: var(--muted); }
.rank-table tr.current td { font-weight: 700; color: var(--text); }

.primary {
  display: block;
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 24px;
  background: var(--honey);
  color: #1a1a1a;
  font-weight: 700;
}

.mini-hive {
  display: flex;
  gap: 6px;
  margin: 8px 0 12px;
}
.mini-hive span {
  width: 34px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hex);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
}
.mini-hive span.c { background: var(--honey); color: #1a1a1a; }

.word-table { width: 100%; border-collapse: collapse; }
.word-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-transform: capitalize; }
.word-table td small { margin-left: 8px; color: var(--muted); text-transform: none; }
.word-table td:last-child { text-align: right; font-weight: 700; }
.word-table tr.got td:first-child::after { content: " ✓"; color: var(--honey-dark); font-weight: 700; }
