/* Fonts are self-hosted, cut down to the characters MahJok shows (tools/make-fonts.py): about 120 KB in all.
   Noto Serif TC and Oswald, SIL Open Font License. Characters outside the set use the device's own fonts. */
@font-face { font-family: "Noto Serif TC"; src: url("../fonts/noto-serif-tc-400.woff2") format("woff2"); font-weight: 100 600; font-display: swap; }
@font-face { font-family: "Noto Serif TC"; src: url("../fonts/noto-serif-tc-900.woff2") format("woff2"); font-weight: 700 900; font-display: swap; }
@font-face { font-family: Oswald; src: url("../fonts/oswald-500.woff2") format("woff2"); font-weight: 100 600; font-display: swap; }
@font-face { font-family: Oswald; src: url("../fonts/oswald-700.woff2") format("woff2"); font-weight: 700 900; font-display: swap; }

:root {
  /* 茶餐廳: cream walls, mint formica, a red sign, enamel-yellow for winning */
  --paper: #f6eedb;
  --paper-2: #fffaf0;
  --ink: #2a2118;
  --muted: #6d5a43;
  --panel: #ebe1c7;
  --red: #c0302b;
  --red-dark: #8f201c;
  --mint: #2f8f6c;
  --mint-deep: #1f6b53;   /* behind white text: 6.4:1, and 5:1 for the yellow highlights */
  --mint-light: #9fd0bb;
  --mint-edge: #6aa08a;
  --gold: #e8b730;
  --plus: #1f7a4c;
  --minus: #b0322e;
  --mosaic: conic-gradient(#2f8f6c 25%, #fff 0 50%, #2f8f6c 0 75%, #fff 0);
  --ui-font: Oswald, "Noto Serif TC", "PingFang TC", sans-serif;
  --text-font: "Noto Serif TC", Georgia, "Songti TC", "PMingLiU", serif;
  /* tile theme: 舊雀新枱, aged cream faces on jade-green backs */
  --t-face: linear-gradient(#fbf1d9, #ecdcb6);
  --t-edge: #d6c08d;
  --t-back: linear-gradient(#2e9a68, #17633f);
  --t-back-edge: #17633f;
  --t-ink: #2b2a40;
  --t-red: #b0322e;
  --t-green: #2f6f4a;
  --t-blue: #2f4f86;
  --t-white: #fff;
  --tile-font: "Noto Serif TC", "Songti TC", "STSong", "PMingLiU", "Noto Serif CJK TC", serif;
  --hand: min(calc((100vw - 42px) / 14.3), 54px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  /* a strip of mosaic tiles and a red rule across the top, then cream wall */
  background: linear-gradient(var(--red), var(--red)) 0 12px / 100% 3px no-repeat, var(--mosaic) 0 0 / 12px 12px repeat-x, var(--paper);
  color: var(--ink);
  font-family: var(--text-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
button, input, select { font: inherit; }
/* Player names and short game messages use the café signage lettering, like the buttons and top bar
   (Oswald for Latin, Noto Serif TC for Chinese). Longer reading text stays in the serif. */
.status, .callout, .hint, .tag, label, .lobby .label, .seat .nm, .who, .plaque, .sheet .sub, .err, .or, .scores td:first-child,
.field, .setting, .seat .wind, .tablecard b, details summary, .clip-head, .compass span, .peek span {
  font-family: var(--ui-font); letter-spacing: .3px; }
.status b, .callout b, .seat .nm, .plaque b { font-weight: 700; }
input, select { -webkit-user-select: text; user-select: text; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 2px solid var(--ink); border-radius: 6px; padding: 11px 18px;
  background: var(--paper-2); color: var(--ink); font-family: var(--ui-font); font-weight: 700; letter-spacing: .4px; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--red); color: #fff; }
.btn.danger { background: var(--red-dark); color: #fff; }
.btn.win { background: var(--gold); color: var(--ink); }
.btn.small { padding: 5px 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.link { background: none; border: 0; box-shadow: none; color: var(--muted); text-decoration: underline; padding: 8px; font-family: var(--ui-font); font-weight: 500; letter-spacing: .3px; }

/* ---------- tiles ---------- */
.tile {
  --w: 30px;
  /* soft shadow under the tile only: the negative spread keeps it from showing at the sides */
  --t-drop: 0 calc(var(--w) * .17) calc(var(--w) * .1) calc(var(--w) * -.1) rgba(0,0,0,.35);
  position: relative;
  display: inline-block;
  width: var(--w); height: calc(var(--w) * 1.36); flex: none;
  background: var(--t-face);
  border-radius: calc(var(--w) * .15);
  box-shadow: 0 calc(var(--w) * .05) 0 var(--t-edge), 0 calc(var(--w) * .12) 0 var(--t-back-edge), var(--t-drop);
  color: var(--ink); line-height: 1; vertical-align: top;
  transition: transform .12s;
}
.tile svg { position: absolute; left: 6%; top: 6%; width: 88%; height: 88%; overflow: visible; pointer-events: none; }
.tile text { font-family: var(--tile-font); font-weight: 900; text-anchor: middle; dominant-baseline: central; }
.tile .r { fill: var(--t-red); } .tile .g { fill: var(--t-green); } .tile .b { fill: var(--t-blue); } .tile .k { fill: var(--t-ink); }
.tile .w { fill: var(--t-white); } .tile text.num { fill: #fff; font-family: inherit; font-weight: 800; }
.tile .rs, .tile .gs, .tile .bs, .tile .ws { fill: none; }
.tile .rs { stroke: var(--t-red); } .tile .gs { stroke: var(--t-green); } .tile .bs { stroke: var(--t-blue); } .tile .ws { stroke: var(--t-white); }
.tile.back { background: var(--t-back); box-shadow: 0 calc(var(--w) * .07) 0 var(--t-edge), var(--t-drop); }
.tile.xs { --w: 19px; }
.tile.sm { --w: 25px; }
.tile.md { --w: 34px; }
.tile.lg { --w: var(--hand); cursor: pointer; }
.tile.xl { --w: 64px; }
.tile.sel { transform: translateY(calc(var(--w) * -.32)); box-shadow: 0 0 0 3px var(--red), 0 calc(var(--w) * .12) 0 3px var(--t-back-edge), var(--t-drop); }
.tile.hot { box-shadow: 0 0 0 2px var(--gold), 0 calc(var(--w) * .12) 0 2px var(--t-back-edge), var(--t-drop); }
.tile.dim { filter: brightness(.82); }
.tile[tabindex]:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; z-index: 3; }

.tiles { display: flex; flex-wrap: wrap; gap: 2px; align-items: flex-end; }
.meld { display: inline-flex; gap: 1px; padding: 2px; border-radius: 4px; background: rgba(42,33,24,.12); }
.melds { display: flex; flex-wrap: wrap; gap: 5px; align-items: flex-end; }

/* ---------- home ---------- */
.home { max-width: 420px; margin: 0 auto; padding: 36px 22px 40px; display: flex; flex-direction: column; gap: 14px; }
.logo { display: flex; gap: 6px; justify-content: center; margin-bottom: 4px; }
.logo .tile:nth-child(odd) { transform: rotate(-6deg); }
.logo .tile:nth-child(even) { transform: rotate(5deg) translateY(4px); }
/* the sign over the café door */
h1 { text-align: center; margin: 6px 0 0; padding: 4px 10px; font-size: 32px; font-weight: 900; letter-spacing: 1px;
  color: #fff; background: var(--red); border: 3px double var(--paper); outline: 3px solid var(--red); }
.tag { text-align: center; color: var(--muted); margin: 0 0 10px; }
label { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.field {
  width: 100%; padding: 13px 14px; border-radius: 4px; border: 2px solid var(--ink);
  background: var(--paper-2); color: var(--ink); font-size: 18px; outline: none;
}
.field:focus { border-color: var(--red); box-shadow: 0 0 0 2px rgba(192,48,43,.2); }
.code-input { text-transform: uppercase; letter-spacing: 10px; text-align: center; font-weight: 800; font-size: 26px; }
.or { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 -2px; }
.err { color: var(--red); text-align: center; min-height: 1.2em; margin: 0; }
details { color: var(--muted); font-size: 14px; background: var(--panel); border-radius: 12px; padding: 10px 14px; }
details summary { cursor: pointer; color: var(--ink); font-weight: 700; }
details li { margin: 4px 0; }

/* ---------- lobby ---------- */
.lobby { max-width: 440px; margin: 0 auto; padding: 28px 20px 40px; display: flex; flex-direction: column; gap: 14px; }
.lobby .label { text-align: center; color: var(--muted); font-size: 14px; margin: 0; }
.bigcode { text-align: center; font-family: var(--ui-font); font-size: 64px; font-weight: 700; letter-spacing: 12px; color: var(--red); margin: -6px 0 0; }
.seats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seat { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 14px; padding: 12px 14px; min-height: 58px; }
.seat .wind { width: 34px; height: 34px; border-radius: 50%; background: var(--mint-deep); color: #fff; display: grid; place-items: center; font-weight: 800; }
.seat .nm { flex: 1; font-weight: 700; }
.seat .nm small { display: block; font-weight: 400; color: var(--muted); }
.seat.empty .nm { color: var(--muted); font-weight: 500; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border-radius: 14px; padding: 10px 14px; }
.setting select { padding: 8px 10px; border-radius: 4px; border: 2px solid var(--ink); background: var(--paper-2); color: var(--ink); }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0; }

/* ---------- game ---------- */
.game { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--mint-deep); color: #fff; font-size: 13px;
  font-family: var(--ui-font); letter-spacing: .6px; border-bottom: 3px solid var(--red);
}
.topbar b { color: #ffe08a; }
.topbar .wall { display: inline-flex; align-items: center; gap: 5px; }
.table { flex: 1; padding: 8px 8px 0; display: flex; flex-direction: column; gap: 6px; }
.opp { background: var(--panel); border-radius: 12px; padding: 7px 9px; border: 2px solid transparent; transition: border-color .2s; }
.opp.turn { border-color: var(--red); }
.who { display: flex; align-items: center; gap: 7px; font-size: 14px; margin-bottom: 4px; }
.who .w { min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px; background: var(--mint-deep); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.who .w.dealer { background: var(--red); color: #fff; }
.who .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.who .pos { color: var(--muted); font-size: 12px; }
.who .score { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.who .away { font-size: 11px; color: var(--red); }
.opp .row { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 4px; }
.count { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.discards { display: flex; flex-wrap: wrap; gap: 1px; min-height: 26px; }

.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 4px 10px; text-align: center; }
/* hints for new players: a note pinned above your rack */
.tip { max-width: 440px; text-align: left; background: #fbe9b0; border: 2px solid var(--gold); border-radius: 6px; padding: 8px 12px; font-size: 14px; line-height: 1.4; }
.tip p { margin: 0; } .tip p + p { margin-top: 4px; }
.tip small { color: var(--muted); }
.tip-tag { display: inline-block; font-family: var(--ui-font); font-size: 12px; font-weight: 700; letter-spacing: .5px; color: #fff; background: var(--red); border-radius: 3px; padding: 1px 6px; margin-bottom: 4px; }
.tile.hinted::after { content: ''; position: absolute; left: 50%; top: calc(var(--w) * -.32); width: calc(var(--w) * .22); height: calc(var(--w) * .22);
  margin-left: calc(var(--w) * -.11); border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--ink); }
.setting span small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.status { font-size: 16px; color: var(--muted); }
.status b { color: var(--ink); }
.callout { display: flex; align-items: center; gap: 12px; background: var(--paper-2); border: 2px solid var(--ink); padding: 8px 14px; border-radius: 6px; }

.me { background: var(--panel); padding: 8px 8px calc(env(safe-area-inset-bottom) + 10px); border-top: 3px solid var(--red); position: sticky; bottom: 0; }
.me .who { margin: 0 4px 6px; }
.me .mine { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-end; padding: 0 4px 6px; }
.hand { display: flex; justify-content: center; align-items: flex-end; gap: 1px; padding-top: 14px; }
.hand .gap { width: calc(var(--hand) * .3); flex: none; }
.hand .tile.suitgap { margin-left: 3px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding-top: 10px; min-height: 54px; }
.actions .btn { padding: 10px 16px; }
.actions .chowbtn { display: inline-flex; align-items: center; gap: 6px; }
.timer { height: 4px; border-radius: 2px; background: rgba(42,33,24,.15); overflow: hidden; margin: 8px 6px 0; }
.timer i { display: block; height: 100%; background: var(--red); width: 100%; }
.timer.turn i { background: var(--mint); transition: width .25s linear; }
.turnclock { color: var(--red); font-weight: 700; }
.callout.sitout { flex-direction: column; text-align: center; background: #fbe9b0; border-color: var(--gold); }

/* ---------- result overlay ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,60,44,.72); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: relative; background: #fffdf6; color: var(--ink); padding: 24px 18px 18px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto;
  box-shadow: 0 16px 40px rgba(0,0,0,.4);
  /* torn-off top edge, like a slip off the waiter's pad */
  -webkit-mask: radial-gradient(circle 6px at 50% 0, transparent 98%, #000) 0 0 / 16px 100%; mask: radial-gradient(circle 6px at 50% 0, transparent 98%, #000) 0 0 / 16px 100%; }
.sheet h2 { margin: 0 0 2px; text-align: center; font-size: 26px; font-weight: 900; color: var(--red); }
.sheet .stamp { position: absolute; right: 14px; top: 16px; transform: rotate(-12deg); border: 2px solid var(--red); color: var(--red); border-radius: 4px;
  padding: 2px 7px; font-size: 20px; font-weight: 900; opacity: .85; pointer-events: none; }
.sheet .sub { text-align: center; color: var(--muted); margin: 0 0 12px; }
.sheet .winhand { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 12px; }
.faan { list-style: none; padding: 0; margin: 0 0 12px; font-family: "Courier New", ui-monospace, monospace; }
.faan li { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px dashed #b8ab90; font-size: 15px; }
.faan li:last-child { border-bottom: 2px solid var(--ink); font-weight: 800; color: var(--ink); }
.scores { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 15px; font-family: "Courier New", ui-monospace, monospace; }
.scores td { padding: 6px 4px; border-bottom: 1px dashed #b8ab90; }
.scores td:last-child, .scores td:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; }
.plus { color: var(--plus); font-weight: 700; } .minus { color: var(--minus); }
.sheet .btns { display: flex; flex-direction: column; gap: 8px; }
/* scoring guide */
.guide-sheet h3 { margin: 16px 0 6px; font-family: var(--ui-font); font-size: 15px; letter-spacing: .5px; color: var(--red); }
.faan.guide li { align-items: flex-start; gap: 10px; font-family: var(--text-font); }
.faan.guide li:last-child { border-bottom: 1px dashed #b8ab90; font-weight: 400; }
.faan.guide li small { display: block; color: var(--muted); font-size: 13px; }
.faan.guide li > span:last-child { font-family: var(--ui-font); font-weight: 700; flex: none; }
.pts-wrap { overflow-x: auto; }
.pts { border-collapse: collapse; font-family: var(--ui-font); font-size: 13px; text-align: center; }
.pts td { border: 1px solid #b8ab90; padding: 4px 7px; }
/* game over: final standings on the order slip */
.standings { list-style: none; padding: 0; margin: 0 0 14px; font-family: var(--ui-font); }
.standings li { display: flex; align-items: center; gap: 12px; padding: 9px 6px; border-bottom: 1px dashed #b8ab90; font-size: 17px; }
.standings .rank { width: 2.6em; color: var(--muted); font-weight: 500; }
.standings .st-name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .st-pts { font-family: "Courier New", ui-monospace, monospace; font-weight: 700; }
.standings li.top { background: #fbe9b0; border: 2px solid var(--gold); border-radius: 4px; font-size: 20px; }
.standings li.top .rank { color: var(--ink); }
.standings li.me .st-name { color: var(--red); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%);
  background: var(--red); color: #fff; font-weight: 900; font-size: 24px; letter-spacing: 1px;
  padding: 8px 22px; border: 3px double var(--paper); outline: 3px solid var(--red); opacity: 0; pointer-events: none; z-index: 20;
  transition: opacity .2s; box-shadow: 0 10px 24px rgba(0,0,0,.3); white-space: nowrap;
}
.toast.show { opacity: 1; }

@media (min-width: 700px) {
  .table { max-width: 820px; width: 100%; margin: 0 auto; }
  .me { max-width: 820px; width: 100%; margin: 0 auto; }
  .tile.xs { --w: 24px; }
}

/* ---------- sounds step ---------- */
.sounds h1 { font-size: 30px; }
.note { background: #fbe9b0; border: 2px solid var(--gold); border-radius: 6px; padding: 10px 12px; font-size: 14px; margin: 0; }
.clips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.clip { background: var(--panel); border-radius: 6px; padding: 12px; display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent; }
.clip.done { border-color: var(--mint); }
.clip.rec { border-color: var(--red); animation: recpulse 1s infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 5px rgba(192,48,43,.2); } }
.clip-head { display: flex; justify-content: space-between; font-size: 20px; }
.clip-head span { color: var(--mint); }
.clip small { color: var(--muted); min-height: 2.4em; }
.clip-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.clip-btns .btn { padding: 7px 10px; }
.upload { display: inline-flex; align-items: center; }
.recbar { height: 4px; border-radius: 2px; background: rgba(42,33,24,.15); overflow: hidden; }
.recbar i { display: block; height: 100%; background: var(--red); animation: recfill 3s linear forwards; }
@keyframes recfill { from { width: 0; } to { width: 100%; } }

/* ---------- game extras ---------- */
.iconbtn { appearance: none; border: 0; background: rgba(255,255,255,.18); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 13px; cursor: pointer; }
.opp.mini { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 14px; }
.opp.mini .w { min-width: 22px; height: 22px; border-radius: 11px; background: var(--mint-deep); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.opp.mini .nm { font-weight: 700; max-width: 28vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp.mini .pos { color: var(--muted); font-size: 12px; }
.opp.mini .melds { flex: 1; justify-content: flex-end; }
.opp.mini .score { font-weight: 700; min-width: 32px; text-align: right; }
.clock { display: inline-block; margin-left: 4px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
.tile.fresh { box-shadow: 0 0 0 2px var(--red), 0 calc(var(--w) * .12) 0 2px var(--t-back-edge), var(--t-drop); }

/* ---------- drawing a tile: your side of the wall ---------- */
.pullzone { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wallrow { --sw: 30px; display: flex; gap: 1px; padding: 14px 14px 10px; border-radius: 8px;
  background: radial-gradient(circle at 50% 30%, #24835a, #145a3c); box-shadow: inset 0 0 0 3px var(--mint-light), 0 3px 0 var(--mint-edge); }
.wallrow .stack { position: relative; width: var(--sw); height: calc(var(--sw) * 1.36 + 5px); }
.wallrow .tile { position: absolute; left: 0; top: 5px; --w: var(--sw); }
.wallrow .tile + .tile { top: 0; }
/* the next tile is raised and ringed: yours to take */
.wallrow .tile.pull-next { top: -7px; cursor: grab; touch-action: none; animation: nudge 1.8s ease-in-out infinite;
  box-shadow: 0 0 0 2px var(--gold), 0 calc(var(--w) * .07) 0 var(--t-edge), var(--t-drop); }
.wallrow .tile.pull-next.gone { visibility: hidden; animation: none; }
@keyframes nudge { 50% { transform: translateY(-3px); } }
.tile.slot-draw { background: rgba(42,33,24,.06); box-shadow: none; outline: 2px dashed rgba(42,33,24,.35); outline-offset: -2px; cursor: default; }
.pullcard { position: fixed; z-index: 40; width: var(--cw); height: calc(var(--cw) * 1.36); transform-origin: 0 0; transform-style: preserve-3d; pointer-events: none; }
.pullcard.turning { transform-origin: 50% 50%; transition: transform .32s cubic-bezier(.3,.7,.4,1); }
.pullcard .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.pullcard .face .tile { --w: var(--cw); }
.pullcard .front { transform: rotateY(180deg); }
/* how good the draw is: grey (no glow) · green connects · blue makes a set · purple big · gold can win · pink flower */
.pullcard.glow .front .tile, .tile.fresh.glow { box-shadow: 0 0 0 3px var(--c), 0 0 16px 4px var(--c), 0 calc(var(--w) * .12) 0 var(--t-back-edge); }
.drawnote { font-family: var(--ui-font); font-weight: 700; letter-spacing: .5px; padding: 4px 12px; border-radius: 4px; border: 2px solid var(--c); background: var(--paper-2); color: var(--ink); animation: noteIn .2s ease-out; }
.drawnote.common { border-color: rgba(42,33,24,.25); color: var(--muted); }
.drawnote.legendary { background: var(--gold); border-color: var(--ink); }
@keyframes noteIn { from { opacity: 0; transform: translateY(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- privacy and terms pages ---------- */
.doc-page { max-width: 680px; margin: 0 auto; padding: 36px 20px 60px; line-height: 1.55; -webkit-user-select: text; user-select: text; }
.doc-page h1 { display: inline-block; }
.doc-page h2 { font-family: var(--ui-font); font-size: 20px; color: var(--red); margin: 28px 0 8px; letter-spacing: .3px; }
.doc-updated { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.doc-lead { font-size: 18px; }
.doc-page ul { padding-left: 20px; } .doc-page li { margin: 6px 0; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.doc-table th { font-family: var(--ui-font); text-align: left; border-bottom: 2px solid var(--ink); padding: 6px; }
.doc-table td { border-bottom: 1px dashed #b8ab90; padding: 8px 6px; vertical-align: top; }
.doc-page a { color: var(--red); }
.doc-page small { color: var(--muted); }
.doc-links, .legal { font-family: var(--ui-font); font-size: 14px; text-align: center; color: var(--muted); }
.doc-links a, .legal a { color: var(--muted); }

/* ---------- connection ---------- */
.spinner { width: 42px; height: 42px; margin: 10px auto; border-radius: 50%; border: 4px solid rgba(42,33,24,.15); border-top-color: var(--red); animation: spin .9s linear infinite; }
.netwarn { color: #ffe08a; font-size: 12px; font-weight: 700; }

/* home: Table screen option */
.tablecard { display: flex; gap: 12px; align-items: center; text-align: left; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 6px; border: 2px dashed rgba(42,33,24,.4); background: var(--paper-2); color: inherit; font: inherit; cursor: pointer; }
.tablecard .tc-icon { font-size: 28px; flex: none; }
.tablecard b { display: block; }
.tablecard small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.btn.link.inline { padding: 0; font-size: inherit; color: inherit; }

/* ---------- drag to discard / press to enlarge ---------- */
.tile { -webkit-touch-callout: none; }
.hand .tile[data-act="tile"] { touch-action: none; }
.tile.lifted { opacity: .25; transform: none; box-shadow: none; }
.tile.ghost { position: fixed; z-index: 60; margin: 0; pointer-events: none; transition: none;
  box-shadow: 0 calc(var(--w) * .07) 0 #c4b287, 0 14px 26px rgba(0,0,0,.5); }
.tile.ghost.flying { transition: transform .25s ease-in, opacity .25s; transform: translate(0, -60vh) scale(.6) !important; opacity: 0; }
body.dragging .felt::after { content: 'Drag up here to discard'; position: absolute; inset: 6px 8px 0; border: 2px dashed rgba(255,255,255,.3);
  border-radius: 14px; display: grid; place-items: end center; padding-bottom: 14px; font-weight: 800; color: rgba(255,255,255,.55); background: rgba(0,0,0,.15);
  pointer-events: none; transition: background .15s, border-color .15s, color .15s; }
body.drop-over .felt::after { content: 'Release to discard'; border-color: var(--gold); color: var(--gold); background: rgba(242,193,78,.12); }

.peek { position: fixed; left: 0; top: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: rgba(0,0,0,.72); backdrop-filter: blur(6px); border-radius: 18px; padding: 12px 14px 10px; pointer-events: none;
  opacity: 0; transition: opacity .05s; font-size: 13px; font-weight: 700; color: #fff; }
.peek.show { opacity: 1; }
.peek .tile.xl { --w: 76px; }

@media (hover: hover) and (pointer: fine) {
  .hand .tile[data-act="tile"]:not(.sel):not(.lifted):hover { transform: translateY(-10%) scale(1.12); z-index: 2; }
  .callout .tile:hover { transform: scale(1.6); z-index: 5; }
  .board .tile:hover { outline: 2px solid #fff; outline-offset: 1px; }
}

/* ---------- the board: a square table seen from above (sizes in --u, about one tile width) ----------
   Layout from the centre outwards: compass hole (2.8u), ponds 4 rows deep in a pinwheel (6 x 1.04u wide),
   then a 1.35u band along each edge with that player's nameplate, flowers and melds.
   Discards are always upright for you (whoever threw them). Total 16.6u + 0.8u rim = 17.4u. */
.board { --S: min(calc(100vw - 12px), calc(100vh - 300px), 580px); --u: calc(var(--S) / 17.4);
  width: var(--S); height: var(--S); margin: 6px auto 0; flex: none; padding: calc(var(--u) * .4); border-radius: calc(var(--u) * .8);
  background: var(--mint-light); touch-action: none;
  box-shadow: inset 0 0 0 3px #7fb9a2, 0 4px 0 var(--mint-edge), 0 10px 20px rgba(0,0,0,.18); }
@supports (height: 100dvh) { .board { --S: min(calc(100vw - 12px), calc(100dvh - 300px), 580px); } }
.felt { position: relative; width: 100%; height: 100%; border-radius: calc(var(--u) * .5); overflow: hidden; color: #fff; --muted: rgba(255,255,255,.65);
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    radial-gradient(circle at 50% 45%, #1f8755, #13643e 55%, #0c4a2d);
  box-shadow: inset 0 0 calc(var(--u) * 1.2) rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.4); }

/* one full-size layer per seat, rotated so its edge band faces that player */
.side { position: absolute; inset: 0; transform: rotate(var(--rot)); pointer-events: none; }
.side .tile { pointer-events: auto; }
/* discards: each player's corner of the pinwheel, filled outward from the middle, tiles upright for you.
   You: below-left · across: above-right · left player: above-left · right player: below-right */
.upond { position: absolute; display: flex; flex-wrap: wrap; align-content: flex-start; gap: calc(var(--u) * .02) calc(var(--u) * .04); }
.up-b { left: calc(50% - var(--u) * 6.92); top: calc(50% + var(--u) * 1.4); width: calc(var(--u) * 6.24); }
.up-t { left: calc(50% + var(--u) * .68); bottom: calc(50% + var(--u) * 1.4); width: calc(var(--u) * 6.24); flex-direction: row-reverse; flex-wrap: wrap-reverse; }
.up-l { right: calc(50% + var(--u) * 1.4); top: calc(50% - var(--u) * 6.92); width: calc(var(--u) * 5.2); flex-direction: row-reverse; }
.up-r { left: calc(50% + var(--u) * 1.4); bottom: calc(50% - var(--u) * 6.92); width: calc(var(--u) * 5.2); flex-wrap: wrap-reverse; }
.upond.dense { row-gap: calc(var(--u) * -.32); }
.upond.denser { row-gap: calc(var(--u) * -.5); }
.tile.bd { --w: var(--u); transition: transform .2s;
  box-shadow: 0 calc(var(--w) * .07) 0 var(--t-back-edge), var(--t-drop); }
.tile.bd.last { filter: none; transform: scale(1.18); z-index: 1; }
.tile.bd.hot { filter: none; transform: scale(1.38); z-index: 2;
  box-shadow: 0 0 0 2px var(--gold), 0 0 calc(var(--u) * .6) calc(var(--u) * .15) rgba(242,193,78,.75); }
.band { position: absolute; left: calc(50% - var(--u) * 6.92); width: calc(var(--u) * 13.84); top: calc(50% + var(--u) * 7.02);
  height: calc(var(--u) * 1.24); display: flex; align-items: center; gap: calc(var(--u) * .3); }
/* when melds overflow they spill away from the nameplate, never over it */
.b-melds { flex: 1; min-width: 0; display: flex; justify-content: safe center; align-items: center; gap: calc(var(--u) * .22); }
/* nameplate on the table edge in front of each player: room for a 12-letter name and the score */
.plaque { flex: 0 1 auto; max-width: calc(var(--u) * 5.6); min-width: 0; height: calc(var(--u) * .95); display: flex; align-items: center; gap: calc(var(--u) * .3);
  padding: 0 calc(var(--u) * .3); border-radius: calc(var(--u) * .18); background: var(--paper); color: var(--ink);
  font-size: max(9px, calc(var(--u) * .48)); line-height: 1; white-space: nowrap; box-shadow: 0 2px 0 rgba(0,0,0,.25); position: relative; z-index: 1; }
.plaque b { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.plaque span { color: var(--red); font-weight: 800; font-variant-numeric: tabular-nums; }
.plaque i { font-style: normal; font-weight: 600; margin-right: .3em; }
.plaque.on { background: var(--red); color: #fff; }
.plaque.on span { color: #ffe08a; }
.side-t .plaque { transform: rotate(180deg); } /* across the table: keep it the right way up for you */
.band.reveal-hand .plaque { max-width: calc(var(--u) * 3.4); }
.band .meld { gap: 0; padding: 0; background: none; border-radius: 0; }
.tile.bm { --w: calc(var(--u) * .74); box-shadow: 0 calc(var(--w) * .08) 0 var(--t-back-edge), var(--t-drop); }
.b-melds.tight .tile.bm { --w: calc(var(--u) * .58); }
.b-melds.tighter .tile.bm { --w: calc(var(--u) * .46); }
.band.reveal-hand .tile.bm { --w: calc(var(--u) * .5); }
.b-shown { display: inline-flex; gap: 1px; padding-left: calc(var(--u) * .15); }
.cw { position: absolute; left: 50%; top: calc(50% + var(--u) * .46); transform: translateX(-50%); font-size: calc(var(--u) * .62);
  font-weight: 900; line-height: 1; color: rgba(255,255,255,.7); }
.cw.dealer { color: var(--gold); text-shadow: 0 0 calc(var(--u) * .3) rgba(242,193,78,.6); }
.side.turn::after { content: ''; position: absolute; left: calc(50% - var(--u) * 6.92); width: calc(var(--u) * 13.84); bottom: calc(var(--u) * .06);
  height: calc(var(--u) * .14); border-radius: 99px; background: var(--gold); }

/* centre compass: wall count; during claims a gold ring counts down */
.compass { --left: 360deg; position: absolute; left: 50%; top: 50%; width: calc(var(--u) * 2.7); height: calc(var(--u) * 2.7);
  margin: calc(var(--u) * -1.35) 0 0 calc(var(--u) * -1.35); border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.14); }
.compass.claiming { background: conic-gradient(var(--gold) var(--left), rgba(255,255,255,.12) 0); }
.compass::before { content: ''; position: absolute; inset: calc(var(--u) * .12); border-radius: 50%; background: radial-gradient(#126039, #0a3f26); box-shadow: inset 0 2px 6px rgba(0,0,0,.55); }
.compass span { position: relative; font-size: calc(var(--u) * .46); font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }

/* your tiles stand in a wooden rack */
.hand.rack { margin: 0; padding: 12px 3px 9px; border-radius: 6px; background: var(--mint-light);
  box-shadow: inset 0 0 0 3px #7fb9a2, inset 0 -5px 0 var(--mint-edge); }
.me { padding: 10px 4px calc(env(safe-area-inset-bottom) + 10px); }

/* game menu */
.sheet.menu { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.sheet.menu h2 { margin-bottom: 6px; font-size: 22px; color: var(--ink); }
.sheet.menu .btn.block { text-align: left; padding: 10px 16px; }
.sheet.menu .btn small { display: block; font-family: var(--text-font); font-weight: 400; letter-spacing: 0; font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- phone held sideways: table on the left, status and your rack on the right ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  .game { --boardS: min(calc(100vh - 54px), 58vw); display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top top" "board center" "board me"; min-height: 100vh; }
  @supports (height: 100dvh) { .game { --boardS: min(calc(100dvh - 54px), 58vw); min-height: 100dvh; } }
  .game > .topbar { grid-area: top; padding-top: 6px; padding-bottom: 6px; }
  .game > .board { grid-area: board; --S: var(--boardS); margin: 4px 6px 4px max(6px, env(safe-area-inset-left)); align-self: start; }
  .game > .center { grid-area: center; min-height: 0; overflow: auto; padding: 4px 8px; }
  .game > .me { grid-area: me; position: static; padding: 6px 6px max(8px, env(safe-area-inset-bottom)); max-width: none; margin: 0;
    --hand: min(calc((100vw - var(--boardS) - 64px) / 14.6), 46px); }
  .game > .me .hand.rack { padding-top: 10px; }
  .game > .me .actions { min-height: 0; padding-top: 6px; }
  .tip { font-size: 13px; padding: 6px 10px; }
  .wallrow { --sw: 24px; padding: 10px 10px 8px; }
}
