/* Romie Cute — iPad-first styling.
   Big touch targets, no hover-dependent affordances, no horizontal page
   scroll. Tuned for an iPad in landscape but degrades fine to a laptop. */

:root {
  --tile-w: 60px;
  --tile-h: 80px;
  --gap: 8px;
  --felt: #16704b;
  --felt-dark: #0f5337;
  --cream: #f6efe2;
  --ink: #20211d;
  --accent: #d9772b;
  --red: #d23b2e;
  --blue: #2a6fd6;
  --orange: #e6892a;
  --black: #2b2b2b;
}

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

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--felt);
  overscroll-behavior: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 52px;
}
button:disabled { opacity: 0.4; cursor: default; }
button.secondary { background: #5a6b62; }

input[type="text"] {
  font: inherit;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid #c9bfa8;
  min-height: 52px;
  width: 100%;
}

/* ---------- landing page ---------- */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  min-height: 100%;
  padding: 32px;
  text-align: center;
}
.landing .card {
  background: var(--cream);
  border-radius: 22px;
  padding: 32px;
  width: min(440px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.landing h1 { font-size: 2.6rem; margin: 8px 0; }
.landing .romeo {
  width: 120px; height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 5px solid var(--accent);
}
.landing .row { display: flex; gap: 10px; margin-top: 14px; }
.landing .row input { flex: 1; }
.divider { margin: 20px 0 8px; color: #8a8170; font-weight: 600; }
.error { color: var(--red); font-weight: 600; min-height: 1.2em; }
.hint { color: #8a8170; font-size: 0.9rem; }

/* ---------- game table ---------- */
.table {
  display: flex;
  flex-direction: column;
  /* Dynamic viewport height: tracks Safari's collapsing toolbar so the rack
     is never hidden behind browser chrome. */
  height: 100dvh;
}
header.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--felt-dark);
  color: var(--cream);
  flex-wrap: wrap;
}
header.bar .title { font-weight: 800; font-size: 1.15rem; }
header.bar .code { font-family: ui-monospace, monospace; letter-spacing: 2px; }
header.bar .spacer { flex: 1; }
/* Small inline button (Invite) — lives in the header, not the action bar. */
.ghostbtn {
  background: rgba(255, 255, 255, 0.16);
  color: var(--cream);
  padding: 6px 12px;
  min-height: 0;
  border-radius: 8px;
  font-size: 0.82rem;
}
.turn-banner { font-weight: 700; }
.turn-banner.you { color: #ffd479; }
.timer {
  font-family: ui-monospace, monospace;
  font-size: 1.3rem;
  font-weight: 800;
  min-width: 56px;
  text-align: center;
}
.timer.low { color: #ff7b6b; }

.players {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  flex-wrap: wrap;
  background: var(--felt-dark);
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--cream);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
}
.chip.turn { background: var(--accent); color: white; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: #6fdc8c; }
.chip .dot.off { background: #d23b2e; }
.chip .count { opacity: 0.8; font-size: 0.85rem; }

main.board {
  flex: 1;
  min-height: 0;          /* allow the board to shrink + scroll, not overflow */
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-content: flex-start;
}
.set {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  min-width: calc(var(--tile-w) + 16px);
  min-height: calc(var(--tile-h) + 16px);
}
.set.newset {
  border: 2px dashed rgba(255, 255, 255, 0.4);
  background: transparent;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 600;
  padding: 8px 14px;
}
/* A set that is not yet a legal run or group — flagged so the player can fix
   it before pressing Done. Shown only on your turn, while you build. */
.set.invalid {
  background: rgba(210, 59, 46, 0.28);
  outline: 2px solid var(--red);
  outline-offset: -2px;
}
/* Your rack: a stack of independent rows. Each row holds however many tiles
   you drop there — 3 in one, 5 in the next — so you can group your thinking. */
footer.rack {
  background: var(--felt-dark);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 42vh;
  overflow-y: auto;
  border-top: 3px solid var(--accent);
}
.rack-row {
  display: flex;
  gap: 4px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  min-height: calc(var(--tile-h) + 10px);
}
.rack-row.newrow {
  border: 2px dashed rgba(255, 255, 255, 0.35);
  background: transparent;
  align-items: center;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 600;
  padding: 6px 14px;
  min-height: 34px;
}

/* The live "this is where it lands" gap shown while a tile is being dragged.
   Surrounding tiles shift to make room because the row is a flex container. */
.placeholder {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 9px;
  border: 2px dashed #ffd479;
  background: rgba(255, 212, 121, 0.14);
  flex: 0 0 auto;
  pointer-events: none;
}

/* Action bar — the three turn actions, one compact row that never wraps. */
.controls {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--felt-dark);
}
.controls button {
  flex: 1;
  white-space: nowrap;
  padding: 12px 8px;
  min-height: 48px;
}

/* Phone tuning: smaller chrome so the board keeps real estate. */
@media (max-width: 600px) {
  header.bar { gap: 8px; padding: 7px 12px; }
  header.bar .title { font-size: 1rem; }
  .timer { font-size: 1.15rem; min-width: 44px; }
  .controls button { padding: 11px 6px; min-height: 46px; font-size: 0.95rem; }
  footer.rack { max-height: 38vh; }
}

/* ---------- a tile ---------- */
.tile {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 9px;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 800;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
  user-select: none;
  flex: 0 0 auto;
  position: relative;
}
.tile.red { color: var(--red); }
.tile.blue { color: var(--blue); }
.tile.orange { color: var(--orange); }
.tile.black { color: var(--black); }
.tile.movable { cursor: grab; touch-action: none; }
.tile.dragging { opacity: 0.3; }
.tile.joker {
  background-size: cover;
  background-position: center;
  border: 3px solid var(--accent);
}
.tile.joker::after {
  content: "★";
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 0.9rem;
  color: var(--accent);
  text-shadow: 0 0 3px white;
}
.tile.ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  transform: scale(1.12) rotate(-3deg);
  opacity: 0.95;
}

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 2000;
}
.overlay[hidden] { display: none; }
.overlay .card {
  background: var(--cream);
  border-radius: 22px;
  padding: 30px;
  width: min(420px, 100%);
  text-align: center;
}
.overlay h2 { margin-top: 4px; }
.scores { list-style: none; padding: 0; text-align: left; }
.scores li {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid #ddd2b8;
  font-weight: 600;
}
.scores li.winner { color: var(--accent); font-size: 1.15rem; }
