/* App layout and components. Theme tokens and primitives are in theme.css. */

/* Jua, self-hosted so the first offline visit has it too. Latin only;
   anything outside the range falls back to the next font in the stack. */
@font-face {
  font-family: "Jua";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/jua-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root[data-mode="dark"] { color-scheme: dark; }

/* Water is a fixed-meaning accent, like the footer heart in other uwuapps:
   it reads as water whatever the swatch. js/game.js draws with these. */
:root,
:root[data-mode="light"] {
  --water: #2f7fe0;
  --water-line: #9cc9ff;
}
:root[data-mode="dark"] {
  --water: #2a6fd6;
  --water-line: #6aa8f2;
}

:root {
  /* The body's own colour, for anything that has to match it. */
  --page-bg: color-mix(in srgb, var(--brand) 10%, var(--bg));
  /* Glass that text stays readable through when the water is behind it.
     Plain --surface over the water leaves --brand-ink near 3.5:1; this
     clears 4.5:1 in both modes and is still see-through. */
  --glass-read: color-mix(in srgb, var(--bg) 80%, transparent);
  /* Where the floating controls start: under the update bar when there is
     one, which already clears the notch, or under the notch. */
  --hud-top: calc(var(--vv-top, 0px) + max(calc(var(--notice-h, 0px) + 14px), calc(env(safe-area-inset-top) + 14px)));
  --hud-edge: max(16px, calc(env(safe-area-inset-right) + 16px));
  --hud-edge-left: max(16px, calc(env(safe-area-inset-left) + 16px));
}

h1, h2 { font-weight: normal; }

:focus-visible {
  outline: 2px solid var(--brand-ink);
  outline-offset: 2px;
}

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

/* A full screen game: nothing scrolls, and taps never zoom. */
html, body { overflow: hidden; overscroll-behavior: none; }
body { touch-action: manipulation; }

.field-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  color: var(--muted-strong);
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: center;
}
/* Key hints mean nothing on a touch screen. */
body.vk-on .kbd-hint,
body.vk-on .keys-legend,
body.device-keyboard .kbd-hint { display: none; }

/* ---- Floating controls ----
   Each sits on its own over the playing field; there is no bar to hide a
   strip of it. Buttons are glass so drops stay visible through them. */

.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease;
}
.glass-btn:hover { transform: translateY(-1px); background: var(--surface-strong); }
.glass-btn svg { width: 22px; height: 22px; }
.glass-btn.small { width: 36px; height: 36px; border-radius: 12px; }
.glass-btn.small svg { width: 18px; height: 18px; }

/* Level, misses and score, top left, as plain text. The soft halo in the
   page colour keeps it legible when a pale drop passes behind. */
.hud-stats {
  position: fixed;
  z-index: 5;
  top: var(--hud-top);
  left: var(--hud-edge-left);
  pointer-events: none;
  text-shadow: 0 0 4px var(--page-bg), 0 0 8px var(--page-bg);
  transition: top 0.2s ease;
}
.hud-level {
  font-size: 1.7rem;
  line-height: 1.1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}
.hud-line {
  font-size: 0.95rem;
  color: var(--muted);
}
.hud-line span { color: var(--ink); }

/* Pause, top right, with the menu tray under it. */
.hud-right {
  position: fixed;
  z-index: 5;
  top: var(--hud-top);
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
  transition: top 0.2s ease;
}
.hud-right > * { pointer-events: auto; }

.hud-pause {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-right: var(--hud-edge);
}
.pause-btn { width: 54px; height: 54px; border-radius: 16px; }
.pause-btn svg { width: 28px; height: 28px; }

/* The tray: a column of glass buttons with an arrow tab beside it. Collapsed,
   the buttons slide off the right edge and the tab is left peeking out. */
.tray {
  --tray-shift: calc(44px + 8px + var(--hud-edge));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tray.collapsed { transform: translateX(var(--tray-shift)); }

.tray-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: border-radius 0.22s ease;
}
.tray-tab svg {
  width: 16px;
  height: 16px;
  transition: transform 0.22s ease;
}
/* At the edge it is a tab, flat on the side the screen cuts off. */
.tray.collapsed .tray-tab { border-radius: 12px 0 0 12px; border-right: none; }
.tray.collapsed .tray-tab svg { transform: rotate(180deg); }

.tray-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-right: var(--hud-edge);
  transition: opacity 0.22s ease;
}
.tray.collapsed .tray-buttons { opacity: 0; }

/* The typing row, bottom centre: a hint, a clear button, the typing box. */
.typing-dock {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  /* --kb-inset is the height the device's keyboard covers, 0 when closed. */
  bottom: calc(var(--kb-inset, 0px) + max(18px, calc(env(safe-area-inset-bottom) + 18px)));
  display: flex;
  justify-content: center;
  padding: 0 12px;
  pointer-events: none;
}
.typing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* A real text field, so a tap on a phone opens its keyboard. Its font stays
   above 16px, under which iOS zooms the page on focus. */
.buffer {
  display: block;
  min-width: 228px;
  width: 228px;
  text-align: center;
  caret-color: var(--brand-ink);
  max-width: 60vw;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--glass-read);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  /* 3:1 against what is behind it, as a field's edge must be. */
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  box-shadow: var(--shadow);
  color: var(--brand-ink);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
}
.buffer::placeholder {
  color: var(--muted-strong);
  opacity: 1;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.buffer:focus-visible { outline-offset: 3px; }
.buffer.shake {
  color: var(--error);
  border-color: var(--error);
  animation: shake 0.3s ease;
}
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* ---- On-screen keyboard ---- */

.vkeyboard {
  position: fixed;
  z-index: 6;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(var(--kb-inset, 0px) + max(8px, env(safe-area-inset-bottom)));
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}
.vkeyboard[hidden] { display: none; }

/* The typing row, moved in here. Nested in the keyboard's glass, so its
   parts use the strong surface, one level above the card. */
.vk-head .typing-row { width: 100%; }
.vk-head .buffer {
  flex: 1;
  width: auto;
  min-width: 0;
  max-width: none;
  height: 38px;
  background: var(--surface-strong);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}
.vk-head .glass-btn {
  background: var(--surface-strong);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}

.vk-keys {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* The device's keyboard is open: its keys replace these, and the head, with
   the typing box, rides just above it. */
body.device-keyboard .vk-keys { display: none; }
.k-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}
.key {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 1.05rem;
  touch-action: manipulation;
  transition: background 0.12s ease, transform 0.12s ease;
}
.key.wide { grid-column: span 2; }
.key svg { width: 20px; height: 20px; }
.key.pressed {
  background: var(--brand-fill);
  color: var(--on-brand);
  transform: translateY(1px);
}

/* ---- Pause and game over ----
   The same look as the theme modal, on their own class so ui.js never
   counts them as an open window. Below the windows, which can open on top. */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(10, 15, 12, 0.35);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}
.overlay.hidden .modal {
  opacity: 0;
  transform: translateY(14px) scale(0.97);
}

.modal .hidden,
.overlay .hidden { display: none !important; }

.panel {
  align-items: center;
  gap: 12px;
  text-align: center;
}
.panel h2 {
  font-size: 1.5rem;
  color: var(--brand-ink);
}
.panel p {
  line-height: 1.5;
  color: var(--muted-strong);
}
.keys-legend { font-size: 0.9rem; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.panel-actions .btn { padding: 9px 16px; }

.coffee-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}
.coffee-link svg { width: 16px; height: 16px; }

.panel .credit {
  margin-top: -6px;
  font-size: 0.8rem;
}

/* A key hint inside a button, after its label. */
.btn .kbd-hint {
  margin-left: 2px;
  font-size: 0.7rem;
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}
.final-stats > div {
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.final-stats dt {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.final-stats dd {
  font-size: 1.3rem;
  color: var(--ink);
}

/* Buttons. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.btn-primary:hover { background: var(--brand-fill-strong); }
.btn-quiet {
  color: var(--ink);
  border: 1px solid var(--surface-border);
}
.pill { border-radius: 999px; }

/* Text fields: the leaderboard name, on game over and in Settings. */
.guess {
  display: flex;
  gap: 8px;
  width: 100%;
}
.field {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-strong);
  /* 3:1 against the card, as a field's edge must be. */
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  color: var(--ink);
  font-size: 1rem;
}
.field::placeholder { color: var(--muted-strong); opacity: 1; }
.guess .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
}

.submit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.submit-label {
  font-size: 0.95rem;
  color: var(--ink);
}
.panel .submit-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--error);
}
.panel .submit-note {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.submitted {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  text-align: left;
}
.panel .submitted p { color: var(--ok); }
.ok-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--ok);
}
.ok-icon svg { width: 100%; height: 100%; }

/* ---- Settings modal ---- */

.saved-name {
  font-size: 0.95rem;
  color: var(--ink);
}
.clear-name { align-self: flex-start; }
.mode-toggle.thirds { grid-template-columns: repeat(3, 1fr); }

.setting-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
  text-align: left;
}
.setting-toggle > span:first-child { flex: 1; }
.switch-state {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted-strong);
  transition: transform 0.18s ease, background 0.18s ease;
}
.setting-toggle[aria-checked="true"] .switch {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
}
.setting-toggle[aria-checked="true"] .switch::after {
  background: var(--bg);
  transform: translateX(16px);
}

/* ---- Leaderboard modal ---- */

.board-body {
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  transition: opacity 0.15s ease;
}
.board-body[aria-busy="true"] { opacity: 0.6; }
.board-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.board-table th {
  padding: 6px 8px;
  text-align: left;
  font-weight: normal;
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.board-table td {
  padding: 7px 8px;
  border-top: 1px solid var(--surface-border);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.board-table th:first-child,
.board-table td:first-child { width: 2.5em; color: var(--muted-strong); }
.board-empty {
  padding: 32px 8px;
  text-align: center;
  color: var(--muted-strong);
}

/* ---- Update bar ----
   Per update-bar-spec.md: quieter than the controls, full width, tinted
   enough to read as a notice. Fixed, since everything in the game is, and
   js/update-bar.js publishes its height as --notice-h. */

.update-notice {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--brand-ink) 12%, var(--bg));
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
  animation: notice-in 0.2s ease;
}
@keyframes notice-in {
  from { transform: translateY(-100%); }
}
.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}
.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn {
  flex: none;
  padding: 6px 12px;
}

/* A landscape phone: the keys give the field back some height. */
@media (max-height: 500px) {
  .key { height: 34px; }
  .vkeyboard, .vk-keys, .k-row { gap: 4px; }
  .vkeyboard { padding: 6px; }
}

@media (max-width: 480px) {
  :root {
    --hud-edge: max(10px, calc(env(safe-area-inset-right) + 10px));
    --hud-edge-left: max(12px, calc(env(safe-area-inset-left) + 12px));
  }
  .hud-level { font-size: 1.35rem; }
  .hud-line { font-size: 0.85rem; }
  .pause-btn { width: 46px; height: 46px; }
  .pause-btn svg { width: 24px; height: 24px; }
  .glass-btn { width: 40px; height: 40px; }
  .tray { --tray-shift: calc(40px + 8px + var(--hud-edge)); }
  .tray-tab { height: 40px; }
  .buffer { min-width: 180px; width: 180px; }
  .final-stats { grid-template-columns: repeat(2, 1fr); }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
