:root {
  color-scheme: dark;
  --bg: #121213;
  --fg: #ffffff;
  --border-empty: #3a3a3c;
  --border-filled: #818384;
  --key-bg: #818384;
  --key-fg: #ffffff;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #3a3a3c;
  /* Bounded by both vw and dvh so tiles can never push the board wider
     or taller than the viewport, on any phone/tablet/desktop size. */
  --tile-size: clamp(30px, min(9vw, 8dvh), 58px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-header {
  text-align: center;
  padding: clamp(6px, 2vh, 14px) 8px clamp(2px, 1vh, 6px);
  border-bottom: 1px solid var(--border-empty);
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(22px, 6vw, 32px);
  letter-spacing: 0.06em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: clamp(11px, 3vw, 14px);
  color: #a0a0a0;
}

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(4px, 1.5vh, 12px) 8px;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: clamp(4px, 1vh, 6px);
  margin: 0 auto;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  gap: clamp(4px, 1vw, 6px);
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tile-size);
  height: var(--tile-size);
  font-size: calc(var(--tile-size) * 0.5);
  font-weight: 700;
  border: 2px solid var(--border-empty);
  border-radius: 4px;
  text-transform: uppercase;
  color: var(--fg);
  background: transparent;
}

.tile.filled {
  border-color: var(--border-filled);
}

.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.flip {
  animation: flip 0.4s ease;
}

@keyframes flip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

.tile.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.footer-area {
  flex-shrink: 0;
}

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1vh, 8px);
  padding: clamp(4px, 1vh, 10px) 4px calc(clamp(4px, 1vh, 10px) + env(safe-area-inset-bottom));
}

.keyboard[hidden] {
  display: none;
}

/* Replaces the keyboard once a round ends — same footer slot, so it
   never pushes the board or grows the page past one screen. */
.reference {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: clamp(10px, 3vh, 20px) 16px calc(clamp(10px, 3vh, 20px) + env(safe-area-inset-bottom));
}

.reference[hidden] {
  display: none;
}

.reference .ref-word {
  font-size: clamp(16px, 4.5vw, 22px);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.reference .ref-verse {
  font-size: clamp(14px, 4vw, 18px);
  color: #a0a0a0;
}

.reference .ref-note {
  font-size: clamp(11px, 3vw, 13px);
  color: #6a6a6a;
}

/* grid-template-columns is set per-row from script.js (fr weights, so
   columns always sum to exactly the row's width — never overflow it) */
.key-row {
  display: grid;
  width: 100%;
  max-width: 480px;
  gap: clamp(4px, 1vw, 6px);
}

.key {
  width: 100%;
  min-width: 0;
  height: clamp(42px, 12vh, 58px);
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-fg);
  font-weight: 700;
  font-size: clamp(11px, 3.2vw, 15px);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.key.wide {
  font-size: clamp(9px, 2.4vw, 12px);
}

.key.correct {
  background: var(--correct);
}

.key.present {
  background: var(--present);
}

.key.absent {
  background: #565758;
}

.key:active {
  filter: brightness(1.2);
}

.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  color: #121213;
  padding: 10px 16px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
}
