/* ---------------------------------------------------------------------------
   Tilebo Español — board styles
   Palette drawn from Spanish ceramics & terracotta: warm clay, ochre, azulejo
   blue. The board reads as warm and inviting (a learning tool), not a stark
   competitive grid. Premium colors are muted so letter tiles will pop later.
   --------------------------------------------------------------------------- */

:root {
  --bg:        #f3ead9;  /* warm parchment background        */
  --ink:       #3a2c20;  /* dark cocoa text                  */
  --board-bg:  #c9a227;  /* ochre board frame                */
  --cell:      #f7f1e3;  /* empty cell (bone)                */
  --cell-line: #d8c7a6;  /* cell borders                     */

  --tw: #b5533f;  /* triple word  — deep terracotta */
  --dw: #d98a5f;  /* double word  — soft clay       */
  --tl: #3f6b7a;  /* triple letter— azulejo teal    */
  --dl: #8ab0b8;  /* double letter— pale azulejo    */

  --start: #7a9a4e;  /* olive green start square */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- Auth nav + forms ------------------------------------------------------ */
.auth-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.auth-nav a { color: var(--ink); }

.auth-nav form { margin: 0; }

.link-button {
  border: none;
  background: none;
  padding: 0;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}

.button {
  padding: 0.5em 1.2em;
  border: none;
  border-radius: 4px;
  background: var(--tw);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(92vw, 360px);
  margin: 1.5rem auto;
  padding: 1.25rem;
  background: var(--cell);
  border: 1px solid var(--cell-line);
  border-radius: 8px;
}

.auth-form h2 { margin: 0 0 0.5rem; text-align: center; }

.auth-form label { font-size: 0.85rem; font-weight: 700; }

.auth-form input {
  padding: 0.5em;
  border: 1px solid var(--cell-line);
  border-radius: 4px;
  font-size: 1rem;
}

.auth-form .button { margin-top: 0.5rem; }

.form-error {
  margin: 0;
  padding: 0.5em;
  border-radius: 4px;
  background: var(--tw);
  color: #fff;
  font-size: 0.85rem;
}

.auth-alt {
  text-align: center;
  font-size: 0.85rem;
  color: #6b5a47;
}

/* Honeypot: off-screen (not display:none, which some bots check for and
   skip) so a real browser never renders it, but a bot filling every field
   blindly still catches it. See register() in app/auth.py. */
.hp-field {
  position: absolute;
  left: -5000px;
  top: -5000px;
}

.app-header { text-align: center; margin-bottom: 1.25rem; }

.app-header h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
  font-weight: 800;
}

.tagline {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
  color: #7c6a55;
  font-style: italic;
}

.score {
  margin: 0.5rem 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

/* --- Landing page --------------------------------------------------------- */
.landing {
  width: min(92vw, 640px);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.landing-hero { text-align: center; }

.landing-lead {
  font-size: 1.05rem;
  line-height: 1.5;
}

.landing-cta {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 1.1rem;
  padding: 0.6em 1.6em;
  text-decoration: none;
}

.landing-features h2 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.landing-features ul {
  padding-left: 1.2rem;
  line-height: 1.5;
}

.landing-features li { margin-bottom: 0.75rem; }

/* --- The board itself ---------------------------------------------------- */
/* --size (the number of cells per side) is injected inline by the template,
   so this grid always matches whatever BOARD_SIZE is in app.py. */
.board {
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: 3px;
  padding: 10px;
  background: var(--board-bg);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(58, 44, 32, 0.25);
  /* Cap the board width and let it shrink on small screens (mobile-first). */
  width: min(92vw, 560px);
  aspect-ratio: 1 / 1;   /* keep it square */
}

.square {
  background: var(--cell);
  border: 1px solid var(--cell-line);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.5rem, 1.6vw, 0.8rem);
  font-weight: 700;
  aspect-ratio: 1 / 1;
  user-select: none;
}

.square .label { opacity: 0.85; letter-spacing: 0.02em; }
.square .mark  { font-size: 1.3em; color: #fff; }

.square { cursor: pointer; position: relative; }

/* A placed letter tile sits on top of the premium label/start star. Empty
   spans take no visual space, so plain squares look untouched. */
.square .tile:not(:empty) {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0d9a8;
  color: var(--ink);
  border-radius: 2px;
  font-size: 1em;
}

.square.pending .tile:not(:empty) {
  outline: 2px solid var(--tl);
  outline-offset: -2px;
}

/* A blank tile's letter is stored lowercase (see tiles.rack_tile_for) so
   the backend can tell it apart from a real tile, but it should still
   look like a normal tile on screen -- the missing point-value badge
   below is what visually marks it as a blank. */
.tile-letter { text-transform: uppercase; }

/* Point-value badge in the corner of a placed tile, Scrabble-style. Blank
   (0-point) tiles get no badge, so .tile-value is only ever present when
   there's a value worth showing. */
.tile-value {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.55em;
  font-weight: 600;
  line-height: 1;
}

/* Points earned by the last word played, floating off the corner of its
   last tile. pointer-events: none so it never steals the tap-to-define
   click from the tile underneath. */
.score-badge {
  position: absolute;
  top: -0.55rem;
  right: -0.55rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--start);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: 0 2px 5px rgba(58, 44, 32, 0.35);
  z-index: 5;
  pointer-events: none;
}

/* Premium squares — colored fills with white labels */
.premium-TW { background: var(--tw); color: #fff; }
.premium-DW { background: var(--dw); color: #fff; }
.premium-TL { background: var(--tl); color: #fff; }
.premium-DL { background: var(--dl); color: #26343a; }
.start      { background: var(--start); }

.board-note {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  font-style: italic;
  color: #7c6a55;
}

/* Accessibility: respect reduced-motion (nothing animates yet, but sets the
   habit) and ensure focus outlines stay visible when we add interactivity. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* --- Rack + move controls -------------------------------------------------- */
.rack-area {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.rack {
  display: flex;
  gap: 0.4rem;
  min-height: 2.6rem;
}

.rack-tile {
  position: relative;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--cell-line);
  border-radius: 4px;
  background: var(--cell);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.rack-tile.selected {
  background: var(--start);
  color: #fff;
  border-color: var(--start);
}

.rack-tile.exchange-selected {
  background: var(--tw);
  color: #fff;
  border-color: var(--tw);
}

.rack-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

#play-btn, #hint-btn, #exchange-btn, #pass-btn, #exchange-cancel-btn {
  padding: 0.5em 1.2em;
  border: none;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

#play-btn:disabled, #hint-btn:disabled, #exchange-btn:disabled, #pass-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#play-btn { background: var(--tw); }
#hint-btn { background: var(--tl); }
#exchange-btn, #exchange-cancel-btn { background: var(--dw); }
#pass-btn { background: #8a7a63; }

.move-status {
  margin: 0;
  min-height: 1em;
  font-size: 0.9rem;
  color: #6b5a47;
}

/* The one-time "game over" message deserves more visual weight than the
   routine "Played: CASA (+9)" text it otherwise shares a line with --
   without this it's easy to miss entirely. */
.move-status.game-over {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  padding: 0.5em 1em;
  background: var(--cell);
  border: 2px solid var(--tw);
  border-radius: 6px;
}

.hint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--ink);
  text-align: center;
}

.hint-note {
  max-width: 320px;
  margin: 0;
  font-size: 0.78rem;
  font-style: italic;
  color: #6b5a47;
  text-align: center;
}

/* --- Tap-to-define panel -------------------------------------------------- */
/* :not([hidden]) so the `hidden` attribute (toggled by main.js) actually
   hides it -- an unconditional `display: flex` here would override the
   browser's default `[hidden] { display: none }` rule, same reasoning as
   the blank-picker overlay below. */
.definition-panel:not([hidden]) {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(58, 44, 32, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
}

.definition-card {
  position: relative;
  width: min(92vw, 560px);
  max-height: 80vh;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  background: var(--cell);
  border: 1px solid var(--cell-line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(58, 44, 32, 0.18);
}

.definition-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  border: none;
  background: none;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}

.definition-entry + .definition-entry {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--cell-line);
}

.definition-entry h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.definition-entry .translation {
  font-weight: 400;
  color: #6b5a47;
}

.definition-entry .play-audio {
  margin-left: 0.4rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
}

.definition-entry .example-es {
  margin: 0.15rem 0;
}

.definition-entry .example-en {
  margin: 0.15rem 0;
  color: #6b5a47;
  font-style: italic;
}

/* --- Feedback form ---------------------------------------------------------- */
/* :not([hidden]) for the same reason as .definition-panel/.blank-picker above
   -- an unconditional display: flex would override the browser's default
   [hidden] { display: none } and leave the overlay stuck visible. */
.feedback-panel:not([hidden]) {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(58, 44, 32, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
}

.feedback-card {
  position: relative;
  width: min(92vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  background: var(--cell);
  border: 1px solid var(--cell-line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(58, 44, 32, 0.18);
}

.feedback-card textarea,
.feedback-card input {
  font: inherit;
  padding: 0.5em;
  border: 1px solid var(--cell-line);
  border-radius: 4px;
  resize: vertical;
}

.feedback-actions {
  display: flex;
  gap: 0.5rem;
}

/* --- Blank-tile letter picker ---------------------------------------------- */
/* :not([hidden]) so the `hidden` attribute (which main.js toggles) actually
   hides it -- an unconditional `display: flex` here would override the
   browser's default `[hidden] { display: none }` rule and leave the
   overlay stuck visible regardless of the attribute. */
.blank-picker:not([hidden]) {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  background: rgba(58, 44, 32, 0.55);
  z-index: 10;
}

.blank-picker p {
  margin: 0;
  color: #fff;
  font-weight: 700;
}

.blank-picker-letters {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  max-width: min(90vw, 420px);
}

.blank-picker-letter {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--cell-line);
  border-radius: 4px;
  background: var(--cell);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.blank-picker-letter:hover {
  background: var(--start);
  color: #fff;
  border-color: var(--start);
}

#blank-picker-cancel {
  padding: 0.4em 1.2em;
  border: none;
  border-radius: 4px;
  background: var(--cell);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
