/* King's Keep: a cardboard board and paper cards on a walnut table.
   Layout: table top (opponents, board + mercenary group, your hand) on one screen
   on desktops; stacked in play order on phones. */
:root {
  --table: #2a1c13;
  --table-2: #352418;
  --ink: #1b130b;
  --board: #c79e6e;
  --board-edge: #a87d4f;
  --paper: #f5efe1;
  --paper-blue: #e2eaf0;
  --paper-gold: #f6e6a8;
  --paper-king: #f2c891;
  --text: #f1e6d0;
  --muted: #bfae92;
  --gold: #e2b33c;
  --royal: #9b2b25;
  --line: #4a3626;
  --focus: #ffd65a;
  --font-display: "IM Fell English SC", "Iowan Old Style", Georgia, serif;
  --font-body: "Alegreya Sans", "Gill Sans", "Segoe UI", system-ui, sans-serif;
  --cw: 116px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; min-height: 100%; display: flex; flex-direction: column;
  color: var(--text); font-family: var(--font-body); font-size: 16px; line-height: 1.4;
  background-color: var(--table);
  background-image:
    repeating-linear-gradient(92deg, rgba(255,255,255,0.018) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(88deg, rgba(0,0,0,0.12) 0 1px, transparent 1px 23px),
    radial-gradient(ellipse at 30% 20%, var(--table-2), var(--table) 70%);
  font-variant-numeric: tabular-nums;
}
a { color: var(--gold); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { font: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; text-wrap: balance; margin: 0; }

/* --- Top bar (every Cheetah Moon game) --- */
.bar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); font-size: 15px; background: rgba(0,0,0,0.25);
}
.bar .home { color: var(--muted); text-decoration: none; }
.bar .home:hover { color: var(--text); }
.bar .right { display: flex; gap: 14px; align-items: center; color: var(--muted); }
.bar .account strong { color: var(--text); }
.linkish { background: none; border: 0; color: var(--gold); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--ink); background: var(--paper); color: var(--ink);
  font-weight: 700; box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--royal); color: #fff6e4; }
.btn.gold { background: var(--gold); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 3px 0 var(--ink); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }

/* --- Home and lobby --- */
.home-page { flex: 1; display: grid; place-items: start center; padding: 32px 16px 48px; }
.hero { text-align: center; max-width: 640px; display: grid; gap: 14px; justify-items: center; }
.hero svg.crest { width: 112px; height: 112px; }
.hero h1 { font-size: clamp(44px, 9vw, 76px); line-height: 1; color: var(--paper); letter-spacing: .02em; }
.hero p.tag { color: var(--muted); font-size: 18px; max-width: 46ch; margin: 0; }
.panel {
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); width: min(560px, 100%); text-align: left;
}
.panel h2 { font-size: 26px; margin-bottom: 10px; }
.panel .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.panel input {
  font: inherit; font-size: 20px; letter-spacing: .2em; text-transform: uppercase; width: 9ch;
  padding: 6px 10px; border: 2px solid var(--ink); border-radius: 6px; background: #fffaf0; color: var(--ink);
}
.panel .muted { color: #6b5a44; }
.tables { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.tables a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid #cdbf9f; border-radius: 6px; color: var(--ink); text-decoration: none; }
.tables a:hover { background: #efe5cd; }
.tables .turn { color: var(--royal); font-weight: 700; }
.seats { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.seats li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid #cdbf9f; border-radius: 6px; }
.seats .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.seats .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.invite { font-family: var(--font-display); font-size: 30px; letter-spacing: .15em; }

/* --- The table --- */
.table {
  flex: 1; display: grid; gap: 14px; padding: 12px 16px 20px;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 560px);
  grid-template-areas: "opps opps" "board prompt" "board side" "you side";
  grid-template-rows: auto auto 1fr auto;
  align-items: start; max-width: 1500px; width: 100%; margin: 0 auto;
}
.opps { grid-area: opps; display: flex; gap: 10px; flex-wrap: wrap; }
.board-wrap { grid-area: board; align-self: start; display: grid; gap: 10px; justify-items: center; min-width: 0; }
.prompt-wrap { grid-area: prompt; min-width: 0; }
.side { grid-area: side; display: grid; gap: 14px; min-width: 0; align-self: start; }
.side .cards { --cw: 96px; gap: 8px; }
.side .piles { --cw: 72px; gap: 10px; }
.side .piles .card .c-text, .side .piles .card .c-top .c-badge { display: none; }
.you { grid-area: you; min-width: 0; }

.opp {
  display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 8px;
  background: rgba(0,0,0,.28); border: 2px solid transparent; min-width: 0; flex: 1 1 220px;
}
.opp.active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(226,179,60,.2); }
.opp.out { opacity: .5; }
.opp .who { min-width: 0; flex: 1; }
.opp .who b { display: block; overflow-wrap: anywhere; }
.opp .stats { color: var(--muted); font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.opp .mini-hand { display: flex; }
.marker { width: 26px; height: 32px; flex: none; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--gold); color: var(--ink); white-space: nowrap; }
.chip.ruler { background: var(--royal); color: #fff6e4; }
.chip.bot { background: #5c4a39; color: var(--text); }

/* The board itself: cardboard with ink lines. */
.board {
  width: min(100%, 700px, calc(100vh - 360px)); min-width: 420px; aspect-ratio: 1; max-width: 100%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.1), transparent 55%),
    repeating-linear-gradient(0deg, rgba(0,0,0,.035) 0 2px, transparent 2px 6px),
    var(--board);
  border-radius: 6px; border: 3px solid var(--board-edge);
  box-shadow: 0 16px 40px rgba(0,0,0,.55), inset 0 0 40px rgba(90,60,30,.35);
}
.board svg { width: 100%; height: 100%; display: block; }
.board .space { cursor: default; }
.board .hit { fill: transparent; }
.board .hit.can { cursor: pointer; }
.board .glow { fill: none; stroke: var(--gold); stroke-width: 6; animation: pulse 1.2s ease-in-out infinite; pointer-events: none; }
.board .glow.from { stroke: #7fd0ff; }
@keyframes pulse { 50% { stroke-opacity: .35; } }
.board .hit.can:hover + .glow, .board .hit.can:focus-visible + .glow { stroke-width: 9; stroke-opacity: 1; }

.bank { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 14px; flex-wrap: wrap; justify-content: center; }
.bank svg { width: 16px; height: 22px; vertical-align: middle; }

/* --- The prompt: what's happening, what you can do --- */
.prompt {
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 14px 16px;
  box-shadow: 0 8px 22px rgba(0,0,0,.4); display: grid; gap: 10px; position: relative;
}
.prompt.mine { box-shadow: 0 0 0 3px var(--gold), 0 8px 22px rgba(0,0,0,.4); }
.prompt h2 { font-size: 22px; line-height: 1.15; }
.prompt p { margin: 0; color: #4d3f2e; }
.prompt .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.prompt .battle { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 15px; padding: 8px 10px; border-radius: 6px; background: #ece2c9; }
.prompt .battle .vs { font-family: var(--font-display); font-size: 18px; }
.prompt .battle.won { background: #dcebd2; }
.prompt .battle.lost { background: #f0d3cd; }
.strength { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; }
.card.big { --cw: 150px; }
.selected-card { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* Dice */
.die {
  width: 46px; height: 46px; display: inline-grid; place-items: center; flex: none;
  background: #fffaf0; color: var(--ink); border: 2px solid var(--ink); border-radius: 9px;
  font-weight: 800; font-size: 22px; box-shadow: 0 3px 0 var(--ink);
}
.die.d10 { border-radius: 4px; transform: rotate(45deg); width: 40px; height: 40px; }
.die.d10 span { transform: rotate(-45deg); }
.die.rolling { animation: roll .7s cubic-bezier(.2,.8,.3,1.2); }
@keyframes roll { 0% { transform: rotate(-200deg) scale(.4); opacity: 0; } 100% { opacity: 1; } }
.die.d10.rolling { animation-name: roll10; }
@keyframes roll10 { 0% { transform: rotate(-155deg) scale(.4); opacity: 0; } 100% { transform: rotate(45deg); opacity: 1; } }
.pips { display: grid; grid-template: repeat(3, 8px) / repeat(3, 8px); gap: 3px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.pips i.on { background: var(--ink); }

/* --- Areas of cards --- */
.area { background: rgba(0,0,0,.22); border: 1px dashed rgba(241,230,208,.18); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.area > h3 { font-size: 17px; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.area > h3 small { font-family: var(--font-body); font-size: 13px; }
.cards { display: flex; gap: 10px; flex-wrap: wrap; }
.piles { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.pile { display: grid; gap: 4px; justify-items: center; font-size: 13px; color: var(--muted); text-align: center; }

/* --- A card --- */
.card {
  --kind: var(--paper-blue);
  position: relative; width: var(--cw); aspect-ratio: 5 / 7; flex: none;
  background: var(--kind); color: var(--ink); border-radius: calc(var(--cw) * .07);
  border: 1px solid rgba(0,0,0,.35);
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 4px 10px rgba(0,0,0,.4);
  padding: calc(var(--cw) * .055); display: flex; flex-direction: column; gap: calc(var(--cw) * .035);
  font-size: calc(var(--cw) * .085); line-height: 1.15; text-align: left;
  font-family: var(--font-body); transition: transform .12s, box-shadow .12s;
  background-image: radial-gradient(circle at 20% 10%, rgba(255,255,255,.55), transparent 60%);
}
.card.k-chest, .card.k-item, .card.k-treasure { --kind: var(--paper-gold); }
.card.k-king { --kind: var(--paper-king); }
.card.k-move { --kind: #d8e8f3; }
.card .c-top { display: flex; align-items: center; gap: 4px; min-height: 1.6em; }
.card .c-name { flex: 1; font-family: var(--font-display); font-size: 1.12em; line-height: 1; min-width: 0; overflow-wrap: anywhere; }
.card .c-badge {
  flex: none; width: 1.75em; height: 1.75em; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: .95em; border: 1.5px solid var(--ink);
}
.card .c-cost { background: var(--royal); color: #fff; border-radius: 4px; }
.card .c-wealth { background: var(--gold); }
.card .c-art { flex: none; aspect-ratio: 1.45; border: 1.5px solid var(--ink); border-radius: 3px; background: radial-gradient(circle at 50% 40%, #4a3a2c, #16100b 80%); overflow: hidden; display: grid; place-items: center; }
.card .c-art svg { width: 82%; height: 92%; }
.card .c-text { flex: 1; font-size: .92em; color: #2c2216; overflow: hidden; }
.card .c-foot { display: flex; justify-content: space-between; align-items: center; font-size: .9em; font-weight: 700; }
.card .c-kind { text-transform: uppercase; letter-spacing: .08em; font-size: .78em; color: #5a4a36; }
.card .c-str { display: inline-flex; gap: 2px; align-items: center; background: #2a1d14; color: #fff6e4; padding: .05em .45em; border-radius: 3px; }
.card .c-str svg { width: 1em; height: 1em; }

.card.back {
  background: #2c3e63; border: 1px solid #0d1526;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 6px, transparent 6px 12px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.06) 0 6px, transparent 6px 12px);
  display: grid; place-items: center; padding: calc(var(--cw) * .08);
}
.card.back .emblem { width: 100%; height: 100%; border: 2px solid rgba(226,179,60,.7); border-radius: calc(var(--cw) * .04); display: grid; place-items: center; color: var(--gold); font-family: var(--font-display); font-size: 1em; text-align: center; }
.card.back .emblem svg { width: 55%; }
.card.back.b-king { background-color: #6b2a1e; }
.card.back.b-treasure { background-color: #6a5418; }
.card.back.b-move { background-color: #345b73; }
.card.empty { background: none; border: 2px dashed rgba(241,230,208,.25); box-shadow: none; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.count { font-weight: 700; color: var(--text); }

.card.can { cursor: pointer; box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,.45); }
.card.can:hover { transform: translateY(-6px); }
.card.sel { transform: translateY(-10px); box-shadow: 0 0 0 4px #7fd0ff, 0 10px 20px rgba(0,0,0,.5); }
.card.in-army { box-shadow: 0 0 0 3px var(--royal), 0 6px 14px rgba(0,0,0,.45); }
button.card { appearance: none; margin: 0; }
.mini { --cw: 26px; padding: 0; margin-left: -10px; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.mini:first-child { margin-left: 0; }
.stacked { box-shadow: 2px 2px 0 rgba(0,0,0,.35), 4px 4px 0 rgba(0,0,0,.25), 0 4px 10px rgba(0,0,0,.4); }

/* Your area */
.you-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.you-row .hand { flex: 1 1 400px; min-width: 0; }
.purse { display: grid; gap: 8px; justify-items: center; align-content: start; }
.coins { font-family: var(--font-display); font-size: 30px; color: var(--gold); display: flex; align-items: center; gap: 6px; }
.coins svg { width: 30px; height: 30px; }
.king-peek { display: grid; gap: 6px; justify-items: center; }

/* The log */
.log { max-height: 200px; overflow: auto; font-size: 14px; color: var(--muted); display: grid; gap: 2px; padding-right: 6px; }
.log .turn { color: var(--gold); font-family: var(--font-display); margin-top: 6px; }
details.area summary { cursor: pointer; font-family: var(--font-display); color: var(--muted); font-size: 17px; }

/* Reveal: a card shown in the middle of the table */
.reveal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10,6,3,.6); z-index: 20; padding: 16px; }
.reveal .inner { display: grid; gap: 14px; justify-items: center; text-align: center; animation: flip .6s ease-out; }
.reveal .card { --cw: min(210px, 50vw); }
.reveal p { margin: 0; font-size: 18px; max-width: 32ch; }
@keyframes flip { from { transform: perspective(800px) rotateY(90deg) scale(.7); opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--royal); color: #fff6e4; padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: calc(100% - 32px); box-shadow: 0 8px 20px rgba(0,0,0,.5); }

/* Rules dialog */
dialog.rules { max-width: min(760px, calc(100% - 32px)); max-height: calc(100% - 48px); border: 0; border-radius: 10px; padding: 0; background: var(--paper); color: var(--ink); }
dialog.rules::backdrop { background: rgba(10,6,3,.7); }
dialog.rules .body { padding: 20px 22px; overflow: auto; }
dialog.rules h2 { font-size: 30px; }
dialog.rules h3 { font-size: 20px; margin-top: 16px; }
dialog.rules p, dialog.rules li { max-width: 68ch; }
dialog.rules .close { position: sticky; top: 0; float: right; margin: 10px; }
dialog.rules .cards { margin: 8px 0; }

.over-banner { text-align: center; display: grid; gap: 10px; justify-items: center; }
.over-banner h2 { font-size: 30px; }

@media (max-width: 1000px) {
  :root { --cw: 96px; }
  .table { grid-template-columns: minmax(0, 1fr); grid-template-areas: "opps" "prompt" "board" "you" "side"; grid-template-rows: none; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .board { width: min(100%, 640px); }
}
@media (max-width: 560px) {
  .bar .right .home { display: none; }
  :root { --cw: 74px; }
  .table { padding: 10px 10px 16px; gap: 10px; }
  .board { min-width: 0; }
  .card:not(.big) .c-text { display: none; }
  .card:not(.big) .c-art { flex: 1; aspect-ratio: auto; }
  .opp { flex-basis: 100%; }
  .prompt h2 { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
