/* Word Wizards — styles
   Built for tablets (landscape) and computers. The board is sized from the
   viewport height so the rack is always reachable without scrolling. */

:root {
  --cream: #f7f1e3;
  --cream-deep: #efe6d2;
  --ink: #38312a;
  --ink-soft: #6b6055;
  --board-frame: #2f5d50;
  --board-frame-dark: #24483f;
  --square: #f0e6cf;
  --square-line: #dccfb2;
  --dl: #9ad3e8;
  --tl: #3f8fd0;
  --dw: #f4a9b8;
  --tw: #e4664a;
  --tile: #f5d98c;
  --tile-edge: #d9b562;
  --tile-ink: #4a3413;
  --accent: #e07a36;
  --accent-dark: #c4642a;
  --green: #3f9a6a;
  --panel: #fffaf0;
  --shadow: 0 2px 0 rgba(0, 0, 0, .12), 0 8px 24px rgba(60, 40, 20, .10);
  --radius: 14px;
  --font-display: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, #fff6e2 0%, transparent 45%),
    radial-gradient(circle at 88% 8%, #ffeede 0%, transparent 40%),
    var(--cream);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

h1, h2, h3, .brand, .btn { font-family: var(--font-display); }

/* --- Small screen gate ------------------------------------------------- */
#too-small { display: none; }

@media (max-width: 767px), (max-height: 479px) {
  #too-small {
    display: grid;
    place-items: center;
    position: fixed;
    inset: 0;
    padding: 24px;
    background: var(--cream);
    z-index: 500;
  }
  .screen { display: none !important; }
}

.too-small-card { max-width: 420px; text-align: center; }
.too-small-emoji { font-size: 44px; }
.too-small-card h1 { font-size: 26px; margin: 12px 0 8px; }
.too-small-card p { color: var(--ink-soft); line-height: 1.5; }

/* --- Screens ------------------------------------------------------------ */
.screen { height: 100%; }
[hidden] { display: none !important; }

/* --- Start screen ------------------------------------------------------- */
#start-screen,
#lobby-screen {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}

.start-card {
  width: min(720px, 100%);
  background: var(--panel);
  border-radius: 24px;
  padding: 36px 40px 32px;
  box-shadow: var(--shadow);
  border: 2px solid #ece0c8;
}

.logo {
  display: flex;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}

.logo-tile {
  width: 42px;
  height: 46px;
  display: grid;
  place-items: center;
  background: linear-gradient(#fbe6ae, var(--tile));
  border: 1px solid var(--tile-edge);
  border-bottom-width: 3px;
  border-radius: 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  color: var(--tile-ink);
}

.logo-tile:nth-child(odd) { transform: rotate(-2deg); }
.logo-tile:nth-child(even) { transform: rotate(2deg); }
.logo-gap { width: 14px; }

.tagline {
  text-align: center;
  color: var(--ink-soft);
  font-size: 17px;
  margin: 18px 0 26px;
}

.field { display: block; margin-bottom: 22px; border: 0; padding: 0; }
.field-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 9px;
  color: var(--ink);
}

#player-name {
  width: 100%;
  font-family: var(--font-body);
  font-size: 17px;
  padding: 13px 15px;
  border-radius: 12px;
  border: 2px solid #e3d7bd;
  background: #fffdf8;
  color: var(--ink);
}

#player-name:focus { outline: 3px solid #f6c98e; border-color: var(--accent); }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.choice-card {
  text-align: left;
  padding: 15px 16px;
  border-radius: 14px;
  border: 2px solid #e3d7bd;
  background: #fffdf8;
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.choice-card:hover { transform: translateY(-2px); }

.choice-card.is-selected {
  border-color: var(--accent);
  background: #fff3e4;
  box-shadow: 0 0 0 3px #f8dcbd;
}

.choice-card b {
  display: block;
  font-family: var(--font-display);
  font-size: 18px;
  margin-bottom: 4px;
}

.choice-card span { font-size: 13.5px; color: var(--ink-soft); line-height: 1.35; }

.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }

.chip {
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid #e3d7bd;
  background: #fffdf8;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
}

.chip.is-selected {
  border-color: var(--accent);
  background: #fff3e4;
  box-shadow: 0 0 0 3px #f8dcbd;
}

.start-note {
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 18px 0 0;
}

/* --- Buttons ------------------------------------------------------------ */
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, filter .12s ease;
  color: var(--ink);
  background: #efe4cd;
}

.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-big { padding: 15px 26px; font-size: 18px; }

.btn-primary {
  background: linear-gradient(var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 3px 0 #a9521f;
  width: 100%;
}

.btn-primary:active:not(:disabled) { box-shadow: 0 1px 0 #a9521f; }

.play-buttons .btn-primary { width: auto; }

.btn-secondary {
  background: #fffdf8;
  border: 2px solid #e3d7bd;
  box-shadow: 0 2px 0 #e3d7bd;
}

.btn-ghost { background: transparent; border: 2px solid transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(0, 0, 0, .05); }

.btn-icon { background: #fffdf8; border: 2px solid #e3d7bd; font-size: 14px; padding: 9px 14px; }

/* --- Game layout -------------------------------------------------------- */
#game-screen {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 2px solid #ece0c8;
}

.brand { font-size: 20px; font-weight: 800; color: var(--board-frame); }

.turn-banner {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #eaf6ef;
  color: #26694a;
}

.turn-banner.is-waiting { background: #fdf0e2; color: #9a5a20; }

.topbar-actions { display: flex; gap: 6px; }

.layout {
  display: grid;
  grid-template-columns: 1fr minmax(230px, 290px);
  gap: 18px;
  padding: 12px 20px 0;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.board-area {
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
}

.board-wrap { position: relative; }

/* --- Board -------------------------------------------------------------- */
/* The board is always a square that fits the space left over after the
   topbar, sidebar and rack have taken theirs. The exact size is measured from
   the container in app.js (fitBoard) — media-query arithmetic can't see how
   tall the tray actually wrapped to. The value below is only a first paint. */
.board {
  --board-size: min(calc(100vh - 230px), calc(100vw - 350px));
  width: var(--board-size);
  height: var(--board-size);
  max-width: 100%;
  max-height: 100%;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 2px;
  padding: 8px;
  background: linear-gradient(var(--board-frame), var(--board-frame-dark));
  border-radius: 16px;
  box-shadow: 0 6px 0 #1c382f, 0 16px 36px rgba(30, 50, 40, .3);
  touch-action: manipulation;
}

.cell {
  position: relative;
  border-radius: 4px;
  background: var(--square);
  display: grid;
  place-items: center;
  font-size: calc(var(--board-size) / 100);
  font-weight: 700;
  color: rgba(60, 48, 30, .62);
  text-align: center;
  line-height: 1.05;
  cursor: pointer;
  user-select: none;
}

.cell.dl { background: var(--dl); color: #1d4a5e; }
.cell.tl { background: var(--tl); color: #fff; }
.cell.dw { background: var(--dw); color: #7a2a3b; }
.cell.tw { background: var(--tw); color: #fff; }
.cell.center { background: var(--dw); color: #7a2a3b; }
.cell.center::after { content: '★'; font-size: calc(var(--board-size) / 32); }
.cell.center .cell-label { display: none; }

.cell.is-target { outline: 3px solid #ffb257; outline-offset: -2px; z-index: 2; }
.cell.is-hint { animation: hintPulse 1.1s ease-in-out 3; }

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 190, 80, 0); }
  50% { box-shadow: inset 0 0 0 4px rgba(255, 170, 60, .95); }
}

.tile {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background: linear-gradient(#fbe7b4, var(--tile));
  border: 1px solid var(--tile-edge);
  border-bottom-width: 3px;
  color: var(--tile-ink);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(var(--board-size) / 26);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}

.tile .value {
  position: absolute;
  right: 8%;
  bottom: 2%;
  font-size: calc(var(--board-size) / 62);
  font-weight: 700;
  opacity: .72;
}

.tile.is-blank { background: linear-gradient(#fdf3dc, #f2e4c2); color: #7a6a4a; }

.tile.is-pending {
  background: linear-gradient(#fff0c8, #ffdf94);
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0, 0, 0, .2);
}

.tile.is-fresh { animation: dropIn .22s ease-out; }

@keyframes dropIn {
  from { transform: translateY(-14px) scale(1.08); opacity: .4; }
  to { transform: none; opacity: 1; }
}

.board-overlay {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(30, 45, 38, .45);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--font-display);
  font-size: 22px;
  backdrop-filter: blur(1.5px);
}

/* --- Sidebar ------------------------------------------------------------ */
.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 2px solid #ece0c8;
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 0;
}

.panel-title {
  margin: 0 0 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
}

.scoreboard { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }

.score-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8f1e2;
}

.score-row.is-turn { background: #eaf6ef; box-shadow: inset 0 0 0 2px #9fd4b6; }

.score-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  flex: none;
}

.score-name { flex: 1; font-weight: 700; font-size: 15px; }
.score-name small { display: block; font-weight: 600; font-size: 11.5px; color: var(--ink-soft); }
.score-value { font-family: var(--font-display); font-weight: 800; font-size: 21px; }

.bag-count {
  margin-top: 11px;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}

.bag-count span { font-weight: 800; color: var(--ink); }

.feed-panel { overflow: hidden; display: flex; flex-direction: column; }

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  align-content: start;
  /* Claim the rest of the panel. Entries carry a word's meaning now, so they
     run to several lines and the old content-sized box showed barely one. */
  flex: 1 1 auto;
  min-height: 0;
}

.feed li {
  font-size: 13.5px;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8f1e2;
  color: var(--ink-soft);
}

.feed li b { color: var(--ink); }
.feed li.is-you { background: #eaf6ef; }
.feed li.is-big { background: #fff2d9; }

/* --- Tray (rack + actions) ---------------------------------------------- */
.tray {
  background: var(--panel);
  border-top: 2px solid #ece0c8;
  padding: 12px 20px 14px;
}

.tray-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
}

.rack-block { display: flex; align-items: center; gap: 14px; }

.rack {
  display: flex;
  gap: 7px;
  padding: 9px 11px;
  background: linear-gradient(#c08a4e, #9c6c38);
  border-radius: 12px;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .28), 0 3px 0 #7d5528;
  min-height: 70px;
  min-width: 400px;
  align-items: center;
}

.rack-slot { width: 50px; height: 54px; }

.rack-tile {
  width: 50px;
  height: 54px;
  border-radius: 7px;
  background: linear-gradient(#fbe7b4, var(--tile));
  border: 1px solid var(--tile-edge);
  border-bottom-width: 4px;
  color: var(--tile-ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  display: grid;
  place-items: center;
  position: relative;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform .12s ease;
}

.rack-tile:hover { transform: translateY(-3px); }

.rack-tile.is-selected {
  transform: translateY(-8px);
  box-shadow: 0 0 0 3px var(--accent), 0 6px 12px rgba(0, 0, 0, .25);
}

.rack-tile.is-used { opacity: .25; pointer-events: none; }
.rack-tile.is-swapping { box-shadow: 0 0 0 3px #3f8fd0; transform: translateY(-6px); }

.rack-tile .value {
  position: absolute;
  right: 5px;
  bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  opacity: .7;
}

.rack-tools { display: grid; gap: 7px; }

.drag-ghost {
  position: fixed;
  z-index: 400;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .35);
}

/* --- Play block --------------------------------------------------------- */
.play-block { display: grid; gap: 10px; justify-items: center; }

.move-preview {
  min-height: 34px;
  min-width: 320px;
  display: grid;
  place-items: center;
  padding: 6px 16px;
  border-radius: 10px;
  background: #f8f1e2;
  font-size: 15px;
  text-align: center;
}

.move-preview-empty { color: var(--ink-soft); font-size: 14px; }
.move-preview.is-good { background: #eaf6ef; color: #26694a; font-weight: 700; }
.move-preview.is-bad { background: #fdeceb; color: #9d3226; font-weight: 700; }
.move-preview .points { font-family: var(--font-display); font-weight: 800; }

.play-buttons { display: flex; gap: 9px; align-items: center; }

/* --- Modals ------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, .5);
  display: grid;
  place-items: center;
  z-index: 300;
  padding: 24px;
}

.modal-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 28px 32px;
  width: min(520px, 100%);
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .3);
  max-height: 88vh;
  overflow-y: auto;
}

.modal-wide { width: min(680px, 100%); text-align: left; }
.modal-card h2 { margin: 0 0 12px; font-size: 24px; }
.modal-sub { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 18px; line-height: 1.45; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.modal-actions .btn-primary { width: auto; }

.blank-letters {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
  margin: 18px 0;
}

.blank-letters button {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--tile-edge);
  border-bottom-width: 3px;
  background: linear-gradient(#fbe7b4, var(--tile));
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  color: var(--tile-ink);
  cursor: pointer;
}

.blank-letters button:hover { transform: translateY(-2px); }

.swap-tiles { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }

.rules { text-align: left; line-height: 1.6; padding-left: 22px; margin: 0 0 18px; }
.rules li { margin-bottom: 9px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; font-size: 13.5px; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.sq { width: 18px; height: 18px; border-radius: 4px; display: inline-block; }
.sq-dl { background: var(--dl); }
.sq-tl { background: var(--tl); }
.sq-dw { background: var(--dw); }
.sq-tw { background: var(--tw); }

.over-emoji { font-size: 52px; }
.over-scores { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 8px; }

.over-scores li {
  display: flex;
  justify-content: space-between;
  padding: 11px 16px;
  border-radius: 11px;
  background: #f8f1e2;
  font-size: 16px;
}

.over-scores li.is-winner { background: #fff2d9; font-weight: 800; box-shadow: inset 0 0 0 2px #f0c579; }

/* --- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 190px;
  transform: translateX(-50%);
  background: #3b332b;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  z-index: 350;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .3);
  animation: toastIn .18s ease-out;
}

.toast.is-error { background: #a63a2c; }
.toast.is-good { background: #2f7a52; }

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* --- Narrow landscape (small laptops, 1024-wide tablets) ---------------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 1fr minmax(200px, 240px); gap: 12px; padding: 10px 14px 0; }
  .tray { padding: 10px 14px 12px; }
  .tray-inner { gap: 16px; }
  .rack { min-width: 0; min-height: 62px; }
  .rack-tile, .rack-slot { width: 44px; height: 48px; font-size: 22px; }
  .move-preview { min-width: 240px; }
  .play-buttons .btn { padding: 10px 14px; font-size: 14px; }
  .play-buttons .btn-big { padding: 12px 20px; font-size: 16px; }
}

/* --- Portrait tablets --------------------------------------------------- */
@media (orientation: portrait) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
  .feed { max-height: 210px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- Playing with friends ------------------------------------------------ */
.or-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 20px;
  color: var(--ink-soft);
  font-weight: 700;
}
.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: #ece0c8;
  border-radius: 2px;
}

.friends { text-align: center; }
.friends .btn-secondary { width: 100%; }
.friends .start-note { margin: 10px 0 16px; }

.join-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
}
.code-input {
  flex: 0 1 180px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: .22em;
  text-align: center;
  text-transform: uppercase;
  padding: 10px 8px 10px 14px;
  border-radius: var(--radius);
  border: 2px solid #e3d7bd;
  background: #fffdf8;
  color: var(--ink);
  min-width: 0;
}
.code-input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Lobby */
.lobby-card { text-align: center; width: min(560px, 100%); }
.code-display {
  font-family: var(--font-display);
  font-size: clamp(48px, 14vw, 82px);
  font-weight: 800;
  letter-spacing: .16em;
  color: var(--board-frame);
  background: var(--square);
  border: 3px dashed var(--square-line);
  border-radius: 20px;
  padding: 14px 10px 14px 26px;
  margin: 8px 0 16px;
  user-select: all;
}
.lobby-hint {
  color: var(--ink-soft);
  margin: 16px 0 20px;
  font-weight: 600;
}

.seat-list {
  list-style: none;
  margin: 0 0 26px;
  padding: 0;
  display: grid;
  gap: 10px;
  text-align: left;
}
.seat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fffdf8;
  border: 2px solid #ece0c8;
  border-radius: var(--radius);
  font-weight: 700;
}
.seat-row.is-empty {
  border-style: dashed;
  background: transparent;
}
.seat-row.is-empty .score-avatar { background: #d8ccb4 !important; }
.seat-name small {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.seat-name.is-waiting {
  color: var(--ink-soft);
  font-weight: 600;
  font-style: italic;
}
.lobby-card .btn-primary { width: 100%; margin-bottom: 10px; }

/* Word meanings under a feed entry */
.feed-meaning {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 600;
  color: var(--ink-soft);
  font-style: italic;
}
.feed-meaning::before { content: '“'; }
.feed-meaning::after { content: '”'; }
