/* Game night: a lacquered teal table with thick bone tiles.
   Design tokens first; everything below uses them. */
:root {
  --table: #0b3f43;
  --table-light: #13605f;
  --felt-shade: rgba(0, 0, 0, 0.18);
  --felt-deep: rgba(0, 0, 0, 0.24);
  --ink-on-table: #e9f2ec;
  --bone: #f1eadb;
  --bone-edge: #c9bea6;
  --ink: #22302f;
  --jade: #3fb37a;
  --jade-edge: #23804f;
  --amber: #e3a52b;
  --amber-edge: #a97511;
  --amber-text: #f4c25e;
  --absent: #2e4f50;
  --absent-edge: #1c3637;
  --absent-ink: #8faaa6;
  --serif: "Young Serif", Georgia, serif;
  --sans: Figtree, system-ui, sans-serif;
  --drop: 0 5px 8px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--table);
}

body {
  font-family: var(--sans);
  font-weight: 500;
  color: var(--ink-on-table);
  -webkit-tap-highlight-color: transparent;
  background: radial-gradient(120% 80% at 50% 40%, var(--table-light), var(--table)) fixed;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--amber-text);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------ layout */

.table {
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.push {
  margin-top: auto;
}

.caption {
  font-size: 13px;
  opacity: 0.7;
  margin: 0 0 8px;
  text-align: center;
}

.hint {
  font-size: 13px;
  opacity: 0.65;
  text-align: center;
  margin: 10px 0 0;
}

.error {
  color: #ffd7a1;
  font-size: 14px;
  text-align: center;
  margin: 10px 0 0;
}

h2 {
  font: 400 19px var(--serif);
  margin: 0 0 10px;
}

/* ------------------------------------------------------------ tiles */

.tiles {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.tile {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: none;
  font: 400 22px/1 var(--serif);
  text-transform: uppercase;
  border-radius: 7px;
  background: var(--bone);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--bone-edge), var(--drop);
}

.tile.gap {
  width: 8px;
  background: none;
  box-shadow: none;
}

.tile.c {
  background: var(--jade);
  color: #fff;
  box-shadow: 0 3px 0 var(--jade-edge), var(--drop);
}

.tile.p {
  background: var(--amber);
  color: #2a1c00;
  box-shadow: 0 3px 0 var(--amber-edge), var(--drop);
}

.tile.a {
  background: var(--absent);
  color: var(--absent-ink);
  box-shadow: 0 3px 0 var(--absent-edge), var(--drop);
}

.tile.empty {
  background: var(--felt-shade);
  color: var(--ink-on-table);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* ------------------------------------------------------------ buttons */

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--felt-deep);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.btn.wide {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.btn.go {
  background: var(--amber);
  color: #2a1c00;
  box-shadow: 0 3px 0 var(--amber-edge);
}

.btn.go:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--amber-edge);
}

.btn:disabled {
  cursor: default;
  opacity: 0.6;
  transform: none;
}

.btn.quiet {
  background: none;
  font-weight: 600;
  opacity: 0.8;
  padding: 8px;
}

.stack {
  display: grid;
  gap: 8px;
}

/* ------------------------------------------------------------ home */

.logo {
  margin: 9vh 0 12px;
  gap: 5px;
}

.logo .tile {
  width: 46px;
  height: 50px;
  font-size: 28px;
}

.logo .tile:nth-child(odd) {
  transform: rotate(-3deg);
}

.logo .tile:nth-child(even) {
  transform: rotate(2deg) translateY(3px);
}

.tagline {
  text-align: center;
  font-size: 15px;
  opacity: 0.8;
  margin: 16px auto 40px;
  max-width: 30ch;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.8;
  display: block;
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  background: var(--bone);
  color: var(--ink);
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 14px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  opacity: 0.65;
  margin: 26px 0 16px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(233, 242, 236, 0.3);
}

/* The code input is a real <input> laid over tiles that show its value. */
.code-entry {
  position: relative;
  width: fit-content;
  margin: 0 auto 12px;
  border-radius: 10px;
}

.code-entry input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  font-size: 16px; /* stops iOS zooming in */
  cursor: text;
}

.code-entry:focus-within {
  outline: 3px solid var(--amber-text);
  outline-offset: 6px;
}

.code-entry .tile.caret {
  box-shadow: inset 0 0 0 2px var(--bone);
}

/* ------------------------------------------------------------ lobby */

.share {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 12px 0 22px;
}

.player-list {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--felt-shade);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 600;
}

.player-list .tile {
  width: 30px;
  height: 30px;
  font-size: 16px;
}

.player-list small {
  margin-left: auto;
  opacity: 0.65;
  font-weight: 500;
  font-size: 12px;
}

.player-list li.away {
  opacity: 0.55;
}

.player-list li.open {
  background: none;
  border: 1.5px dashed rgba(233, 242, 236, 0.25);
  opacity: 0.7;
  font-weight: 500;
  min-height: 46px;
}

.settings {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 8px;
  align-items: center;
  font-size: 14px;
  padding-bottom: 18px;
  margin: 0;
}

.segmented {
  display: flex;
  background: var(--felt-deep);
  border-radius: 9px;
  padding: 3px;
  border: 0;
  margin: 0;
}

.segmented button {
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  opacity: 0.75;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--bone);
  color: var(--ink);
  opacity: 1;
}

.segmented button:disabled {
  cursor: default;
}

/* ------------------------------------------------------------ game */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}

.topbar .room {
  font: 400 19px var(--serif);
}

.topbar .meta {
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.topbar .meta.low {
  color: var(--amber-text);
  opacity: 1;
}

.seats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.seat {
  background: var(--felt-shade);
  border-radius: 12px;
  padding: 8px 8px 7px;
}

.seat.first {
  outline: 2px solid var(--amber);
}

.seat.away {
  opacity: 0.5;
}

.seat-head {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.seat-head span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-head span:last-child {
  opacity: 0.7;
  font-weight: 600;
  flex: none;
}

.seat.first .seat-head span:last-child {
  color: var(--amber-text);
  opacity: 1;
}

.seat .waiting {
  font-size: 12px;
  opacity: 0.65;
  height: 72px;
  display: grid;
  place-items: center;
  text-align: center;
}

/* Colour-only miniature of a board. */
.mini {
  display: grid;
  gap: 2px;
  width: 62px;
  margin: 0 auto;
}

.mini-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.mini-row i {
  aspect-ratio: 1;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.mini-row i.c {
  background: var(--jade);
}

.mini-row i.p {
  background: var(--amber);
}

.mini-row i.a {
  background: var(--bone);
  opacity: 0.35;
}

.board {
  --size: min(300px, 100%, calc((100dvh - 430px) * 5 / 6));
  width: max(200px, var(--size));
  margin: 0 auto 14px;
  display: grid;
  gap: 7px;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.board .tile {
  width: auto;
  height: auto;
  aspect-ratio: 1;
  font-size: clamp(20px, calc(var(--size) / 9), 32px);
}

.board .tile.typed {
  background: var(--bone);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--bone-edge), var(--drop);
}

.board-row.shake {
  animation: shake 0.4s;
}

.tile.flip {
  animation: flip 0.5s ease-in-out both;
  animation-delay: var(--delay);
}

@keyframes flip {
  0% {
    transform: rotateX(0);
    background: var(--bone);
    color: var(--ink);
    box-shadow: 0 3px 0 var(--bone-edge), var(--drop);
  }
  49% {
    background: var(--bone);
    color: var(--ink);
    box-shadow: 0 3px 0 var(--bone-edge), var(--drop);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.status-line {
  min-height: 20px;
  text-align: center;
  font-size: 14px;
  margin: 0 0 12px;
}

.spectating {
  margin: 30px 0;
  text-align: center;
}

.spectating p {
  opacity: 0.8;
  margin: 6px 0 0;
}

.keyboard {
  display: grid;
  gap: 7px;
  margin-top: auto;
}

.keyboard-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  flex: 1;
  max-width: 40px;
  height: 52px;
  border: 0;
  border-radius: 6px;
  background: var(--bone);
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 0 var(--bone-edge);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}

.key:active {
  transform: translateY(2px);
  box-shadow: none;
}

.key.wide {
  max-width: 62px;
  flex: 1.5;
  font-size: 12px;
}

.key.c {
  background: var(--jade);
  color: #fff;
  box-shadow: 0 2px 0 var(--jade-edge);
}

.key.p {
  background: var(--amber);
  color: #2a1c00;
  box-shadow: 0 2px 0 var(--amber-edge);
}

.key.a {
  background: var(--absent);
  color: var(--absent-ink);
  box-shadow: 0 2px 0 var(--absent-edge);
}

/* ------------------------------------------------------------ results */

.reveal {
  text-align: center;
  margin: 8px 0 18px;
}

.columns {
  font-size: 12px;
  opacity: 0.65;
  display: flex;
  justify-content: flex-end;
  gap: 22px;
  padding-right: 12px;
  margin: 0 0 6px;
}

.ranking {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.ranking li {
  display: grid;
  grid-template-columns: 36px 1fr auto 34px;
  gap: 10px;
  align-items: center;
  background: var(--felt-shade);
  border-radius: 12px;
  padding: 9px 10px;
}

.ranking li.first {
  outline: 2px solid var(--amber);
}

.ranking li.me {
  background: rgba(241, 234, 219, 0.12);
}

.ranking .mini {
  width: 36px;
  gap: 1.5px;
}

.ranking .mini-row {
  gap: 1.5px;
}

.who b {
  display: block;
  font-weight: 700;
}

.who span {
  font-size: 12px;
  opacity: 0.7;
}

.points {
  font: 400 16px var(--serif);
  color: var(--amber-text);
  text-align: right;
}

.points.none {
  color: var(--ink-on-table);
  opacity: 0.4;
}

.total {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ------------------------------------------------------------ final */

.winner {
  text-align: center;
  margin: 10px 0 6px;
}

.winner .tiles {
  margin: 8px 0 12px;
  flex-wrap: wrap;
}

.winner h1 {
  font: 400 27px var(--serif);
  margin: 0;
}

.winner p {
  margin: 6px 0 0;
  opacity: 0.75;
  font-size: 14px;
}

.standings {
  display: grid;
  gap: 8px;
  margin: 22px 0 16px;
  padding: 0;
  list-style: none;
}

.standings li {
  display: grid;
  grid-template-columns: 22px 1fr auto 34px;
  gap: 10px;
  align-items: center;
  background: var(--felt-shade);
  border-radius: 12px;
  padding: 10px 12px;
}

.standings li.first {
  outline: 2px solid var(--amber);
}

.standings li.me {
  background: rgba(241, 234, 219, 0.12);
}

.standings .place,
.standings .total {
  font: 400 18px var(--serif);
}

.standings .place {
  opacity: 0.75;
}

.bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 22px;
}

.bars i {
  width: 7px;
  border-radius: 2px;
  background: var(--jade);
}

.bars i.none {
  background: rgba(233, 242, 236, 0.25);
}

/* ------------------------------------------------------------ overlays */

.toast {
  position: fixed;
  left: 50%;
  /* Just above the keyboard, clear of the opponents' boards. */
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 190px);
  transform: translateX(-50%);
  background: var(--bone);
  color: var(--ink);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--drop);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.toast.show {
  opacity: 1;
}

.banner {
  background: var(--amber);
  color: #2a1c00;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  padding: 6px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.qr-dialog {
  border: 0;
  border-radius: 16px;
  background: var(--table);
  color: var(--ink-on-table);
  padding: 20px;
  text-align: center;
}

.qr-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.qr-dialog img {
  display: block;
  margin: 0 auto 16px;
  border-radius: 10px;
}

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