:root {
  --bg: #12100e;
  --card: #1e1a15;
  --line: #3a3229;
  --field: #17130f;
  --text: #f2e9db;
  --muted: #a8998485;
  --muted2: #a89984;
  --accent: #f4a261;
  --accent2: #2a2219;
  --good: #6bbf59;
  --bad: #e76f51;
  --gold: #e9c46a;
  --tile: #ecdcc0;
  --tile-ink: #2a2118;
  --tile-edge: #b89b6e;
  --w3: #b5482f;
  --w2: #c77d3e;
  --a5: #4a7a9b;
  --a3: #5a8f6b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
#app { max-width: 460px; margin: 0 auto; min-height: 100vh; padding: 10px 12px 16px; display: flex; flex-direction: column; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.muted { color: var(--muted2); font-size: 14px; }
.h { font-size: 12px; color: var(--muted2); text-transform: uppercase; letter-spacing: .06em; }
input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--field); color: var(--text); font-size: 16px; margin: 6px 0; }
button { width: 100%; padding: 13px; border-radius: 10px; border: 0; background: var(--accent); color: #241606; font-size: 15px; font-weight: 800; margin-top: 10px; cursor: pointer; }
button.sec { background: var(--accent2); color: var(--text); font-weight: 600; border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--muted2); border: 1px solid var(--line); font-weight: 600; }
button:disabled { opacity: .4; cursor: not-allowed; }
.err { color: var(--bad); font-size: 14px; min-height: 18px; margin-top: 8px; }
.right { margin-left: auto; }
.good { color: var(--good); } .bad { color: var(--bad); } .gold { color: var(--gold); }

/* Home / hero */
.hero { text-align: center; padding: 20px 0 6px; }
.logo { display: inline-flex; gap: 5px; }
.logo .lt { width: 40px; height: 46px; border-radius: 8px; background: var(--tile); color: var(--tile-ink); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800; box-shadow: 0 3px 0 var(--tile-edge); transform: rotate(-3deg); }
.logo .lt:nth-child(even) { transform: rotate(3deg); }
.tag { color: var(--muted2); margin-top: 12px; font-size: 15px; }

/* Lobby */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.brand { font-weight: 800; letter-spacing: .02em; }
.code { font-size: 30px; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 4px 0; color: var(--accent); }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.av { width: 30px; height: 30px; border-radius: 8px; background: var(--tile); color: var(--tile-ink); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; flex: none; }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted2); }
.tiers { display: flex; gap: 6px; margin-top: 6px; }
.tier { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--field); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.tier.sel { border-color: var(--accent); background: rgba(244,162,97,.16); color: var(--accent); }
.iconbtn { width: auto; margin: 0; padding: 5px 9px; font-size: 13px; background: transparent; border: 1px solid var(--line); color: var(--muted2); }

/* Play screen */
.playbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.turnchip { font-weight: 800; font-size: 15px; }
.turnchip.you { color: var(--accent); }
.bagchip { font-size: 12px; color: var(--muted2); }
.scores { display: flex; gap: 6px; margin-bottom: 6px; overflow-x: auto; }
.pscore { flex: 1 0 auto; min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; background: var(--field); font-size: 12px; }
.pscore.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pscore .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 78px; }
.pscore .sc { font-size: 16px; font-weight: 800; }

.board { display: grid; gap: 2px; background: var(--line); border: 2px solid var(--line); border-radius: 8px; padding: 2px; touch-action: manipulation; }
.cell { position: relative; aspect-ratio: 1; border-radius: 3px; background: var(--field); display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: #ffffff9c; user-select: none; overflow: hidden; }
.cell.bW3 { background: var(--w3); color: #fff; }
.cell.bW2 { background: var(--w2); color: #fff; }
.cell.bA5 { background: var(--a5); color: #fff; }
.cell.bA3 { background: var(--a3); color: #fff; }
.cell.star { background: #2a2219; color: var(--accent); font-size: 15px; }
.tile { position: absolute; inset: 1px; border-radius: 3px; background: var(--tile); color: var(--tile-ink); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; line-height: 1; box-shadow: 0 1px 0 var(--tile-edge); }
.tile .v { position: absolute; right: 1px; bottom: 0px; font-size: 8px; font-weight: 700; opacity: .7; }
.tile.pending { background: #ffe9c7; box-shadow: 0 0 0 2px var(--accent), 0 1px 0 var(--tile-edge); }
.tile.last { box-shadow: 0 0 0 2px var(--gold); }

/* Rack + controls */
.rack { display: flex; gap: 5px; justify-content: center; margin: 10px 0 6px; min-height: 52px; }
.rtile { width: 44px; height: 50px; border-radius: 7px; background: var(--tile); color: var(--tile-ink); display: flex; align-items: center; justify-content: center; position: relative; font-size: 24px; font-weight: 800; box-shadow: 0 3px 0 var(--tile-edge); cursor: pointer; flex: none; }
.rtile .v { position: absolute; right: 3px; bottom: 1px; font-size: 10px; font-weight: 700; opacity: .7; }
.rtile.sel { transform: translateY(-6px); box-shadow: 0 6px 0 var(--tile-edge), 0 0 0 2px var(--accent); }
.rtile.swap { box-shadow: 0 3px 0 var(--tile-edge), 0 0 0 2px var(--bad); }
.rtile.empty { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.acts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 4px; }
.acts button { margin-top: 0; padding: 11px 6px; font-size: 14px; }
.flash { text-align: center; min-height: 20px; font-size: 14px; font-weight: 700; margin: 2px 0; }
.hint { text-align: center; font-size: 12px; color: var(--muted2); min-height: 16px; }

/* Results */
.res-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); margin-bottom: 6px; }
.res-row.win { border-color: var(--gold); background: rgba(233,196,106,.12); }
.res-row .rk { width: 24px; font-weight: 800; color: var(--muted2); }
.res-row .sc { margin-left: auto; font-size: 20px; font-weight: 800; }

/* Overlay (QR + About) */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px; text-align: center; max-width: 340px; width: 100%; }
.box img { display: block; margin: 12px auto; border-radius: 10px; background: #fff; padding: 8px; width: 200px; }
.box p { color: var(--muted2); font-size: 14px; line-height: 1.5; }
.bmc { background: var(--gold); color: #241606; }
.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: rgba(40,34,25,.97); border: 1px solid var(--accent); color: var(--text); padding: 9px 18px; border-radius: 20px; font-size: 13px; font-weight: 600; z-index: 200; max-width: 92%; text-align: center; transition: opacity .5s; }
.linkrow { text-align: center; margin-top: 14px; }
.linkrow a { color: var(--muted2); font-size: 12px; text-decoration: underline; }
.linkbtn { background: none; border: 0; color: var(--muted2); font-size: 12px; text-decoration: underline; cursor: pointer; width: auto; margin: 0; padding: 0; }
