:root {
  color-scheme: dark;
  --bg: #101814;
  --surface: #19231d;
  --line: #344137;
  --ink: #f7eedb;
  --muted: #b9b9a5;
  --gold: #e7ba70;
  --green: #b8e0bd;
  --rust: #ffd1ae;
  font-family: "Segoe UI", system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; background: radial-gradient(ellipse at 20% 0%, #243329, transparent 50%), var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #ffda91; outline-offset: 4px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.topbar { height: 67px; border-bottom: 1px solid var(--line); background: #121b16; padding: 0 max(24px, calc((100% - 1280px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: clamp(1rem, 2.3vw, 1.22rem); font-weight: 750; }
.brand-mark { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border: 1px solid #b68b53; border-radius: 10px; background: #253a2d; }
.brand-mark i, .seal i { display: block; width: 15px; height: 15px; border: 1px solid var(--gold); transform: rotate(45deg); position: relative; }
.brand-mark i::after, .seal i::after { content: ""; position: absolute; inset: 4px; background: var(--gold); }
.outline, .primary { padding: .65rem 1rem; border-radius: 10px; min-height: 43px; font-weight: 650; font-size: .91rem; }
.outline { color: var(--ink); background: #1b2720; border: 1px solid #465549; }
.outline:hover { background: #29392d; border-color: #82947d; }
.help span { display: inline-grid; place-items: center; width: 19px; height: 19px; margin-right: 5px; border: 1px solid #7b806a; border-radius: 50%; color: var(--gold); }
.help { flex-shrink: 0; white-space: nowrap; }
.page { width: min(1280px, calc(100% - 48px)); margin: auto; padding: 39px 0 18px; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 15px; margin-bottom: 25px; }
.intro h1 { margin: 4px 0 6px; font-family: "Noto Serif", Georgia, "Segoe UI", serif; font-size: clamp(2.35rem, 5.2vw, 4.15rem); font-weight: 700; letter-spacing: -.04em; line-height: 1.12; }
.intro p { margin: 0; color: var(--muted); line-height: 1.55; }
.intro .eyebrow { font-size: .82rem; letter-spacing: .14em; color: var(--gold); font-weight: 750; display: flex; align-items: center; gap: 8px; }
.eyebrow span { width: 7px; height: 7px; transform: rotate(45deg); background: var(--gold); }
.intro .outline { margin-bottom: 2px; flex-shrink: 0; }
.mode-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.mode-tabs .outline[aria-pressed="true"] { color: #f7dfac; background: #33483a; border-color: #a88a55; }
.room-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 9px; padding: 10px 14px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 12px; background: #202e25; }
.room-bar strong { color: var(--gold); margin-left: .28em; letter-spacing: .09em; }
.room-tools { display: flex; flex-wrap: wrap; gap: 7px; }
.room-bar p { flex-basis: 100%; margin: 0; overflow-wrap: anywhere; }
.online-lobby { max-width: 760px; padding: 24px; }
.online-lobby h2 { margin: 0; }
.online-lobby p, .leaderboard > p { max-width: 65ch; color: var(--muted); line-height: 1.5; }
.online-lobby form { max-width: 410px; display: grid; gap: 8px; }
.online-lobby form .primary { justify-self: start; }
.online-lobby label { display: block; font-size: .92rem; font-weight: 650; }
.online-lobby input { width: 100%; min-height: 44px; padding: 8px 11px; border: 1px solid #657465; border-radius: 9px; color: var(--ink); background: #131c17; font: inherit; }
.online-lobby input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.join-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 14px; }
.join-row label { margin-bottom: 6px; }
#join-code { text-transform: uppercase; }
.sign-in { width: fit-content; text-decoration: none; }
.online-lobby .online-message, .leaderboard .online-message { color: #f0cc96; }
.leaderboard { max-width: 1000px; }
.leaderboard > p { margin: 13px 15px; }
.rank-table-wrap { overflow: auto; }
.leaderboard table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.leaderboard th, .leaderboard td { padding: 12px 10px; border-top: 1px solid var(--line); text-align: center; }
.leaderboard th { background: #243329; color: var(--muted); font-size: .88rem; }
.leaderboard th:nth-child(2), .leaderboard td:nth-child(2) { text-align: left; overflow-wrap: anywhere; min-width: 85px; }
.leaderboard td:last-child { font-weight: 750; color: var(--gold); }
.leaderboard .mine { background: #2a3e30; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(270px, 318px); gap: 19px; align-items: start; }
.play, .side-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 17px; }
.play { overflow: hidden; }
.arena { min-height: 400px; height: clamp(400px, 36vw, 500px); position: relative; isolation: isolate; background: #32281f url("assets/river-market.webp") center 55% / cover no-repeat; }
.arena::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, #0a120fd6, #10161210 37%, #10161203 72%, #10161299); }
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 9px; padding: 19px; }
.score { min-width: 0; min-height: 65px; max-width: 178px; width: 100%; display: flex; align-items: center; gap: 11px; border: 1px solid #bd986978; border-radius: 12px; padding: 8px 10px; background: #161d18ed; }
.score > div:not(.avatar) { min-width: 0; }
.score span { display: block; color: #efdfbe; font-size: .83rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score strong { display: block; line-height: 1.15; font-size: 1.54rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.score.theirs { justify-self: end; justify-content: flex-end; text-align: right; }
.avatar { flex: 0 0 auto; display: grid; width: 35px; height: 35px; place-items: center; background: #315444; color: #c7dfab; border-radius: 8px; font-size: 1.18rem; }
.theirs .avatar { background: #613a2a; color: #f4bd90; }
.round { min-width: 94px; text-align: center; color: #fdf0d4; text-shadow: 0 2px 10px #000; font-size: .93rem; font-weight: 650; }
.round b { color: #ffdc9c; }
.round-track { display: flex; gap: 3px; justify-content: center; margin-top: 8px; }
.round-track span { width: 9px; height: 3px; border-radius: 3px; background: #efe7d455; }
.round-track .done { background: #e0a758; }
.round-track .current { background: #fff1ca; }
.online-clock { display: block; margin-top: 6px; color: #e9d9bb; font-size: .77rem; }
.online-clock.urgent { color: #ffb984; }
.table-cards { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -34%); display: flex; align-items: center; gap: clamp(12px, 3.5vw, 47px); }
.card-slot { display: grid; justify-items: center; gap: 11px; }
.card { width: clamp(102px, 13vw, 159px); aspect-ratio: 0.74; perspective: 950px; filter: drop-shadow(0 15px 12px #100e15a0); }
.card-inner { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transform: rotateX(4deg) rotateY(-7deg); transition: transform .62s cubic-bezier(.28,.69,.24,1); }
.card-slot:last-child .card-inner { transform: rotateX(4deg) rotateY(7deg); }
.card.revealed .card-inner, .card-slot:last-child .card.revealed .card-inner { transform: rotateX(4deg) rotateY(180deg); }
.card.reset .card-inner { transition: none; }
.card-face { position: absolute; inset: 0; display: grid; place-items: center; border: 2px solid #d5a564; border-radius: 12px; backface-visibility: hidden; overflow: hidden; }
.card-back { background: repeating-linear-gradient(45deg, #a3b7a008 0 1px, transparent 1px 9px), linear-gradient(155deg, #304939, #172b26 85%); box-shadow: inset 0 0 0 3px #172922; }
.card-back::before { content: ""; position: absolute; inset: 9px; border: 1px solid #ceac7270; border-radius: 7px; }
.card-back::after { content: ""; position: absolute; inset: 17px; border: 1px dashed #ceac7247; border-radius: 50%; }
.seal { display: grid; place-items: center; transform: rotate(45deg); width: 42%; aspect-ratio: 1; background: #233b30; border: 1px solid #bb945d; box-shadow: 0 0 0 5px #b58d5120; }
.seal i { transform: none; width: 26px; height: 26px; }
.seal i::after { inset: 8px; }
.card-front { transform: rotateY(180deg); background: #f1d2a2; padding: 7%; grid-template-rows: minmax(0, 1fr) auto; gap: 5px; }
.card-front img { width: 100%; height: 100%; object-fit: cover; border-radius: 7px; }
.card-front span { width: 100%; padding: 5px 3px; border-radius: 5px; background: #245239; color: #fff6e3; font-weight: 750; font-size: clamp(.75rem, 1.6vw, .94rem); text-align: center; }
.card-front.flip span { background: #87391f; }
.card-caption { display: inline-flex; white-space: nowrap; padding: 4px 10px; border-radius: 20px; border: 1px solid #b68b5270; background: #171b17ee; color: #f6e4c4; font-size: .8rem; font-weight: 650; }
.versus { color: #f9d598; font: 1.8rem Georgia, serif; text-shadow: 0 1px 7px #110b05; margin-top: -22px; }
.coin-layer { pointer-events: none; position: absolute; inset: 0; overflow: hidden; }
.coin { position: absolute; left: var(--start); top: 67%; width: 13px; height: 13px; border: 2px solid #ffe5a6; border-radius: 50%; background: #d3973f; box-shadow: 0 2px 6px #271b05; animation: toss .64s var(--delay) both ease-out; }
@keyframes toss { 0% { transform: scale(.5); opacity: 0; } 16% { opacity: 1; } 56% { transform: translate(var(--middle), -64px) rotateY(160deg); opacity: 1; } 100% { transform: translate(var(--end), -95px) rotateY(340deg) scale(.7); opacity: 0; } }
.controls { padding: 15px 19px 19px; min-height: 139px; }
.status { min-height: 24px; margin: 0 0 12px; text-align: center; color: #e9dec7; font-size: .95rem; line-height: 1.5; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.action { display: flex; align-items: center; gap: 11px; min-height: 64px; padding: 8px 12px; text-align: left; border: 1px solid #587865; background: #263e31; color: #f4f9e9; border-radius: 11px; }
.action.flip { border-color: #99694e; background: #503225; color: #fff3dc; }
.action:hover:not(:disabled), .action.picked { border-color: #ddc68d; filter: brightness(1.15); }
.action:disabled:not(.picked) { opacity: .7; }
.action b, .action small { display: block; }
.action b { font-size: 1.03rem; }
.action small { color: #d2d8c7; font-size: .79rem; margin-top: 2px; }
.action.flip small { color: #f1cdb5; }
.move-icon { flex: 0 0 36px; height: 36px; border-radius: 7px; background: center / cover no-repeat; box-shadow: 0 0 0 1px #f5e3ad24; }
.hold-icon { background-image: url("assets/hold.webp"); }
.flip-icon { background-image: url("assets/flip.webp"); }
kbd { border: 1px solid #ddcc9c51; color: #efdcb5; padding: 2px 5px; border-radius: 4px; line-height: 1; margin-left: auto; }
.primary { display: block; border: 1px solid #f7d4a0; color: #26180c; background: #e6b96f; }
.primary:hover { background: #f8d291; }
.controls .primary { min-height: 64px; width: 100%; }
.side { display: grid; gap: 16px; }
.side-panel { overflow: hidden; }
.panel-heading { padding: 16px 15px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading h2 { font-size: 1.05rem; margin: 0; }
.panel-heading > span { color: var(--gold); font-size: .85rem; font-variant-numeric: tabular-nums; }
.history-columns, .history li { display: grid; grid-template-columns: .65fr .95fr 1fr .65fr; gap: 5px; align-items: center; text-align: center; padding: 9px 10px; }
.history-columns { color: var(--muted); font-size: .78rem; border-bottom: 1px solid var(--line); }
.empty { display: grid; min-height: 172px; place-content: center; justify-items: center; text-align: center; gap: 5px; padding: 14px; }
.empty div { font-size: 2rem; line-height: 1; color: var(--gold); }
.empty p { margin: 2px 0 0; }
.empty small { color: var(--muted); font-size: .82rem; }
.history { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow: auto; }
.history li { min-height: 41px; font-size: .78rem; border-bottom: 1px solid #3341378c; }
.history li:last-child { border-bottom: 0; background: #243229; }
.history li span:last-child { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.history .hold-text { color: var(--green); }
.history .flip-text { color: var(--rust); }
.payoffs dl { margin: 0; padding: 4px 15px; }
.payoffs dl div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: .89rem; }
.payoffs dl div + div { border-top: 1px solid var(--line); }
.payoffs dd { margin: 0; font-weight: 700; color: var(--gold); white-space: nowrap; }
.payoffs p { margin: 3px 15px 15px; color: var(--muted); font-size: .83rem; }
footer { display: flex; justify-content: space-between; padding-top: 14px; color: var(--muted); font-size: .81rem; }
dialog { width: min(490px, calc(100% - 24px)); max-height: calc(100% - 24px); margin: auto; padding: 25px; border: 1px solid #9c815d; border-radius: 17px; background: #202c23; color: var(--ink); box-shadow: 0 18px 80px #0008; }
dialog::backdrop { background: #09120cbe; backdrop-filter: blur(3px); }
dialog h2 { font-size: 1.75rem; margin: 0 35px 9px 0; }
dialog h3 { margin-bottom: 5px; color: var(--gold); }
dialog p, dialog li { line-height: 1.55; color: #e1dfcb; }
dialog ul { padding-left: 20px; }
dialog li + li { margin-top: 5px; }
.close { position: absolute; top: 12px; right: 12px; min-width: 42px; min-height: 42px; font-size: 1.4rem; border-radius: 9px; border: 1px solid var(--line); color: var(--ink); background: #151e18; }
.rival-list { display: grid; gap: 8px; }
.rival-option { padding: 12px; text-align: left; display: flex; align-items: center; gap: 10px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.final-score { color: var(--gold); font-size: 1.42rem; font-weight: 750; margin: 10px 0 16px; }
@media (max-width: 960px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 260px; gap: 12px; }
  .card { width: clamp(102px, 16vw, 144px); }
  .action kbd { display: none; }
}
@media (max-width: 730px) {
  .page { width: calc(100% - 28px); padding-top: 23px; }
  .topbar { height: 58px; padding-inline: 14px; }
  .game-layout { grid-template-columns: 1fr; }
  .arena { min-height: 335px; height: clamp(335px, 77vw, 460px); }
  .card { width: clamp(97px, 26vw, 143px); }
  .table-cards { top: 51%; }
  .side { grid-template-columns: 1fr 1fr; gap: 12px; }
  .intro { margin-bottom: 17px; }
}
@media (max-width: 500px) {
  .help { padding-inline: 9px; }
  .help span { display: none; }
  .intro { flex-wrap: wrap; gap: 10px; }
  .intro .outline { min-height: 39px; padding: 6px 10px; }
  .intro p { font-size: .91rem; }
  .mode-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .mode-tabs .outline { padding: 6px 4px; font-size: .79rem; }
  .online-lobby { padding: 15px; }
  .leaderboard th, .leaderboard td { padding: 9px 4px; font-size: .79rem; }
  .side { grid-template-columns: 1fr; }
  .scoreboard { padding: 10px; gap: 6px; }
  .score { gap: 5px; padding: 6px; width: max-content; max-width: 100%; min-height: 55px; }
  .score .avatar { display: none; }
  .score span { font-size: .77rem; }
  .score strong { font-size: 1.35rem; }
  .round { min-width: 80px; font-size: .8rem; }
  .round-track span { width: 6px; }
  .controls { padding: 12px 10px; }
  .actions { gap: 7px; }
  .action { padding: 7px; gap: 7px; }
  .action .move-icon { flex-basis: 27px; height: 27px; }
  .action b { font-size: .97rem; }
  .action small { font-size: .73rem; }
}
@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
  .coin { display: none; }
}
