:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --muted: #787c7e;
  --border: #d3d6da;
  --border-filled: #878a8c;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --danger: #d9443b;
  --key: #d3d6da;
  --key-text: #1a1a1b;
  --on-color: #ffffff;
  --surface: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  --toast-bg: #1a1a1b;
  --toast-text: #ffffff;
  --shark-ink: #1a2226;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121213;
    --text: #f8f8f8;
    --muted: #818384;
    --border: #3a3a3c;
    --border-filled: #565758;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --danger: #e5584f;
    --key: #818384;
    --key-text: #ffffff;
    --surface: #1d1d1f;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    --toast-bg: #f8f8f8;
    --toast-text: #121213;
    --shark-ink: #e6eeef;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121213;
  --text: #f8f8f8;
  --muted: #818384;
  --border: #3a3a3c;
  --border-filled: #565758;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --danger: #e5584f;
  --key: #818384;
  --key-text: #ffffff;
  --surface: #1d1d1f;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  --toast-bg: #f8f8f8;
  --toast-text: #121213;
  --shark-ink: #e6eeef;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Shark background: fixed behind everything, faded so the board stays readable */
#sea {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: -1;
  opacity: 0.35;
  pointer-events: none;
}

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

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: 0.01em; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 2px solid var(--text);
  border-radius: 50%;
  background: none;
  font-weight: 700; font-size: 17px;
}
#theme-btn { border-color: transparent; font-size: 20px; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 14px;
  padding: 12px 16px;
  min-height: 0;
  overflow-y: auto; /* on very short or landscape screens the board scrolls instead of shrinking away */
}

.banner {
  margin: 0;
  padding: 8px 16px;
  background: var(--present);
  color: var(--on-color);
  font-weight: 600; font-size: 14px; text-align: center;
}
.banner a { color: inherit; font-weight: 800; }

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

/* Round pills */
.pills { display: flex; gap: 8px; margin: 0; padding: 0; list-style: none; }
.pills li {
  min-width: 34px; padding: 4px 10px;
  border: 2px solid var(--border);
  border-radius: 99px;
  color: var(--muted);
  font-size: 13px; font-weight: 700; text-align: center;
}
.pills li.current { background: var(--text); border-color: var(--text); color: var(--bg); }
.pills li.won { background: var(--correct); border-color: var(--correct); color: var(--on-color); }
.pills li.lost { background: var(--absent); border-color: var(--absent); color: var(--on-color); text-decoration: line-through; }

/* Row timer */
.timer { display: flex; align-items: center; gap: 10px; width: min(100%, 280px); }
.timer.off { visibility: hidden; }
.timer-bar { flex: 1; height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.timer-bar span {
  display: block; height: 100%;
  background: var(--correct);
  transform-origin: left;
  transform: scaleX(var(--left, 1));
  transition: transform 0.1s linear;
}
.timer.low .timer-bar span { background: var(--danger); }
#timer-text { min-width: 3ch; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.timer.low #timer-text { color: var(--danger); }
/* Held after a reload */
.timer.frozen .timer-bar span { background: var(--muted); }
.timer.frozen #timer-text { color: var(--muted); }

/* Board */
.board {
  --cols: 4;
  --gap: 6px;
  --size: max(32px, min(58px, calc((100vw - 32px - 5 * var(--gap)) / 6), calc((100dvh - 424px - env(safe-area-inset-bottom)) / 6)));
  display: grid;
  grid-template-rows: repeat(5, var(--size));
  gap: var(--gap);
}
.row { display: grid; grid-template-columns: repeat(var(--cols), var(--size)); gap: var(--gap); }
.row.shake { animation: shake 0.3s; }

.tile {
  display: grid; place-items: center;
  width: var(--size, 40px); height: var(--size, 40px);
  border: 2px solid var(--border);
  font-size: calc(var(--size, 40px) * 0.55);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}
.tile.filled { border-color: var(--border-filled); }
.tile.filled.pop { animation: pop 0.1s; }
.tile.correct, .tile.present, .tile.absent { color: var(--on-color); }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent { background: var(--absent); border-color: var(--absent); }
.tile.reveal { animation: flip 0.4s ease backwards; }

@keyframes flip {
  0% { transform: rotateX(0); background: var(--bg); border-color: var(--border-filled); color: var(--text); }
  49% { background: var(--bg); border-color: var(--border-filled); color: var(--text); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Panel under the board */
.panel { min-height: 46px; display: flex; align-items: center; gap: 12px; }
.panel p { margin: 0; font-weight: 600; }
.panel b { letter-spacing: 0.06em; }

.primary {
  border: 0; border-radius: 99px;
  padding: 11px 22px;
  background: var(--correct);
  color: var(--on-color);
  font-weight: 700; font-size: 16px;
}
.primary:focus-visible, .icon-btn:focus-visible, .key:focus-visible { outline: 3px solid var(--present); outline-offset: 2px; }

/* Keyboard */
.keyboard {
  width: 100%; max-width: 500px;
  margin: 0 auto;
  padding: 0 6px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 7px;
  user-select: none;
}
.kb-row { display: flex; gap: 5px; }
.kb-row.middle { padding: 0 5%; }
.key {
  flex: 1;
  height: 56px;
  border: 0; border-radius: 4px;
  background: var(--key);
  color: var(--key-text);
  font-size: 14px; font-weight: 700;
  text-transform: uppercase;
  touch-action: manipulation;
}
.key.wide { flex: 1.5; font-size: 12px; }
.key.correct { background: var(--correct); color: var(--on-color); }
.key.present { background: var(--present); color: var(--on-color); }
.key.absent { background: var(--absent); color: var(--on-color); }

/* Toast */
.toast {
  position: fixed; top: 68px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--toast-bg); color: var(--toast-text);
  font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; }

/* Dialogs */
dialog {
  width: min(400px, calc(100vw - 32px));
  border: 0; border-radius: 10px;
  padding: 24px 22px 22px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  text-align: center;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 12px; font-size: 22px; }
dialog p { margin: 10px 0; line-height: 1.45; }
dialog .close {
  position: absolute; top: 8px; right: 10px;
  border: 0; background: none;
  font-size: 26px; line-height: 1; color: var(--muted);
}
.example { display: flex; justify-content: center; gap: 5px; margin: 14px 0 6px; --size: 40px; }
.eyebrow { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 13px; }
.big-score { font-size: 56px; font-weight: 800; margin: 0 !important; }
.answers { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.answers li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px; background: var(--bg); }
.answers .word { font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.answers .won { color: var(--correct); font-weight: 700; }
.answers .lost { color: var(--muted); font-weight: 700; }
.countdown { color: var(--muted); font-variant-numeric: tabular-nums; }
.rate p { margin: 4px 0 8px; font-weight: 600; }
.rate-buttons { display: flex; justify-content: center; gap: 6px; }
.rate-buttons button {
  width: 44px; height: 40px;
  border: 2px solid var(--border); border-radius: 6px;
  background: none; color: var(--text);
  font-weight: 800; font-size: 16px;
}
.rate-buttons button[aria-pressed="true"] { background: var(--correct); border-color: var(--correct); color: var(--on-color); }
.rate-buttons button:focus-visible { outline: 3px solid var(--present); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .tile.reveal, .tile.filled.pop, .row.shake { animation: none; }
}

/* Short screens (e.g. phones in landscape): smaller keys leave room for the board. */
@media (max-height: 600px) {
  .key { height: 42px; }
  .keyboard { gap: 5px; }
}

/* Privacy page (privacy.html) */
a.icon-btn { color: var(--text); text-decoration: none; }
.topbar .spacer { visibility: hidden; }
main.policy {
  display: block;
  flex: 1 0 auto;
  overflow: visible;
  width: 100%; max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px calc(40px + env(safe-area-inset-bottom));
  line-height: 1.55;
}
.policy h2 { margin: 0; font-size: 28px; }
.policy h3 { margin: 28px 0 6px; font-size: 18px; }
.policy p { margin: 8px 0; }
.policy .updated { color: var(--muted); font-size: 14px; }
.policy a { color: inherit; text-underline-offset: 2px; }
.policy a.primary { display: inline-block; margin-top: 20px; text-decoration: none; color: var(--on-color); }
.fine { font-size: 13px; color: var(--muted); margin: 14px 0 0 !important; }
.fine a { color: inherit; }
