:root {
  --bg: #08332a;
  --bg-deep: #031611;
  --felt: #0d5b4b;
  --felt-light: #18826b;
  --wood: #c58d52;
  --wood-dark: #6f4722;
  --paper: #f1e5c9;
  --paper-dark: #d5c4a0;
  --ink: #1e221c;
  --muted: rgba(255, 244, 220, 0.72);
  --gold: #f6d06b;
  --accent: #f47f4a;
  --danger: #d95c54;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  --radius: 28px;
  --tile-size: clamp(1.75rem, 4vw, 3rem);
  --cell-gap: clamp(2px, 0.38vw, 5px);
  --seat-width: min(22vw, 260px);
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: #fff5de;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(248, 211, 117, 0.18), transparent 32%),
    linear-gradient(180deg, #0d3128 0%, #02120e 100%);
}

body {
  overflow: hidden;
}

button, input {
  font: inherit;
}

select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(4, 18, 14, 0.78);
  color: #fff7e7;
  border-radius: 18px;
  padding: 0.9rem 1rem;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow: hidden;
}

.ambient {
  position: absolute;
  inset: auto;
  border-radius: 999px;
  filter: blur(30px);
  pointer-events: none;
}

.ambient-a {
  width: 40vw;
  height: 40vw;
  background: rgba(255, 170, 77, 0.14);
  top: -10vw;
  left: -6vw;
}

.ambient-b {
  width: 32vw;
  height: 32vw;
  background: rgba(41, 154, 123, 0.18);
  bottom: -8vw;
  right: -4vw;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem 0;
}

.topbar h1,
.overlay-card h2 {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", serif;
  letter-spacing: 0.02em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: rgba(255, 245, 222, 0.68);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.68rem;
}

.pill,
.status-panel,
.dock-card,
.seat-card,
.overlay-card {
  background: rgba(8, 24, 20, 0.72);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 245, 222, 0.08);
  box-shadow: var(--shadow);
}

.pill {
  min-width: 110px;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
}

.pill span,
.rules-note,
.dock-hint,
.seat-note,
.tile-score {
  color: var(--muted);
}

.ghost-button,
.accent-button {
  padding: 0.9rem 1.15rem;
  min-height: 48px;
  font-weight: 600;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.ghost-button {
  background: rgba(255,255,255,0.08);
  color: #fff4d6;
}

.accent-button {
  background: linear-gradient(135deg, #ffbf6e, #f06b3f);
  color: #251003;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

.table-stage {
  position: relative;
  min-height: calc(100vh - 98px);
  display: grid;
  place-items: center;
  padding: 4.5rem 5rem 6rem;
}

.board-wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  width: fit-content;
  max-width: 100%;
  justify-items: center;
  z-index: 1;
}

.board-chassis {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  padding: clamp(0.8rem, 2vw, 1.25rem);
  border-radius: 40px;
  background:
    linear-gradient(160deg, rgba(247, 229, 186, 0.12), rgba(86, 52, 25, 0.26)),
    linear-gradient(180deg, rgba(27, 11, 1, 0.62), rgba(49, 22, 4, 0.88));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.12),
    inset 0 -12px 24px rgba(0,0,0,0.22),
    0 30px 70px rgba(0,0,0,0.36);
  transform: perspective(1200px) rotateX(10deg);
}

.board-grid {
  width: min(68vw, 70vh);
  height: min(68vw, 70vh);
  max-width: 720px;
  max-height: 720px;
  display: grid;
  gap: var(--cell-gap);
  padding: clamp(0.45rem, 1vw, 0.75rem);
  border-radius: 30px;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.08), transparent 48%),
    linear-gradient(180deg, #1c6956 0%, #0a4034 100%);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(255, 239, 206, 0.11);
  color: rgba(255, 245, 222, 0.7);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  overflow: hidden;
  appearance: none;
}

.cell::after {
  content: attr(data-bonus);
  font-size: clamp(0.45rem, 0.85vw, 0.72rem);
  letter-spacing: 0.08em;
}

.cell[data-bonus-type="triple_word"] { background: linear-gradient(135deg, #b32c2c, #db5d56); }
.cell[data-bonus-type="double_word"] { background: linear-gradient(135deg, #2767a5, #4795d9); }
.cell[data-bonus-type="triple_letter"] { background: linear-gradient(135deg, #a17b14, #d7b33a); }
.cell[data-bonus-type="double_letter"] { background: linear-gradient(135deg, #1b875c, #34b680); }
.cell[data-bonus-type="start"] { background: linear-gradient(135deg, rgba(255,255,255,0.28), rgba(255,255,255,0.1)); }

.cell.drop-target {
  outline: 3px solid rgba(255, 212, 105, 0.7);
  outline-offset: 1px;
}

.tile,
.rack-tile {
  position: relative;
  width: 86%;
  height: 86%;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background:
    linear-gradient(180deg, #fff4dc 0%, #ecd9b3 100%);
  color: var(--ink);
  font-family: Georgia, "Palatino", serif;
  font-weight: 700;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.75),
    0 6px 10px rgba(62, 42, 17, 0.28);
  transform: translateZ(0);
}

.tile-letter {
  font-size: clamp(0.95rem, 1.7vw, 1.5rem);
}

.tile-score {
  position: absolute;
  bottom: 0.22rem;
  right: 0.32rem;
  font-size: 0.55rem;
  color: rgba(0,0,0,0.55);
}

.tile.blank .tile-score,
.rack-tile.blank .tile-score {
  opacity: 0;
}

.tile.staged,
.rack-tile.selected {
  outline: 3px solid rgba(255, 144, 96, 0.75);
  transform: translateY(-2px);
}

.rack-tile.back {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.16), rgba(255,255,255,0.04)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.12), rgba(255,255,255,0.12) 8px, rgba(0,0,0,0.1) 8px, rgba(0,0,0,0.1) 16px);
  color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.2),
    0 6px 12px rgba(0, 0, 0, 0.28);
}

.status-panel {
  position: absolute;
  width: min(320px, 32vw);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem;
  border-radius: var(--radius);
  z-index: 3;
  --status-transform: translateX(-50%);
  transform: var(--status-transform);
  transition: transform 220ms ease, top 220ms ease, right 220ms ease, bottom 220ms ease, left 220ms ease, opacity 220ms ease;
}

.status-panel.hidden-panel {
  opacity: 0;
  pointer-events: none;
  transform: var(--status-transform) scale(0.98);
}

.status-panel[data-seat="south"] { left: 1rem; bottom: 1rem; --status-transform: none; }
.status-panel[data-seat="north"] { right: 1rem; top: 1rem; left: auto; --status-transform: rotate(180deg); }
.status-panel[data-seat="east"] { right: 1rem; top: 18%; --status-transform: rotate(90deg); }
.status-panel[data-seat="west"] { left: 1rem; top: 18%; --status-transform: rotate(-90deg); }

.status-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.status-panel-head .ghost-button {
  min-height: 42px;
  padding: 0.75rem 1rem;
}

.status-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.status-stats .pill {
  min-width: 0;
}

.seats-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.seat {
  position: absolute;
  width: var(--seat-width);
  pointer-events: auto;
  z-index: 2;
}

.seat.north { top: 0.35rem; left: 50%; transform: translateX(-50%) rotate(180deg); }
.seat.south { bottom: 0.35rem; left: 50%; transform: translateX(-50%); }
.seat.east { right: 0.35rem; top: 50%; transform: translateY(-50%) rotate(90deg); }
.seat.west { left: 0.35rem; top: 50%; transform: translateY(-50%) rotate(-90deg); }

.seat-card {
  border-radius: 26px;
  padding: 0.8rem;
  background:
    linear-gradient(180deg, rgba(8, 19, 16, 0.9), rgba(7, 24, 21, 0.76));
  border: 1px solid rgba(255, 233, 190, 0.14);
}

.seat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.seat-name {
  margin: 0;
  font-size: 1.05rem;
}

.seat-score {
  font-family: Georgia, serif;
  font-size: 1.35rem;
}

.rack {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding: 0.35rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.1));
}

.rack-tile {
  aspect-ratio: 0.9;
  min-width: 0;
  width: 100%;
  height: auto;
  padding-top: 0.15rem;
}

.seat.active .seat-card {
  box-shadow: 0 0 0 1px rgba(255, 208, 110, 0.28), var(--shadow);
}

.control-dock {
  position: absolute;
  z-index: 3;
  width: min(29vw, 300px);
  transition: transform 240ms ease, top 240ms ease, right 240ms ease, bottom 240ms ease, left 240ms ease;
}

.control-dock[data-seat="south"] { right: 1rem; bottom: 1rem; left: auto; transform: none; }
.control-dock[data-seat="north"] { left: 1rem; top: 1rem; transform: rotate(180deg); }
.control-dock[data-seat="east"] { right: 1rem; top: 50%; transform: translateY(-50%) rotate(90deg); }
.control-dock[data-seat="west"] { left: 1rem; top: 50%; transform: translateY(-50%) rotate(-90deg); }

.dock-card {
  padding: 0.85rem;
  border-radius: 28px;
  background: rgba(4, 24, 19, 0.86);
}

.dock-header,
.dock-actions,
.form-actions {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  justify-content: space-between;
}

.dock-actions {
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.dock-actions button {
  flex: 1 1 40%;
}

.dock-hint {
  font-size: 0.86rem;
  line-height: 1.35;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 10, 8, 0.72);
  backdrop-filter: blur(18px);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(92vw, 460px);
  border-radius: 34px;
  padding: 1.4rem;
}

.form-card {
  display: grid;
  gap: 0.8rem;
}

.form-card label {
  display: grid;
  gap: 0.35rem;
}

@media (max-width: 1100px) {
  .board-wrap {
    width: min(100%, 760px);
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .table-stage {
    min-height: auto;
    padding-bottom: 18rem;
  }

  .seats-layer {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
  }

  .seat,
  .seat.north,
  .seat.south,
  .seat.east,
  .seat.west {
    position: static;
    width: 100%;
    transform: none;
  }

  .control-dock,
  .control-dock[data-seat],
  .board-chassis {
    position: static;
    transform: none;
    width: 100%;
    margin-top: 1rem;
  }

  .board-grid {
    width: min(94vw, 94vw);
    height: min(94vw, 94vw);
  }

  .status-panel {
    position: fixed;
    top: auto;
    right: 0.75rem;
    left: 0.75rem;
    bottom: 0.75rem;
    width: auto;
    --status-transform: none;
    transform: none;
  }

  .status-panel.hidden-panel {
    transform: translateY(12px) scale(0.98);
  }
}
