:root {
  color-scheme: dark;
  --ink-0: #0f0e0c;
  --ink-1: #151310;
  --ink-2: #1d1b18;
  --ink-3: #242220;
  --ink-4: #2b2824;
  --line: #46423b;
  --line-soft: #33302b;
  --text: #f3e9d6;
  --text-soft: #c3b9aa;
  --muted: #8a8175;
  --quiet: #6f675c;
  --ember: #c9663a;
  --ember-hover: #dc7947;
  --heading: "Cinzel", Georgia, serif;
  --prose: "EB Garamond", Garamond, Georgia, serif;
  --numbers: "Figtree", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { color: var(--text); background: var(--ink-1); font: 17px/1.5 var(--prose); }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--heading); letter-spacing: .02em; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: 17px; }
a { color: var(--ember); text-underline-offset: 3px; }
button, input { font: inherit; }
select { font: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { border-color: var(--ember) !important; box-shadow: 0 0 0 3px #c9663a38; }
::selection { background: #c9663a55; }

.site-header { display: flex; align-items: center; min-height: 68px; padding: 0 28px; border-bottom: 1px solid var(--line-soft); background: var(--ink-2); }
.brand { color: var(--text); font: 600 15px var(--heading); letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.site-header nav { display: flex; gap: 20px; margin-left: auto; }
.site-header nav a { color: var(--muted); font: 600 11px var(--heading); letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.site-header nav a:hover, .site-header nav a[aria-current="page"] { color: var(--ember); }

.page { width: min(960px, calc(100% - 32px)); margin: 0 auto; padding: 64px 0; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(--line-soft); }
.page-heading h1 { margin-bottom: 5px; }
.page-heading p { margin: 0; color: var(--muted); }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.auth-shell { width: min(430px, 100%); }
.auth-brand { margin-bottom: 22px; color: var(--ember); font: 600 11px var(--heading); letter-spacing: .2em; text-align: center; text-transform: uppercase; }
.auth-card { padding: 30px; border: 1px solid var(--line-soft); border-radius: 3px; background: var(--ink-2); }
.auth-card h1 { margin-bottom: 24px; font-size: 30px; }
.field { margin-bottom: 17px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font: 600 10.5px var(--heading); letter-spacing: .14em; text-transform: uppercase; }
.field input { width: 100%; min-height: 42px; padding: 9px 14px; border: 1px solid #3b3731; border-radius: 3px; color: var(--text); caret-color: var(--ember); background: var(--ink-0); font: 16px var(--prose); }
.primary-action, .secondary-action { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 0 20px; border-radius: 3px; font: 700 11px var(--heading); letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.primary-action { border: 0; color: var(--ink-1); background: var(--ember); }
.primary-action:hover { color: var(--ink-1); background: var(--ember-hover); }
.primary-action:disabled { cursor: not-allowed; opacity: .55; }
.primary-action.is-loading:disabled { cursor: wait; }
.secondary-action { border: 1px solid var(--line); color: var(--text-soft); background: var(--ink-4); }
.secondary-action:hover { color: var(--text); border-color: var(--muted); }
.block-action { width: 100%; }
.form-error { min-height: 24px; margin: 0 0 12px; color: #d98a72; }
.auth-switch { margin: 18px 0 0; color: var(--muted); text-align: center; }

.home-panel { padding: 34px; border: 1px solid var(--line-soft); border-radius: 3px; background: var(--ink-2); }
.home-panel h1 { margin-bottom: 10px; }
.home-panel > p { color: var(--muted); }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

.room-card { max-width: 620px; margin: 0 auto; padding: 30px; border: 1px solid var(--line-soft); border-radius: 3px; background: var(--ink-2); }
.room-card > p { color: var(--muted); }
.room-card select { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #3b3731; border-radius: 3px; color: var(--text); background: var(--ink-0); }
.room-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.room-status { min-height: 25px; margin: 16px 0 0; color: var(--muted); }
.player-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 26px 0; }
.player-slot { min-height: 145px; padding: 20px; border: 1px solid var(--line-soft); background: var(--ink-0); }
.player-slot span { display: block; margin-bottom: 12px; color: var(--ember); font: 700 10px var(--heading); letter-spacing: .14em; text-transform: uppercase; }
.player-slot strong { display: block; font: 600 17px var(--heading); }
.player-slot small { color: var(--muted); }
.invite-row { display: flex; gap: 8px; }
.invite-row input { min-width: 0; flex: 1; padding: 9px 12px; border: 1px solid var(--line); color: var(--text-soft); background: var(--ink-0); }

.game-board { margin-top: 24px; border: 1px solid var(--line-soft); border-radius: 3px; background: #11100e; overflow: hidden; }
.game-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.game-header { padding: 16px 20px; border-bottom: 1px solid var(--line-soft); background: var(--ink-2); }
.game-header div { display: flex; align-items: baseline; gap: 14px; }
.game-header span { color: var(--ember); font: 700 11px var(--heading); letter-spacing: .12em; text-transform: uppercase; }
.game-header strong { font: 600 16px var(--numbers); }
.game-header p { margin: 0; color: var(--text-soft); }
.three-stage { position: absolute; inset: 0; background: radial-gradient(circle at 50% 45%, #25211b, #0d0c0a 72%); overflow: hidden; touch-action: none; }
.three-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.three-hud { position: absolute; z-index: 2; left: 18px; min-width: 180px; padding: 8px 11px; border: 1px solid #6b563b77; border-radius: 3px; color: #eadcc4; background: #11100dcc; font: 600 12px var(--numbers); pointer-events: none; backdrop-filter: blur(5px); }
.three-hud-opponent { top: 15px; }
.three-hud-own { bottom: 15px; }
.three-help { position: absolute; z-index: 2; right: 15px; bottom: 15px; padding: 6px 9px; color: #958a79; background: #11100dbb; font: 600 10px var(--numbers); pointer-events: none; }
.three-tooltip { position: absolute; z-index: 3; max-width: 230px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 3px; color: var(--text); background: #11100ded; font: 12px var(--numbers); pointer-events: none; }
.three-card-preview { position: absolute; z-index: 7; top: 50%; left: 18px; width: clamp(280px, 32vw, 460px); padding: 7px; border: 1px solid #8a7049; border-radius: 5px; background: #0d0c0aeb; box-shadow: 0 18px 55px #000b; transform: translateY(-50%); pointer-events: none; backdrop-filter: blur(7px); }
.three-card-preview[hidden] { display: none; }
.three-card-preview img { display: block; width: 100%; aspect-ratio: 512 / 712; border-radius: 3px; object-fit: cover; }
.action-panel h2 { margin: 18px 0 10px; color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.action-panel { padding: 18px 20px 22px; border-top: 1px solid var(--line-soft); background: var(--ink-2); }
.game-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.game-actions button { min-height: 37px; padding: 0 12px; border: 1px solid var(--line); border-radius: 3px; color: var(--text-soft); background: var(--ink-4); font: 700 10px var(--heading); letter-spacing: .04em; }
.game-actions button:hover { border-color: var(--ember); color: var(--text); }
.game-actions button:disabled { cursor: wait; opacity: .5; }
.game-board.three-ready { position: fixed; z-index: 20; inset: 0; width: 100vw; height: 100vh; margin: 0; border: 0; border-radius: 0; }
.game-board.three-ready .game-header { position: absolute; z-index: 4; top: 15px; left: 50%; min-width: min(430px, calc(100vw - 400px)); padding: 9px 14px; border: 1px solid #6b563b77; border-radius: 3px; background: #11100dcc; transform: translateX(-50%); backdrop-filter: blur(6px); }
.exit-game { position: absolute; z-index: 6; top: 15px; right: 18px; min-height: 38px; padding: 0 13px; border: 1px solid #714638; border-radius: 3px; color: #dfb4a6; background: #211512dd; font: 700 10px var(--heading); letter-spacing: .08em; text-transform: uppercase; backdrop-filter: blur(6px); }
.exit-game:hover { color: #f3d1c6; border-color: #b5654c; background: #2c1914ee; }
.three-ready .action-panel { position: absolute; z-index: 4; right: 18px; bottom: 18px; width: min(390px, calc(100vw - 36px)); max-height: 32vh; padding: 11px 13px; border: 1px solid #6b563b77; border-radius: 3px; background: #11100ddd; overflow-y: auto; backdrop-filter: blur(7px); }
.three-ready .action-panel h2 { margin-top: 0; }
.game-message { position: absolute; z-index: 5; top: 72px; left: 50%; margin: 0; padding: 7px 11px; border-radius: 3px; color: #e7b39f; background: #281915dd; transform: translateX(-50%); pointer-events: none; }
.game-message:empty { display: none; }
.card-action-popup { position: fixed; z-index: 8; width: min(280px, calc(100vw - 24px)); padding: 10px; border: 1px solid #8a6543; border-radius: 4px; background: #11100df2; box-shadow: 0 16px 45px #000b; backdrop-filter: blur(8px); }
.card-action-popup[hidden] { display: none; }
.card-action-popup header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 3px 9px; }
.card-action-popup header strong { font: 600 13px var(--heading); }
.card-action-popup header button { width: 27px; height: 27px; border: 0; color: var(--muted); background: transparent; font-size: 20px; }
.card-action-popup header button:hover { color: var(--text); }
.card-action-stats { margin-bottom: 8px; padding: 8px 9px; border: 1px solid var(--line-soft); color: var(--text-soft); background: #1b1916; font: 600 12px var(--numbers); line-height: 1.45; }
.card-action-stats strong { color: var(--ember); }
.card-action-stats small { display: block; margin-top: 4px; color: var(--muted); font: 13px/1.3 var(--prose); }
.card-action-popup > div { display: grid; gap: 6px; }
.card-action-popup > div button { min-height: 38px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 3px; color: var(--text-soft); background: var(--ink-3); text-align: left; font: 700 10px var(--heading); letter-spacing: .04em; }
.card-action-popup > div button:hover { color: var(--text); border-color: var(--ember); }
.card-action-popup .popup-empty { margin: 0; padding: 7px 4px; color: var(--muted); font-size: 13px; }
body.game-active { overflow: hidden; }
body.game-active > .site-header, body.game-active > .page > .room-card { display: none; }
body.game-active > .page { width: 100%; margin: 0; padding: 0; }

.deck-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.deck-list a { display: flex; min-height: 135px; flex-direction: column; justify-content: space-between; padding: 18px; border: 1px solid var(--line-soft); border-radius: 3px; color: var(--text); background: var(--ink-2); text-decoration: none; }
.deck-list a:hover { border-color: var(--ember); background: var(--ink-3); }
.deck-list strong { font: 600 16px var(--heading); letter-spacing: .035em; }
.deck-list span { color: var(--muted); font: 600 12px var(--numbers); }
.empty-state { padding: 38px; border: 1px solid var(--line-soft); border-radius: 3px; color: var(--muted); background: var(--ink-2); text-align: center; }

@media (max-width: 700px) {
  .site-header { padding: 0 16px; }
  .page { padding: 36px 0; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .deck-list { grid-template-columns: 1fr; }
  .auth-card { padding: 23px; }
  .player-slots { grid-template-columns: 1fr; }
  .game-board { margin-right: -8px; margin-left: -8px; }
  .three-ready .three-stage { height: auto; }
  .three-help { display: none; }
  .three-card-preview { top: 50%; left: 8px; width: min(58vw, 290px); }
  .game-board.three-ready .game-header { top: 8px; width: calc(100vw - 16px); min-width: 0; }
  .exit-game { top: 62px; right: 8px; }
  .three-ready .action-panel { right: 8px; bottom: 8px; width: calc(100vw - 16px); max-height: 25vh; }
  .three-hud { left: 8px; min-width: 150px; }
  .three-hud-opponent { top: 68px; }
  .three-hud-own { bottom: calc(31vh + 18px); }
}
