:root {
  color-scheme: dark;
  --ink: #f4ecd9;
  --muted: #9fa9a3;
  --bg: #07110e;
  --panel: #0e1b17;
  --panel-2: #13231e;
  --line: #294138;
  --accent: #d57b42;
  --accent-2: #f1b06e;
  --green: #6fbe88;
  --danger: #d8655a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; color: var(--ink); background: radial-gradient(circle at 50% -15%, #1b3a2f 0, var(--bg) 38rem); }
button, input, select { font: inherit; }
button, label[for], select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.topbar { min-height: 68px; padding: 0 3vw; border-bottom: 1px solid var(--line); background: #08130ff2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 10px; font-family: Georgia, serif; font-size: 1.18rem; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid #a56138; color: var(--accent-2); transform: rotate(45deg); }
.brand-mark::first-letter { transform: rotate(-45deg); }
.room-chip { display: flex; align-items: center; gap: 9px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 8px 7px 16px; }
.room-chip span, .opponent-card small, .field-label, .eyebrow { color: var(--muted); font-size: .69rem; letter-spacing: .14em; }
.room-chip strong { letter-spacing: .14em; }
.icon-button { border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--ink); padding: 3px 8px 3px 12px; font-size: 1.15rem; }
.connection { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; }
.connection i { width: 8px; height: 8px; border-radius: 50%; background: #d9a149; box-shadow: 0 0 0 4px #d9a14918; }
.connection i.online { background: var(--green); box-shadow: 0 0 0 4px #6fbe8818; }
.connection i.offline { background: var(--danger); }
main { width: min(1480px, 94vw); margin: 0 auto; }
.setup-view { padding: 6vh 0 5vh; }
.setup-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.eyebrow { color: var(--accent-2); margin: 0 0 10px; font-weight: 700; }
h1 { font: 500 clamp(2rem, 4vw, 4rem)/1.02 Georgia, serif; max-width: 760px; margin: 0; letter-spacing: -.03em; }
.setup-players { display: flex; gap: 10px; align-items: stretch; }
.player-card, .opponent-card { display: flex; align-items: center; gap: 12px; min-width: 230px; background: var(--panel); border: 1px solid var(--line); padding: 13px 16px; }
.player-card > span:last-child { display: grid; gap: 4px; }
.player-card small { color: var(--muted); font-size: .69rem; letter-spacing: .14em; }
.player-card input { width: 150px; padding: 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); font-weight: 700; }
.opponent-card div { display: grid; gap: 4px; }
.opponent-card strong { font-size: .92rem; }
.opponent-card div > span { color: var(--muted); font-size: .72rem; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); color: var(--accent-2); font-family: Georgia, serif; }
.builder-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(330px, .75fr); gap: 18px; }
.panel { min-height: 510px; background: linear-gradient(145deg, #11211cdd, #0b1713dd); border: 1px solid var(--line); box-shadow: 0 24px 60px #0006; padding: 24px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.panel-title > div { display: flex; align-items: center; gap: 12px; }
.panel-title h2 { font: 500 1.45rem Georgia, serif; margin: 0; }
.step { color: var(--accent); font: italic 1rem Georgia, serif; }
.subtle, .storage-tools { color: var(--muted); font-size: .78rem; }
.search-box { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: #07110eaa; padding: 0 14px; }
.search-box:focus-within { border-color: var(--accent); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); padding: 14px 0; font-size: 1rem; }
.empty-message { color: var(--muted); text-align: center; padding: 80px 20px; }
.search-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; margin-top: 18px; max-height: 390px; overflow: auto; padding-right: 4px; }
.card-result { position: relative; min-width: 0; }
.card-result img, .battle-card img { display: block; width: 100%; aspect-ratio: 488/680; object-fit: cover; border-radius: 4.6% / 3.3%; background: #1b2b25; }
.card-result button { position: absolute; inset: auto 7px 7px 7px; border: 0; background: #f4ecd9ed; color: #102019; padding: 8px; font-weight: 750; opacity: .88; transform: translateY(3px); transition: .18s; }
.card-result:hover button, .card-result button:focus { opacity: 1; transform: none; }
.card-result button.added { background: var(--green); color: #07110e; opacity: 1; transform: none; }
.deck-tools { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 16px; }
.deck-tools #autoDeck { grid-column: 1 / -1; }
.deck-tools select, .text-input { width: 100%; background: #07110e; color: var(--ink); border: 1px solid var(--line); padding: 11px 12px; }
.field-label { display: block; margin: 12px 0 6px; }
.deck-list { margin-top: 16px; max-height: 265px; overflow: auto; border-top: 1px solid var(--line); }
.deck-row { display: grid; grid-template-columns: 38px 1fr auto auto auto; align-items: center; gap: 10px; min-height: 52px; border-bottom: 1px solid #21382f; }
.deck-row img { width: 34px; height: 42px; object-fit: cover; border-radius: 3px; }
.deck-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-row button { width: 28px; height: 28px; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.storage-tools { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 18px; }
.storage-tools span { margin-left: auto; }
.button { border: 1px solid var(--line); background: transparent; color: var(--ink); padding: 10px 16px; font-weight: 700; }
.button.primary { min-width: 190px; border-color: #e99d62; background: var(--accent); color: #160e09; }
.button.primary[disabled] { filter: grayscale(1); opacity: .4; cursor: not-allowed; }
.button.ghost:hover, .text-button:hover { color: var(--accent-2); }
.text-button { border: 0; padding: 0; background: transparent; color: var(--ink); text-decoration: underline; text-decoration-color: #ffffff35; text-underline-offset: 4px; }
.ready-bar { margin-top: 18px; border: 1px solid var(--line); background: #0d1c17; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 24px; }
.ready-bar > div { display: flex; align-items: center; gap: 14px; }
.ready-bar small { color: var(--muted); display: block; margin-top: 4px; }
.ready-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #6fbe8822; color: var(--green); border: 1px solid #6fbe8866; }
.game-view { padding: 18px 0 36px; }
.game-status { display: flex; justify-content: space-between; color: var(--muted); padding: 0 4px 12px; }
.game-status > div { display: flex; align-items: center; gap: 12px; }
.game-status time { color: var(--ink); font-variant-numeric: tabular-nums; font-size: .8rem; padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; }
.board { min-height: 38vh; display: grid; grid-template-columns: 120px 1fr 130px; gap: 16px; padding: 18px; border: 1px solid var(--line); background: radial-gradient(circle at center, #1a382c, #0b1713 72%); }
.remote-board { transform: rotate(180deg); }
.remote-board > * { transform: rotate(180deg); }
.board-side { display: flex; flex-direction: column; gap: 12px; }
.player-plate, .zone { border: 1px solid var(--line); background: #08130fdd; padding: 12px; }
.player-plate strong { font: 500 1.15rem Georgia, serif; display: block; margin-bottom: 10px; }
.life { display: flex; align-items: center; justify-content: center; gap: 8px; }
.life output { font: 500 2.2rem Georgia, serif; min-width: 46px; text-align: center; }
.life button, .zone button { border: 1px solid var(--line); background: #14271f; color: var(--ink); min-width: 30px; min-height: 30px; }
.zone { min-height: 118px; display: grid; place-items: center; gap: 7px; text-align: center; }
.zone span { color: var(--muted); font-size: .75rem; display: block; margin-bottom: 4px; }
.zone strong { font-size: 1.2rem; }
.zone-stack { width: 72px; padding: 0; border: 0 !important; background: transparent !important; color: var(--ink); }
.stack-card, .card-back { position: relative; display: grid; place-items: center; width: 56px; aspect-ratio: 488/680; margin: 0 auto 8px; border: 2px solid #9f633d; border-radius: 5px; background: radial-gradient(circle, #31483f 0 18%, #0a1511 19% 45%, #a65f34 46% 51%, #0a1511 52%); color: var(--accent-2) !important; box-shadow: 3px 3px 0 #172920, 6px 6px 0 #263d33; overflow: hidden; }
.stack-card img { width: 100%; height: 100%; object-fit: cover; }
.stack-card.empty { border-color: var(--line); background: #0b1713; box-shadow: none; opacity: .45; }
.zone-stack-label { font-size: .63rem !important; letter-spacing: .08em; }
.zone-stack strong { display: inline; margin-left: 4px; font-size: .9rem; }
.battlefield { display: flex; gap: 12px; flex-wrap: wrap; align-content: center; justify-content: center; min-width: 0; }
.battle-card { width: clamp(90px, 9vw, 132px); position: relative; z-index: 1; transition: .2s; }
.card-image-button { display: block; width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink); transition: transform .2s; }
.battle-card:hover, .hand-card:hover { z-index: 5; }
.battle-card:hover > .card-image-button { transform: scale(1.08); }
.hand-card:hover > .card-image-button { transform: scale(1.12); }
.battle-card.tapped { margin: 20px 24px; }
.battle-card.tapped > .card-image-button { transform: rotate(90deg); }
.battle-card.tapped:hover > .card-image-button { transform: rotate(90deg) scale(1.08); }
.counter { position: absolute; top: -8px; right: -8px; background: var(--accent); color: #130c08; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; box-shadow: 0 3px 10px #0008; }
.hand { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: safe center; align-items: end; min-height: 86px; overflow-x: auto; border-top: 1px solid #284137; padding: 10px 4px 4px; }
.hand-card { flex: 0 0 72px; width: 72px; min-width: 72px; max-width: 72px; display: grid; gap: 4px; }
.hand-card button { width: 100%; min-width: 0; overflow: hidden; }
.hand-card img { width: 100%; border-radius: 4px; display: block; }
.hand-card span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .7rem; margin-top: 4px; }
.hidden-hand { color: var(--muted); align-self: center; }
.opponent-hand { display: flex; justify-content: center; align-items: end; padding: 0 24px 8px; }
.opponent-hand .card-back { width: 48px; margin: 0 0 0 -24px; box-shadow: 2px 2px 0 #172920; transform: rotate(var(--angle)); transform-origin: bottom center; }
.opponent-hand .card-back:first-child { margin-left: 0; }
.table-divider { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; color: var(--muted); font-size: .67rem; letter-spacing: .13em; padding: 10px 18px; }
.table-divider i { height: 1px; background: var(--line); }
.toast { position: fixed; left: 50%; bottom: 28px; max-width: calc(100vw - 32px); text-align: center; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: #0b1713; padding: 11px 16px; z-index: 40; transition: .2s; box-shadow: 0 8px 30px #0008; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.card-preview, .card-menu { position: fixed; inset: auto; margin: 0; }
.card-preview { padding: 0; border: 0; border-radius: 4px; background: transparent; max-width: none; max-height: none; overflow: hidden; pointer-events: none; transition: display .14s allow-discrete, overlay .14s allow-discrete; }
.card-preview::backdrop, .card-menu::backdrop { display: none; background: transparent; }
.card-preview img { display: block; height: min(72vh, 680px); width: auto; max-width: min(90vw, 488px); object-fit: contain; border: 0; border-radius: 4px; opacity: 0; transform: scale(.985); transition: opacity .14s ease-out, transform .14s ease-out; }
.card-preview:popover-open img { opacity: 1; transform: scale(1); }
@starting-style { .card-preview:popover-open img { opacity: 0; transform: scale(.985); } }
.card-menu { z-index: 60; display: grid; gap: 2px; min-width: 148px; padding: 6px; border: 1px solid var(--line); background: #0e1b17f2; color: var(--ink); box-shadow: 0 16px 40px #000a; }
.card-menu:not([open]) { display: none; }
.card-menu button { width: 100%; border: 0; background: transparent; color: var(--ink); text-align: left; padding: 8px 10px; font-size: .8rem; }
.card-menu button:hover, .card-menu button:focus-visible { background: #1a332a; }
.preview-close { position: absolute; top: 8px; right: 8px; z-index: 1; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: #08130fee; color: var(--ink); font-size: 1.3rem; }
.graveyard-dialog { width: min(720px, 92vw); max-height: 82vh; border: 1px solid var(--line); background: #08130f; color: var(--ink); padding: 20px; box-shadow: 0 30px 100px #000d; }
.graveyard-dialog::backdrop { background: #000b; backdrop-filter: blur(4px); }
.dialog-heading h2 { margin: 0 45px 16px 0; font: 500 1.45rem Georgia, serif; }
.graveyard-cards { display: grid; gap: 8px; overflow: auto; max-height: 66vh; }
.graveyard-row { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--line); background: #0e1b17; }
.graveyard-row .card-image-button { width: 50px; }
.graveyard-row img { display: block; width: 100%; border-radius: 4px; }
.graveyard-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graveyard-actions { display: flex; gap: 5px; }
.graveyard-actions button { width: 32px; height: 32px; border: 1px solid var(--line); background: #14271f; color: var(--ink); }
footer { color: #77847d; font-size: .7rem; text-align: center; padding: 0 20px 22px; }
@media (prefers-reduced-motion: reduce) { .card-preview, .card-preview img { transition: none; } }
@media (max-width: 860px) {
  main { width: calc(100% - 24px); }
  .topbar { grid-template-columns: 1fr auto; padding: 10px 4vw; gap: 10px; }
  .room-chip { grid-row: 2; grid-column: 1 / -1; justify-self: center; }
  .connection { grid-column: 2; grid-row: 1; }
  .setup-view { padding: 32px 0; }
  .setup-heading { align-items: stretch; flex-direction: column; }
  .setup-players { flex-wrap: wrap; }
  .player-card, .opponent-card { flex: 1; }
  .builder-grid { grid-template-columns: 1fr; }
  .panel { min-height: auto; }
  .game-view { padding-top: 12px; }
  .board { grid-template-columns: 88px 1fr 94px; padding: 10px; gap: 8px; }
  .battle-card { width: 82px; }
  .card-preview { top: calc(env(safe-area-inset-top) + 72px) !important; left: 50% !important; transform: translateX(-50%); }
  .card-preview img { height: auto; max-height: 55dvh; max-width: 82vw; }
  .card-menu { inset: auto 8px calc(8px + env(safe-area-inset-bottom)) 8px !important; grid-template-columns: repeat(2, minmax(0, 1fr)); width: auto; max-height: 34dvh; overflow: auto; border-radius: 10px; padding: 8px; }
  .card-menu button { min-height: 44px; }
  .card-menu button:only-child { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar { min-height: 60px; grid-template-columns: auto 1fr auto; padding: max(8px, env(safe-area-inset-top)) 12px 8px; }
  .brand > span:last-child, .room-chip > span, .connection span { display: none; }
  .room-chip { grid-row: 1; grid-column: 2; justify-self: center; padding: 6px 8px 6px 13px; }
  .connection { grid-column: 3; grid-row: 1; }
  h1 { font-size: clamp(1.8rem, 9vw, 2.35rem); }
  .setup-view { padding-top: 28px; }
  .setup-heading { margin-bottom: 20px; }
  .panel { padding: 14px; }
  .setup-players { display: grid; }
  .player-card, .opponent-card { min-width: 0; padding: 12px; }
  .player-card > span:last-child, .opponent-card div { min-width: 0; }
  .player-card input { width: 100%; }
  .panel-title { gap: 8px; margin-bottom: 16px; }
  .panel-title h2 { font-size: 1.25rem; }
  .subtle { display: none; }
  .empty-message { padding: 48px 12px; }
  .search-results { grid-template-columns: repeat(2, 1fr); }
  .deck-row { gap: 6px; }
  .storage-tools span { width: 100%; margin-left: 0; }
  .ready-bar { align-items: stretch; flex-direction: column; }
  .button.primary { width: 100%; }
  .game-status { align-items: center; gap: 12px; font-size: .82rem; }
  .game-status > div { gap: 7px; }
  .board { grid-template-columns: 72px minmax(0, 1fr) 72px; min-height: 42vh; padding: 7px; gap: 6px; }
  .board-side { gap: 6px; }
  .player-plate, .zone { padding: 7px; }
  .player-plate strong { font-size: .9rem; overflow-wrap: anywhere; }
  .life { gap: 3px; }
  .life output { font-size: 1.6rem; min-width: 32px; }
  .zone { min-height: 96px; }
  .stack-card, .card-back { width: 46px; }
  .battlefield { gap: 8px; }
  .battle-card { width: 68px; }
  .battle-card.tapped { margin: 14px 18px; }
  .hand { gap: 6px; }
  .hand-card { flex-basis: 58px; width: 58px; min-width: 58px; max-width: 58px; }
  .table-divider { gap: 8px; padding: 9px 6px; font-size: .58rem; }
  .card-preview { top: calc(env(safe-area-inset-top) + 66px) !important; }
  .card-preview img { max-height: 42dvh; max-width: 90vw; }
  .graveyard-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 14px; }
  footer { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) {
  button, select { min-height: 44px; }
  .deck-row button, .graveyard-actions button, .preview-close { width: 44px; height: 44px; }
}
