/* Cutthroat Dominoes — wooden table, styled after a real domino table:
   warm light-wood frame, woven herringbone playing surface in golden-brown,
   dark walnut border, brass cup holders at the four corners. */
:root {
  --wood-light: #d9a860;
  --wood-mid: #b9823f;
  --wood-dark: #7a4a1f;
  --walnut: #4a2c14;
  --walnut-deep: #2e1a0b;
  --herring-a: #c99a4b;
  --herring-b: #a87a33;
  --herring-c: #e0b96e;
  --brass: #d4af37;
  --brass-deep: #8a6d1f;
  --felt-shadow: rgba(0, 0, 0, 0.45);
  --ink: #241708;
  --paper: #f7ecd7;
  --bone: #fbf6ea;
  --bone-edge: #cbb98f;
  --accent: #1f6f43;
  --gold: #ffd75e;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; overflow-x: clip; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #12351f radial-gradient(1200px 700px at 50% -10%, #1d5c33, #0d2a17);
  color: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
input { font: inherit; font-size: 16px; }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; padding: 10px 16px;
  background: linear-gradient(180deg, #3a2410, #241708);
  border-bottom: 3px solid var(--brass-deep);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; letter-spacing: 0.5px; font-size: 20px; color: #f3d98b; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-chip { font-size: 13px; color: #e8d5a8; }

.btn {
  background: linear-gradient(180deg, #e8c078, #c99a4b);
  color: #241708; border: 1px solid #6b4a1d; border-radius: 8px;
  padding: 9px 14px; font-weight: 700;
}
.btn:hover { filter: brightness(1.07); }
.btn.primary { background: linear-gradient(180deg, #37a05e, #1f6f43); color: #fff; border-color: #0f4d28; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; margin: 8px 0; }
.btn:disabled { opacity: 0.55; cursor: default; }

main { padding: 16px; max-width: 1180px; margin: 0 auto; }
.view { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ------------------------------ lobby ------------------------------ */
/* Welcome screen: the photo of Andy's own dominoes fills the whole
   lobby behind the login card (relative path, so it works offline on
   the home network). The card sits on top of it. */
#view-lobby {
  background: url("welcome-hero.jpg") center / cover no-repeat;
  margin: -16px calc(50% - 50vw) -16px;
  padding: 28px 16px 48px;
  min-height: calc(100vh - 48px);
  min-height: calc(100dvh - 48px);
}
.lobby-card {
  max-width: 560px; margin: 24px auto; padding: 24px;
  background: linear-gradient(180deg, #fdf6e3, #f3e3bd);
  color: var(--ink); border-radius: 14px;
  border: 3px solid var(--walnut);
  box-shadow: 0 10px 30px var(--felt-shadow);
}
.lobby-card h1 { margin: 0 0 6px; font-size: 28px; }

/* Welcome hero: title and tagline over the domino photo. The photo is
   the centrepiece now, so the hero is just text with a soft dark wash
   behind it for legibility. */
.lobby-hero {
  margin: 0 auto 18px;
  padding: 16px 16px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(24, 10, 32, 0.5), rgba(24, 10, 32, 0.2));
  text-align: center;
  animation: hero-fade 0.45s ease both;
}
@keyframes hero-fade { from { opacity: 0; } to { opacity: 1; } }
.lobby-hero h1 {
  margin: 0 0 4px; font-size: 34px; letter-spacing: 0.5px;
  color: var(--gold);
  text-shadow: 0 2px 0 #2e1a0b, 0 4px 12px rgba(0,0,0,0.65);
}
.lobby-hero .tagline { margin: 0; color: #ffe9ad; text-shadow: 0 1px 3px rgba(0,0,0,0.7); }
.tagline { margin: 0 0 16px; color: #5b4322; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  flex: 1; padding: 8px; border-radius: 8px 8px 0 0;
  background: #e2cd9c; border: 1px solid #b99b62; border-bottom: none; font-weight: 700; color: #5b4322;
}
.tab.active { background: #fff8e6; color: var(--ink); }
#auth-form {
  background: #fff8e6; border: 1px solid #b99b62; border-radius: 0 0 8px 8px;
  padding: 14px; margin-bottom: 10px;
}
#auth-form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
#auth-form input, .join-row input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid #b99b62; border-radius: 8px; background: #fff;
}
.fine { font-size: 13px; color: #6d5427; }
.error {
  background: #fde3e3; color: #7a1414; border: 1px solid #d98a8a;
  border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 14px;
}
.welcome { font-size: 17px; }
.join-row { display: flex; gap: 8px; margin: 8px 0; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 2px; font-weight: 700; }
.code-box {
  margin-top: 14px; padding: 14px; border: 2px dashed var(--wood-dark);
  border-radius: 10px; background: #fff8e6; text-align: center;
}
.invite-code {
  font-size: 34px; font-weight: 800; letter-spacing: 8px; margin: 6px 0;
  color: var(--walnut-deep);
}

/* ------------------------------ game ------------------------------- */
.game-top {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  justify-content: space-between; margin-bottom: 12px;
}
.scoreboard { display: flex; gap: 8px; flex-wrap: wrap; }
.score-chip {
  background: #241708; border: 2px solid #6b4a1d; border-radius: 10px;
  padding: 6px 12px; font-size: 14px; min-width: 110px;
}
.score-chip .nm { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.score-chip .pts { color: var(--gold); font-weight: 800; }
.score-chip.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 215, 94, 0.5); }
.score-chip .jail { color: #ff9d9d; font-size: 11px; font-weight: 700; }
.score-chip .you-tag { color: #9be7b4; font-size: 11px; font-weight: 700; }
.game-meta { display: flex; gap: 10px; align-items: center; }
#game-info { font-size: 14px; color: #e8d5a8; }

/* The wooden table. Frame: light wood with plank grain. Playing surface:
   woven herringbone in golden-brown, ringed by a dark walnut border. */
.table-wrap { display: flex; justify-content: center; }
.domino-table {
  position: relative;
  width: 100%; max-width: 1120px; min-height: 560px;
  border-radius: 18px; padding: 26px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.05) 0 3px, transparent 3px 90px),
    linear-gradient(160deg, var(--wood-light), var(--wood-mid) 55%, #a06a2c);
  border: 4px solid var(--walnut-deep);
  box-shadow: 0 18px 40px var(--felt-shadow), inset 0 0 0 2px rgba(255, 235, 180, 0.25);
  display: grid;
  grid-template-columns: 150px 1fr 150px;
  grid-template-rows: 74px 1fr 74px;
  grid-template-areas:
    ". top ."
    "left board right"
    ". bottom .";
  gap: 6px;
}
.domino-table::before {
  content: ""; position: absolute; inset: 14px; border-radius: 12px;
  border: 10px solid var(--walnut);
  box-shadow: inset 0 0 0 2px #1d0f04, inset 0 4px 18px rgba(0,0,0,0.5);
  pointer-events: none;
}
.cup {
  position: absolute; width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f7e08a, var(--brass) 45%, var(--brass-deep) 75%, #5c4712);
  border: 3px solid #3a2a08;
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.55), 0 2px 4px rgba(0,0,0,0.4);
  z-index: 3;
}
.cup-tl { top: 6px; left: 6px; }
.cup-tr { top: 6px; right: 6px; }
.cup-bl { bottom: 6px; left: 6px; }
.cup-br { bottom: 6px; right: 6px; }

.board {
  grid-area: board; position: relative; z-index: 2;
  min-height: 330px; border-radius: 8px; padding: calc(18px * var(--bs, 1));
  /* --bs is the tile scale the layout engine sets from the board's
     measured width (1 on desktop, down to 0.5 on a phone). Pips and
     padding scale with it so small bones still read as dominoes. */
  /* woven herringbone: two diagonal weaves over golden-brown tones */
  background-color: var(--herring-b);
  background-image:
    repeating-linear-gradient(45deg, rgba(224,185,110,0.55) 0 10px, rgba(168,122,51,0.55) 10px 20px, rgba(120,82,28,0.35) 20px 22px),
    repeating-linear-gradient(-45deg, rgba(224,185,110,0.5) 0 10px, rgba(140,98,36,0.5) 10px 20px, rgba(90,60,18,0.35) 20px 22px);
  box-shadow: inset 0 0 0 3px rgba(46,26,11,0.8), inset 0 6px 24px rgba(0,0,0,0.45);
}
/* Board bones are placed absolutely by the layout engine (renderBoard),
   so the chain can run out along the first row and drop vertically from
   the ends of rows. Their pips scale with --bs (see .board above). */
.board .bone { position: absolute; }
.board .bone .half { padding: calc(3px * var(--bs, 1)); }
.board .bone { border-radius: calc(6px * var(--bs, 1)); }
.board .pip { width: calc(7px * var(--bs, 1)); height: calc(7px * var(--bs, 1)); }
.seat {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: center;
  text-align: center; font-weight: 700; color: #fff8e6;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7); font-size: 14px;
  padding: 4px; overflow: hidden;
}
.seat .seat-inner { max-width: 100%; }
.seat .seat-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .seat-count { display: block; font-size: 12px; font-weight: 600; color: #ffe9ad; }
.seat.turn { color: var(--gold); }
.seat-top { grid-area: top; }
.seat-left { grid-area: left; }
.seat-right { grid-area: right; }
.seat-bottom { grid-area: bottom; }

/* Domino bones */
.bone {
  width: 66px; height: 34px; background: linear-gradient(180deg, #fffdf6, var(--bone));
  border: 1px solid var(--bone-edge); border-radius: 6px;
  display: flex; flex-direction: row; flex: 0 0 auto;
  box-shadow: 0 2px 4px rgba(0,0,0,0.45);
  position: relative;
}
.bone.double { width: 34px; height: 66px; flex-direction: column; }
/* An upright bone that is not a double — a bone in the vertical drop
   at the end of a row. */
.bone.vertical { width: 34px; height: 66px; flex-direction: column; }
.bone.vertical:not(.double) .half + .half { border-top: 1px solid #b3a075; border-left: none; }
.bone .half {
  flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 3px; position: relative;
}
.bone:not(.double) .half + .half { border-left: 1px solid #b3a075; }
.bone.double .half + .half { border-top: 1px solid #b3a075; }
.pip {
  width: 7px; height: 7px; border-radius: 50%; background: #241708;
  place-self: center; box-shadow: inset 0 1px 1px rgba(0,0,0,0.6);
}
.bone.hard-end { outline: 3px solid var(--gold); outline-offset: 1px; }
.bone.pose { box-shadow: 0 0 0 2px var(--gold), 0 0 12px rgba(255, 215, 94, 0.55); }
.bone.playable { cursor: pointer; outline: 3px solid #37a05e; outline-offset: 1px; transform: translateY(-3px); touch-action: manipulation; }
.bone.playable:hover { outline-color: var(--gold); }
.bone.selected { outline: 3px solid #ff8c1a; outline-offset: 1px; transform: translateY(-3px); }

.hand {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin: 14px auto 6px; padding: 12px; max-width: 1120px;
  background: rgba(0,0,0,0.35); border-radius: 12px; min-height: 92px;
}
.hand .bone { width: 76px; height: 40px; }
.hand .bone.double { width: 40px; height: 76px; }
.hand-actions { text-align: center; margin-bottom: 8px; }
.turn-banner {
  text-align: center; font-weight: 700; min-height: 24px; margin-top: 10px;
  color: #ffe9ad; font-size: 16px;
}
/* Onlooker table talk: a toast over the table showing the spoken line. */
.onlooker-toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 30; pointer-events: none; max-width: 92vw; text-align: center;
  background: rgba(24, 10, 32, 0.92); color: var(--gold);
  border: 2px solid var(--brass); border-radius: 999px;
  padding: 10px 22px; font-size: 19px; font-weight: 800; letter-spacing: 0.3px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  animation: toast-in 0.25s ease both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.end-chooser { text-align: center; margin: 6px 0; }
.end-chooser .btn { margin: 0 4px; }

.log-box {
  max-width: 1120px; margin: 10px auto; background: rgba(0,0,0,0.35);
  border-radius: 12px; padding: 12px 16px;
}
.log-box h2 { margin: 0 0 6px; font-size: 15px; color: #e8d5a8; }
.log-box ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.55; max-height: 160px; overflow-y: auto; }
.log-box li.bruk { color: #ffb3b3; font-weight: 700; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px;
}
.overlay-card {
  background: linear-gradient(180deg, #fdf6e3, #f3e3bd); color: var(--ink);
  border-radius: 14px; border: 3px solid var(--walnut); padding: 24px; max-width: 440px; text-align: center;
}
.overlay-card h2 { margin-top: 0; }

/* ---------------------------- rankings ----------------------------- */
.rankings-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.rankings-table th, .rankings-table td {
  border-bottom: 1px solid #cbb27e; padding: 8px 6px; text-align: left; font-size: 15px;
}
.rankings-table tr.you { background: #ffe9ad; font-weight: 700; }

/* ----------------------------- drawer ------------------------------ */
.drawer {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 50;
  display: flex; justify-content: flex-end;
}
.drawer-card {
  width: min(520px, 94vw); height: 100%; overflow-y: auto;
  background: linear-gradient(180deg, #fdf6e3, #f3e3bd); color: var(--ink);
  padding: 22px; border-left: 4px solid var(--walnut);
}
.drawer-card h2 { margin-top: 4px; }
.drawer-card h3 { margin: 16px 0 4px; }
.drawer-card ul { padding-left: 20px; line-height: 1.5; }
.drawer-card p { line-height: 1.55; }

@media (max-width: 900px) {
  /* Narrow screens: the seats move out of the side columns so the board
     gets the full width of the table — with 150px seats on each side a
     phone board had almost no room and the chain spilled off it. */
  .domino-table {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "top top"
      "board board"
      "left right"
      "bottom bottom";
    min-height: 0;
    padding: 12px;
    gap: 4px;
  }
  .board { min-height: 220px; }
  .cup { width: 36px; height: 36px; }
  .seat { min-height: 36px; }
}

@media (max-width: 760px) {
  main { padding: 12px 10px; }
  #view-lobby { margin: -12px calc(50% - 50vw) -12px; }
  .lobby-card { padding: 20px 16px; margin: 16px auto; }
  .lobby-hero h1 { font-size: 28px; }
  .invite-code { font-size: 28px; letter-spacing: 6px; }
  /* Touch targets: hand bones and buttons are at least 44px tall so a
     finger can hit them reliably. Hand bones stay 2:1, so they wrap. */
  .hand .bone { width: 88px; height: 44px; }
  .hand .bone.double { width: 44px; height: 88px; }
  .hand .pip { width: 8px; height: 8px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 44px; padding: 10px 14px; }
  .tab { min-height: 44px; }
  .score-chip { min-width: 0; font-size: 12px; padding: 5px 8px; }
  .brand { font-size: 16px; }
}

@media (max-width: 560px) {
  /* Rankings table: shrink type and let long names ellipsize so the
     table fits a phone without sideways page scrolling. */
  .rankings-table th, .rankings-table td { padding: 6px 4px; font-size: 13px; }
  .rankings-table td:nth-child(2) {
    max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
}
