/* Carcassonne · BoardBazi
   Phone first: players on top, the map in the middle, the drawn tile and the action buttons at the bottom.
   body.lay-desktop puts players, the tile and the game log in a sidebar next to a large map.
   Colours: parchment panels, castle-roof red, Carcassonne blue and wheat gold on a dark meadow. */

:root {
  --bg: #1c2620;
  --bg-2: #243128;
  --table: #2b3a2d;
  --panel: #f5ead0;
  --panel-2: #eadcb8;
  --ink: #34281a;
  --ink-2: #7a6a50;
  --line: rgba(70, 50, 20, .18);
  --gold: #e0a92e;
  --gold-2: #b9821c;
  --blue: #23508f;
  --roof: #b8432c;
  --grass: #6aa84f;
  --radius: 12px;
  --app-h: 100vh;
  --bar-h: 40px;
  --font: Vazirmatn, "Vazir", Tahoma, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  /* Player colours */
  --p-red: #d23a2a;
  --p-blue: #2c66d4;
  --p-yellow: #e9b710;
  --p-green: #2f9a45;
  --p-black: #2a2a2a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: 15px;
  line-height: 1.5;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
body.busy { cursor: progress; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 14px; border-radius: 11px;
  border: 1px solid var(--line); background: #fffaf0; color: var(--ink);
  text-decoration: none; font-weight: 700; white-space: nowrap;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn-gold { background: linear-gradient(180deg, #f1c45a, var(--gold-2)); border-color: #9a6a12; color: #2a1c04; }
.btn-blue { background: linear-gradient(180deg, #3a6db3, var(--blue)); border-color: #173a6a; color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { background: #f6d9d1; border-color: #dba08f; color: #7a2412; }
.btn-lg { min-height: 50px; font-size: 17px; width: 100%; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn-xs { min-height: 28px; min-width: 28px; padding: 2px 8px; font-size: 13px; }
.icon-btn { background: transparent; border: 0; color: #fff; font-size: 22px; width: 42px; height: 42px; flex: none; }

.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--ink-2); font-weight: 700; }
.tag-off { background: #f2d6cf; color: #8b2e1a; }

/* ---------------- splash ---------------- */
.splash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #34503a, var(--bg)); transition: opacity .45s; }
.splash.gone { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; color: var(--panel); }
.splash-logo { width: 84px; height: 84px; object-fit: contain; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .45)); animation: hop 1.6s ease-in-out infinite; }
.splash-title { font-size: 26px; letter-spacing: .32em; font-weight: 300; margin: 12px 0 18px; padding-inline-start: .32em; }
.splash-bar { width: 220px; height: 6px; background: rgba(255, 255, 255, .15); border-radius: 6px; overflow: hidden; margin: 0 auto; }
.splash-fill { height: 100%; width: 0; background: var(--gold); transition: width .2s; }
.splash-text { margin-top: 10px; font-size: 13px; opacity: .8; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-14px) rotate(-6deg); } 60% { transform: translateY(0) rotate(0); } }

/* ---------------- BoardBazi bar ---------------- */
.bb-bar {
  position: fixed; inset-inline: 0; top: 0; z-index: 30;
  height: calc(var(--bar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  padding-inline: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(14, 18, 29, .92); border-bottom: 1px solid rgba(255, 255, 255, .08); color: #f8fafc;
  backdrop-filter: blur(6px);
}
.bb-bar a { color: inherit; text-decoration: none; }
.bb-brand { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; min-width: 0; }
.bb-mark { width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(135deg, #6366f1, #06b6d4); display: grid; place-items: center; color: #fff; flex: none; }
.bb-chip { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.bb-initial { width: 24px; height: 24px; border-radius: 50%; background: #334155; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.bb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.bb-level { font-size: 12px; color: #94a3b8; white-space: nowrap; }
.bb-xp { width: 48px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .15); overflow: hidden; flex: none; }
.bb-xp-fill { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #06b6d4); }
.bb-signin { font-size: 13px; color: #cbd5e1 !important; }
body.with-bar .view-intro { padding-top: calc(var(--bar-h) + env(safe-area-inset-top) + 12px); }
/* Results screen: the bar sits above the table */
body.with-bar .view-game { padding-top: calc(var(--bar-h) + env(safe-area-inset-top)); }
body.with-bar .g-top { padding-top: 0; min-height: 46px; }
@media (max-width: 380px) { .bb-word { display: none; } }

/* ---------------- intro / home / lobby ---------------- */
.app { min-height: var(--app-h); }
.view-intro { position: relative; min-height: var(--app-h); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; }
.intro-hero { position: fixed; inset: 0; background: url(img/ui/hero.webp) center / cover no-repeat; }
.intro-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(16, 24, 18, .15), rgba(16, 24, 18, .72)); }
@media (orientation: portrait) { .intro-hero { background-image: url(img/ui/hero-tall.webp); background-position: center top; } }
.intro-card {
  position: relative; z-index: 1; width: 100%; max-width: 440px;
  background: rgba(245, 234, 208, .96); border-radius: 18px; padding: 22px 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .4); display: flex; flex-direction: column; gap: 12px;
  border: 1px solid rgba(255, 255, 255, .5);
}
.intro-box { width: 96px; align-self: center; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); margin-top: -6px; }
.intro-title { margin: 0; text-align: center; font-size: 30px; color: var(--blue); letter-spacing: .02em; }
.intro-sub { margin: -8px 0 0; text-align: center; color: var(--roof); font-size: 14px; font-weight: 700; }
.intro-text { margin: 0; color: var(--ink); font-size: 14.5px; text-align: justify; }
.intro-hint { background: #fff3cf; border-radius: 8px; padding: 8px 10px; margin: 0; font-size: 14px; }
.intro-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.intro-link { text-align: center; color: var(--blue); text-decoration: none; font-size: 14px; }
.intro-note { margin: 0; text-align: center; font-size: 12px; color: var(--ink-2); }
.lang-switch { display: flex; gap: 4px; justify-content: flex-end; }
.lang-switch button { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 2px 10px; font-size: 13px; }
.lang-switch button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.dev-login { border-top: 1px dashed var(--line); padding-top: 10px; font-size: 13px; }
.dev-login .row { display: flex; gap: 6px; margin-top: 4px; }
.dev-login input, .join-form input { flex: 1; min-width: 0; min-height: 42px; border-radius: 10px; border: 1px solid var(--line); padding: 6px 10px; font: inherit; background: #fff; }
.home-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.home-hello { color: var(--ink-2); font-size: 13px; }
.home-name { font-size: 22px; font-weight: 800; overflow-wrap: anywhere; }
.home-tools { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.home-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.home-stats:empty { display: none; }
.home-stats div { background: var(--panel-2); border-radius: 10px; padding: 8px; text-align: center; }
.home-stats b { display: block; font-size: 20px; }
.home-stats span { font-size: 12px; color: var(--ink-2); }
.divider { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-form { display: flex; gap: 8px; }
.join-form input { text-transform: uppercase; letter-spacing: .2em; text-align: center; font-weight: 800; }
#btn-rules-home { align-self: center; }

.lobby-top { display: flex; align-items: center; gap: 10px; }
.chip { background: var(--panel-2); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.lobby-code { flex: 1; font-size: 30px; font-weight: 800; letter-spacing: .18em; color: var(--blue); text-align: center; }
.lobby-help { margin: 0; color: var(--ink-2); font-size: 13.5px; }
.lobby-count { font-weight: 700; font-size: 14px; }
.lobby-seats { display: flex; flex-direction: column; gap: 6px; }
.seat { display: flex; align-items: center; gap: 8px; background: #fffaf0; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-height: 44px; }
.seat-meeple { width: 26px; height: 26px; object-fit: contain; flex: none; }
.seat-empty { border-style: dashed; background: transparent; color: var(--ink-2); }
.seat-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px dashed var(--line); flex: none; }
.seat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.seat-name small { color: var(--ink-2); font-weight: 400; }
.lobby-settings { display: flex; flex-direction: column; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.toggle > span:first-child { flex: 1; display: flex; flex-direction: column; }
.toggle strong { font-size: 14px; }
.toggle small { color: var(--ink-2); font-size: 12px; line-height: 1.4; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { width: 44px; height: 26px; border-radius: 26px; background: #c9b996; position: relative; flex: none; transition: background .15s; }
.toggle-ui::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.toggle input:checked + .toggle-ui { background: var(--blue); }
.toggle input:checked + .toggle-ui::after { inset-inline-start: 21px; }
.toggle input:disabled + .toggle-ui { opacity: .55; }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--gold); outline-offset: 2px; }
.lobby-actions { display: flex; gap: 8px; }
.lobby-actions .btn { flex: 1; }

/* ---------------- game view ---------------- */
.view-game {
  height: var(--app-h); overflow: hidden; color: #f3ead6;
  display: grid; grid-template-columns: 100%;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "players" "board" "dock";
  background: var(--bg);
}
.g-top {
  grid-area: top; display: flex; align-items: center; gap: 6px;
  padding: env(safe-area-inset-top) 8px 0; min-height: calc(46px + env(safe-area-inset-top));
  background: linear-gradient(180deg, #121a15, #18221b);
}
.g-status { flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }
.g-timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 14px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .1); }
.g-timer.low { background: #b8432c; color: #fff; animation: pulse 1s infinite; }
.g-conn { width: 9px; height: 9px; border-radius: 50%; background: #4caf50; margin-inline: 4px; flex: none; }
.g-conn.lost { background: #e0533a; }
@keyframes pulse { 50% { opacity: .55; } }

/* Players */
.g-players {
  grid-area: players; display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto;
  background: #18221b; border-bottom: 1px solid rgba(255, 255, 255, .06); scrollbar-width: none;
}
.g-players::-webkit-scrollbar { display: none; }
.pl {
  flex: 1 1 0; min-width: 84px; display: flex; flex-direction: column; gap: 1px;
  padding: 4px 8px; border-radius: 10px; background: rgba(255, 255, 255, .06);
  border: 2px solid transparent; position: relative; cursor: pointer; text-align: start;
}
.pl.turn { border-color: var(--pc); background: rgba(255, 255, 255, .12); box-shadow: 0 0 14px -2px var(--pc); }
.pl.gone { opacity: .55; }
.pl-top, .pl-bottom { display: flex; align-items: center; gap: 5px; min-width: 0; }
.pl-meeple { width: 20px; height: 20px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .5)); flex: none; }
.pl-name { font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pl-name small { font-weight: 400; color: #c9bfa8; }
.pl-score { font-size: 19px; font-weight: 900; color: #fff; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pl-left { display: flex; align-items: center; gap: 2px; font-size: 11.5px; color: #c9bfa8; white-space: nowrap; margin-inline-start: auto; }
.pl-mini { width: 13px; height: 13px; object-fit: contain; }
.pl-tag { font-size: 10px; padding: 0 5px; border-radius: 6px; background: #8b2e1a; color: #fff; white-space: nowrap; }
.pl-bump { animation: bump .7s; }
@keyframes bump { 30% { transform: scale(1.12); } }

/* Map */
.g-board-wrap { grid-area: board; position: relative; min-height: 0; overflow: hidden; }
.board {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--table);
  background-image:
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
  cursor: grab;
}
.board:active { cursor: grabbing; }
.board::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 80px rgba(0, 0, 0, .45); }
.world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; will-change: transform; }
.world.glide { transition: transform .35s cubic-bezier(.2, .8, .2, 1); }
.layer { position: absolute; left: 0; top: 0; }
/* Fixed stacking: tiles, then marks, meeples, the tile being placed and spots, then floating points */
.layer-tiles { z-index: 1; }
.layer-marks { z-index: 2; }
.layer-meeples { z-index: 3; }
.layer-ui { z-index: 4; }
.layer-fx { z-index: 5; }
.layer img { max-width: none; }
.tile { position: absolute; width: 100px; height: 100px; box-shadow: 0 1px 2px rgba(0, 0, 0, .55); background: #6aa84f; }
.tile img { width: 100%; height: 100%; display: block; pointer-events: none; }
.tile.drop { animation: drop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes drop { from { transform: scale(1.25); opacity: .3; } }
.tile.last::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--lc, #fff), 0 0 12px 1px var(--lc, #fff); pointer-events: none; }
.tile.last[data-color="red"] { --lc: var(--p-red); }
.tile.last[data-color="blue"] { --lc: var(--p-blue); }
.tile.last[data-color="yellow"] { --lc: var(--p-yellow); }
.tile.last[data-color="green"] { --lc: var(--p-green); }
.tile.last[data-color="black"] { --lc: #f5f5f5; }
.cand {
  position: absolute; width: 100px; height: 100px; border-radius: 6px;
  border: 3px dashed rgba(255, 220, 120, .8); background: rgba(255, 220, 120, .13);
  animation: cand 1.6s ease-in-out infinite; pointer-events: none;
}
@keyframes cand { 50% { background: rgba(255, 220, 120, .26); } }
.ghost { position: absolute; width: 100px; height: 100px; z-index: 2; pointer-events: none; }
.ghost img { width: 100%; height: 100%; display: block; transition: transform .18s; }
.ghost::after { content: ""; position: absolute; inset: -3px; border-radius: 4px; border: 4px solid var(--gold); box-shadow: 0 0 18px var(--gold); }
.ghost.bad img { opacity: .55; filter: grayscale(.6); }
.ghost.bad::after { border-color: #e0533a; box-shadow: 0 0 18px #e0533a; }
.ghost.preview { opacity: .75; }
.ghost.preview::after { border-width: 2px; box-shadow: none; }
.meeple { position: absolute; width: 26px; height: 26px; object-fit: contain; transform: translate(-50%, -62%); filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .65)); pointer-events: none; }
.meeple.farmer { transform: translate(-50%, -50%) rotate(90deg); }
.spot {
  position: absolute; width: 38px; height: 38px; margin: -19px 0 0 -19px; padding: 0; border-radius: 50%;
  /* Same size on screen at any zoom, but never wider than about a third of the tile */
  transform: scale(min(var(--inv, 1), .95)); border: 3px solid #fff; background: rgba(20, 20, 20, .45);
  display: grid; place-items: center; font-size: 17px; line-height: 1; z-index: 3;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5); animation: spot 1.4s ease-in-out infinite;
}
.spot[data-color="red"] { border-color: var(--p-red); }
.spot[data-color="blue"] { border-color: var(--p-blue); }
.spot[data-color="yellow"] { border-color: var(--p-yellow); }
.spot[data-color="green"] { border-color: var(--p-green); }
.spot[data-color="black"] { border-color: #111; background: rgba(255, 255, 255, .45); }
.spot.sel { background: rgba(255, 255, 255, .92); animation: none; }
.spot img { width: 28px; height: 28px; object-fit: contain; }
.spot img.farmer { transform: rotate(90deg); }
@keyframes spot { 50% { box-shadow: 0 0 0 6px rgba(255, 255, 255, .25), 0 2px 8px rgba(0, 0, 0, .5); } }
.flash { position: absolute; z-index: 5; pointer-events: none; transform: scale(var(--inv, 1)); }
.flash span {
  display: block; transform: translate(-50%, -50%); padding: 3px 10px; border-radius: 999px; font-weight: 900; font-size: 18px; color: #fff;
  background: linear-gradient(90deg, var(--c1), var(--c2)); border: 2px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .5);
  animation: flash 2.2s ease-out forwards; white-space: nowrap;
}
@keyframes flash { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 70% { opacity: 1; transform: translate(-50%, -110%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -160%); } }

.board-tools { position: absolute; inset-inline-end: 8px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 4; }
.tool-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .15); background: rgba(18, 26, 21, .78); color: #fff; font-size: 20px; line-height: 1; backdrop-filter: blur(4px); display: grid; place-items: center; }
.tool-btn:active { transform: scale(.94); }
.g-toast { position: absolute; inset-inline: 12px; top: 10px; z-index: 6; margin: 0 auto; max-width: 420px; background: rgba(18, 26, 21, .9); color: #fff; border-radius: 12px; padding: 8px 12px; font-size: 13.5px; text-align: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }

/* Dock: the drawn tile and the buttons */
.g-dock {
  grid-area: dock; display: flex; gap: 10px; align-items: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #1d2a20, #141d17); border-top: 1px solid rgba(255, 255, 255, .08);
}
.dock-tile { position: relative; width: 74px; height: 74px; flex: none; padding: 0; border: 0; border-radius: 6px; background: rgba(255, 255, 255, .06); box-shadow: 0 3px 10px rgba(0, 0, 0, .5); }
.dock-tile img { width: 100%; height: 100%; border-radius: 4px; display: block; transition: transform .2s; }
.dock-tile img[src=""], .dock-tile img:not([src]) { visibility: hidden; }
.dock-tile.mine { outline: 3px solid var(--gold); outline-offset: 2px; }
.dock-tile.empty { background: repeating-linear-gradient(45deg, rgba(255, 255, 255, .05) 0 6px, transparent 6px 12px); box-shadow: none; }
.dock-count { position: absolute; bottom: -6px; inset-inline-end: -6px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 800; border-radius: 999px; padding: 1px 7px; border: 2px solid #141d17; white-space: nowrap; }
.dock-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.dock-text { font-size: 13.5px; color: #e6dcc4; line-height: 1.35; min-height: 18px; }
.dock-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.dock-actions .btn { flex: 1 1 auto; min-height: 44px; }
.dock-actions .btn-ghost { color: #f3ead6; border-color: rgba(255, 255, 255, .25); }
.dock-actions:empty { display: none; }

.g-log-panel { display: none; }
.g-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.g-log li { padding: 4px 8px; border-radius: 8px; background: rgba(255, 255, 255, .05); }
.g-log li.log-success { background: rgba(224, 169, 46, .16); }
.g-log li.log-warning { background: rgba(184, 67, 44, .2); }

/* Phone held sideways: map on one side, players and dock on the other */
body.lay-phone.landscape .view-game {
  grid-template-columns: minmax(0, 1fr) 250px;
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "board top" "board players" "board dock";
}
body.lay-phone.landscape .g-top { padding-top: 4px; min-height: 42px; }
body.lay-phone.landscape .g-players { flex-direction: column; overflow-y: auto; overflow-x: hidden; border: 0; }
body.lay-phone.landscape .pl { flex: none; }
body.lay-phone.landscape .g-dock { flex-direction: column; align-items: stretch; border: 0; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
body.lay-phone.landscape .dock-tile { align-self: center; width: 66px; height: 66px; }
body.lay-phone.landscape .board-tools { inset-inline-end: auto; inset-inline-start: 8px; }

/* ---------------- desktop ---------------- */
body.lay-desktop .view-game {
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas: "top top" "board players" "board dock" "board log";
}
body.lay-desktop .g-top { padding-inline: 12px; }
body.lay-desktop .g-players { flex-direction: column; overflow: visible; padding: 10px; gap: 8px; border-bottom: 0; background: #18221b; }
body.lay-desktop .pl { flex: none; padding: 8px 10px; }
body.lay-desktop .pl-meeple { width: 28px; height: 28px; }
body.lay-desktop .pl-name { font-size: 14px; }
body.lay-desktop .pl-score { font-size: 24px; }
body.lay-desktop .pl-left { font-size: 13px; }
body.lay-desktop .pl-pts { display: flex; }
body.lay-desktop .g-dock { flex-direction: column; align-items: stretch; padding: 12px; background: #18221b; border-top: 1px solid rgba(255, 255, 255, .06); border-bottom: 1px solid rgba(255, 255, 255, .06); }
body.lay-desktop .dock-tile { width: 120px; height: 120px; align-self: center; }
body.lay-desktop .dock-text { text-align: center; font-size: 14px; }
body.lay-desktop .g-log-panel { grid-area: log; display: flex; flex-direction: column; min-height: 0; padding: 10px 12px; background: #141d17; }
body.lay-desktop .g-log-panel h3 { margin: 0 0 8px; font-size: 13px; color: #c9bfa8; font-weight: 700; }
body.lay-desktop .g-log { overflow-y: auto; min-height: 0; flex: 1; }
.pl-pts { display: none; flex-basis: 100%; gap: 10px; font-size: 11.5px; color: #c9bfa8; margin-top: 2px; flex-wrap: wrap; }

/* ---------------- sheets ---------------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(8, 12, 9, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); color: var(--ink); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
  animation: up .22s ease-out;
}
.sheet.wide { max-width: 760px; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
body.lay-desktop .sheet-backdrop { align-items: center; }
body.lay-desktop .sheet { border-radius: 18px; }
.sheet h2 { margin: 0 0 10px; font-size: 19px; }
.sheet h3 { margin: 14px 0 6px; font-size: 14px; color: var(--ink-2); }
.sheet-close { position: absolute; top: 8px; inset-inline-end: 8px; width: 38px; height: 38px; border: 0; background: transparent; font-size: 26px; color: var(--ink-2); }
.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.menu-list .btn { justify-content: flex-start; }
.seg { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 10px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 6px 8px; font-size: 13.5px; font-weight: 700; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.rules p { margin: 0 0 10px; font-size: 14px; text-align: justify; }
.sheet .g-log li { background: var(--panel-2); }
.sheet .g-log li.log-success { background: #f6e3b0; }
.sheet .g-log li.log-warning { background: #f2d6cf; }
.tiles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.tiles-grid figure { margin: 0; text-align: center; position: relative; }
.tiles-grid img { width: 100%; aspect-ratio: 1; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); display: block; }
.tiles-grid figure.none img { opacity: .3; filter: grayscale(1); }
.tiles-grid figcaption { font-weight: 800; font-size: 14px; }

.results-head { text-align: center; }
.results-head h2 { font-size: 24px; color: var(--blue); }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.score-table th, .score-table td { padding: 7px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.score-table th { font-size: 12px; color: var(--ink-2); font-weight: 700; }
.score-table td:first-child, .score-table th:first-child { text-align: start; }
.score-table .who { display: flex; align-items: center; gap: 6px; font-weight: 700; max-width: 140px; }
.score-table .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-table .who img { width: 22px; height: 22px; object-fit: contain; flex: none; }
.score-table .total { font-weight: 900; font-size: 16px; }
.score-table tr.win { background: rgba(224, 169, 46, .2); }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }

.confirm-backdrop { align-items: center; z-index: 60; padding: 16px; }
.confirm-sheet { border-radius: 16px; max-width: 380px; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions .btn { flex: 1; }

.toast {
  position: fixed; z-index: 70; inset-inline: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 420px;
  background: #2a1d10; color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
body.in-game .toast { bottom: calc(110px + env(safe-area-inset-bottom)); }
