/*
 * Quordle layout - ported from slivce/wordle/templates/wordle/quordle.html.
 * Requires tokens.css + components.css first (site header, buttons, theme
 * tokens). Game mechanics/proportions (4 boards, shrinking "small" rows,
 * quarter-colored keys) are kept faithful to the Django original - only
 * chrome (header, buttons, modal, colors) moved onto the shared design
 * system. Tile colors (--tile-correct/present/absent) are fixed, same as
 * the daily-Wordle slice - the self-serve theme picker never touches them.
 */

html, body {
  height: 100%;
}

.quordle-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.quordle-header {
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-4);
}

.quordle-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.quordle-header .btn {
  padding: 8px 14px;
  font-size: 0.88rem;
}

.game-wrapper {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  width: 100%;
  padding-bottom: 8px;
}

.boards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 640px;
  padding: 10px;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--surface);
  padding: 6px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}

.row {
  display: flex;
  gap: 3px;
}

.cell {
  flex: 1;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 2vw, 1.3rem);
  font-weight: 700;
  text-transform: uppercase;
  background-color: var(--surface);
  color: var(--ink);
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

/* Only the active row per board renders at full size - with 9 rows per
 * board and 4 boards on screen at once, showing every row full-size would
 * make the page absurdly tall. Matches the Django original exactly. */
.cell.small {
  height: 18px;
  font-size: 0.65rem;
  border-width: 1px;
}

.cell.correct { background-color: var(--tile-correct); border-color: var(--tile-correct); color: #fff; }
.cell.present { background-color: var(--tile-present); border-color: var(--tile-present); color: #fff; }
.cell.gray    { background-color: var(--tile-absent);  border-color: var(--tile-absent);  color: #fff; }

.invalid-letter {
  color: var(--danger) !important;
}

@media (max-width: 1024px) {
  .cell.small {
    height: 13px;
    font-size: 0.5rem;
  }
}

/* ---------- Keyboard (shared across all 4 boards) ---------- */

.keyboard {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-2) var(--space-1) max(var(--space-2), env(safe-area-inset-bottom));
  touch-action: manipulation;
}

/* Same 12-unit grid as game.css: 12 + 12 letters, then 9 letters with
 * Enter/Backspace at 1.5 units each (ґ lives at the end of row 2). */
.krow {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  box-sizing: border-box;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background-color: var(--surface-sunken);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.1s;
}

.key:focus {
  outline: none;
}

@media (hover: hover) {
  .key:hover {
    border-color: var(--accent);
  }
}

.key.is-down {
  transform: scale(0.94);
  box-shadow: inset 0 0 0 100px rgba(0, 0, 0, 0.12);
}

/* Invisible hit area reaching halfway into the gaps around each key, so a
 * tap that lands between two keys still counts. */
.key::before {
  content: '';
  position: absolute;
  inset: -3px -2px;
}

.key-label {
  position: relative;
  z-index: 2;
  pointer-events: none;
  color: var(--ink);
  text-transform: uppercase;
}

/* No overflow:hidden on .key any more (it would clip the touch bubble),
 * so the corner quarters carry the key's rounding themselves. */
.key-quarter {
  position: absolute;
  width: 51%;
  height: 51%;
  z-index: 1;
  pointer-events: none;
  margin: 0;
  padding: 0;
  border: none;
  box-sizing: border-box;
}

.top-left { top: 0; left: 0; border-top-left-radius: 3px; }
.top-right { top: 0; right: 0; border-top-right-radius: 3px; }
.bottom-left { bottom: 0; left: 0; border-bottom-left-radius: 3px; }
.bottom-right { bottom: 0; right: 0; border-bottom-right-radius: 3px; }

.key-quarter.green  { background-color: var(--tile-correct); }
.key-quarter.yellow { background-color: var(--tile-present); }
.key-quarter.gray   { background-color: var(--tile-absent); }

.key.correct .key-label,
.key.present .key-label,
.key.gray .key-label {
  color: #fff;
}

.key-enter,
.key-backspace {
  flex-grow: 1.5;
  background-color: var(--accent);
  border: none;
  font-size: 1.25rem;
}

.key-enter .key-label,
.key-backspace .key-label {
  color: var(--accent-ink);
}

@media (hover: hover) {
  .key-enter:hover,
  .key-backspace:hover {
    background-color: var(--accent-strong);
  }
}

@media (max-width: 1024px) {
  .key {
    height: 44px;
  }
}

/* Phones: still shorter than the daily game's keys (four boards need the
 * height), but well past the old 36px / 12px-text keys. */
@media (max-width: 480px) {
  .krow {
    gap: 4px;
  }

  .key {
    height: clamp(42px, 6.2dvh, 50px);
    font-size: clamp(0.95rem, 4.2vw, 1.15rem);
  }

  .key-enter,
  .key-backspace {
    font-size: clamp(1.1rem, 4.8vw, 1.35rem);
  }
}

@media (max-width: 340px) {
  .krow {
    gap: 3px;
  }
}

/* Touch screens: show the held letter above the finger (see
 * keyboardFeedback.js). */
@media (hover: none) {
  .key[data-letter].is-down::after {
    content: attr(data-letter);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    min-width: 44px;
    padding: 6px 0 8px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-card);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    pointer-events: none;
    z-index: 10;
  }

  .krow > .key[data-letter]:first-child.is-down::after {
    left: 0;
    transform: none;
  }

  .krow > .key[data-letter]:last-child.is-down::after {
    left: auto;
    right: 0;
    transform: none;
  }
}

/* ---------- Result modal ---------- */

.modal {
  display: none;
  position: fixed;
  z-index: 99999;
  inset: 0;
  background: rgba(10, 12, 20, 0.45);
  backdrop-filter: blur(2px);
}

.modal-content {
  background: var(--surface);
  color: var(--ink);
  margin: 8dvh auto;
  padding: var(--space-6) var(--space-5) var(--space-5);
  width: min(90vw, 360px);
  max-height: 80dvh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  position: relative;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-faint);
  background: none;
  border: none;
}

.modal-content h2 {
  color: var(--accent);
  margin: 0 0 var(--space-3);
  font-size: 1.2rem;
}

#resultMessage {
  font-size: 1.05rem;
  margin: var(--space-3) 0;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  max-width: 90%;
  text-align: center;
  white-space: pre-wrap;
}

.toast.show {
  opacity: 0.95;
  transform: translateX(-50%) translateY(10px);
}
