/* Project: Duel Synapse — MEIOCG. Same tokens as the KodeX app (theme is read from the app's saved choice). */
:root {
  --bg: #080a10;
  --glow: #17213a;
  --panel: #111522;
  --panel-2: #171b2a;
  --panel-3: #080a10;
  --text: #eef2ff;
  --muted: #9aa4bd;
  --line: #272d40;
  --line-2: #33405a;
  --a: #67a8ff;
  --a2: color-mix(in srgb, var(--a) 62%, #fff);
  --soft: rgba(103,168,255,.16);
  --rival: #d2464f;
  --gold: #f2c75c;
  --ok: #5fd39a;
  --z: clamp(40px, min(calc((100vw - 410px) / 7.6), calc((100vh - 318px) / 7.6)), 104px);
  --ch: calc(var(--z) * .92);
  --cw: calc(var(--ch) * 59 / 86);
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
html, body { margin: 0; min-height: 100%; color: var(--text); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
body { background: radial-gradient(circle at top, var(--glow) 0, var(--bg) 58%) fixed; overflow-x: hidden; }
[hidden] { display: none !important; }
a { color: var(--a2); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--a2); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.12; }
code { background: #ffffff10; padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .grow { flex: 1; } .end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; min-height: 1em; }
.error { color: #ff8d95; font-size: 13px; min-height: 1em; margin: 2px 0 10px; }
.count { color: var(--muted); font-size: 12px; font-weight: 500; margin-left: 6px; }

.watermark { position: fixed; inset: 0; z-index: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; overflow: hidden; }
.watermark img { width: min(68vw, 720px); max-height: 68vh; object-fit: contain; opacity: .07; filter: saturate(.8); user-select: none; }
#lobby, #table, .top { position: relative; z-index: 2; }

/* ---------- controls (KodeX language) ---------- */
.btn { min-height: 42px; padding: 0 16px; border-radius: 13px; border: 1px solid var(--line); background: #151b24; color: #dfe6ef; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; transition: border-color .15s, background .15s; }
.btn:hover:not(:disabled) { border-color: #527ca7; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--soft); border-color: var(--a); color: var(--text); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--a) 28%, transparent); }
.btn:active:not(:disabled), .icon:active, .chips button:active, .seg button:active { transform: scale(.97); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb4ba; border-color: #4a262c; background: #1a1215; }
.btn.danger:hover:not(:disabled) { border-color: #8a3a44; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.icon { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: #151b24; cursor: pointer; font-size: 18px; line-height: 1; color: #dfe6ef; }
input, select, textarea { background: var(--panel-3); border: 1px solid var(--line); border-radius: 11px; padding: 9px 12px; min-height: 42px; width: 100%; color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--a); outline: none; box-shadow: 0 0 0 3px #61a8ff22; }
textarea { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
input[type=file] { padding: 8px; font-size: 13px; }
.field { display: grid; gap: 6px; margin: 0 0 12px; min-width: 0; }
.field > span:first-child { font-size: 12px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #111720; color: var(--muted); cursor: pointer; font-size: 13px; }
.chips button[aria-checked="true"], .chips button[aria-pressed="true"] { color: var(--text); border-color: var(--a); background: var(--soft); }
.panel { background: color-mix(in srgb, var(--panel) 93%, transparent); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(14px); }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid #ffffff0a; position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand img { display: block; width: 46px; height: 46px; object-fit: contain; filter: drop-shadow(0 0 4px var(--a)) drop-shadow(0 0 10px var(--glow)); }
.brand-text { display: grid; line-height: 1.05; }
.brand-kicker { font-size: .66rem; font-weight: 800; letter-spacing: .18em; color: var(--a); text-transform: uppercase; }
.brand-name { font-size: 19px; font-weight: 850; letter-spacing: -.01em; line-height: 1.2; }
.toplink { color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.toplink:hover { color: var(--text); border-color: var(--a); }
.net { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: #111720; }
.net.ok { color: var(--ok); border-color: #2b5b45; }
.net.bad { color: #ffb4ba; border-color: #5a2a30; }

/* ---------- lobby ---------- */
#lobby { max-width: 1120px; margin: 0 auto; padding: 18px 16px 28px; }
.hero { text-align: center; padding: 22px 0 26px; }
.hero-logo { display: block; margin: 0 auto 10px; filter: drop-shadow(0 0 5px var(--a)) drop-shadow(0 0 18px var(--glow)); animation: rise .5s ease both, glow 4s ease-in-out .6s infinite; }
.kicker { font-size: .72rem; font-weight: 800; letter-spacing: .22em; color: var(--a); }
.hero h1 { font-size: clamp(30px, 6vw, 54px); line-height: 1.05; margin: 8px 0 10px; letter-spacing: -.035em; font-weight: 850; }
.hero .sub { color: var(--muted); margin: 0; font-size: .95rem; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, 1fr); gap: 16px; align-items: start; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; font-weight: 800; }
.panel-head select { width: auto; max-width: 220px; min-height: 38px; }
.panel-head .btn { min-height: 38px; }
.deck-body { padding: 16px 18px 18px; }
.deck-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.deck-title h3 { font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.deck-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.deck-stats span { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; background: var(--panel-3); }
.deck-stats b { color: var(--text); font-weight: 700; }
.deck-section { display: flex; justify-content: space-between; margin: 16px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 5px; }
.deck-grid img, .deck-grid .ph { width: 100%; aspect-ratio: 59/86; border-radius: 4px; display: block; background: #121a2b; object-fit: cover; }
.deck-grid .nm { display: block; width: 100%; aspect-ratio: 59/86; border-radius: 4px; padding: 3px; font-size: 8px; line-height: 1.15; color: var(--muted); background: linear-gradient(160deg, #1d2a48, #0f1628); overflow: hidden; }
.warn { background: #2a2110; border: 1px solid #5b4416; color: #ffd98a; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 0 0 12px; }
.warn ul { margin: 4px 0 0; padding-left: 18px; }
.empty-state { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 46px 18px; color: var(--muted); }
.empty-state img { opacity: .55; margin-bottom: 6px; }
.empty-state p { margin: 0; color: var(--text); font-weight: 700; }
.empty-state.small { padding: 40px 12px; }
.play-panel { overflow: hidden; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 14px 14px 0; padding: 4px; border-radius: 13px; background: var(--panel-3); border: 1px solid var(--line); }
.seg button { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--a); }
.pane-body { padding: 16px 16px 6px; }
.disclose { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.disclose > summary { cursor: pointer; list-style: none; font-size: 13px; font-weight: 700; color: #c9d2e3; display: flex; align-items: center; margin-bottom: 10px; }
.disclose > summary::-webkit-details-marker { display: none; }
.disclose > summary::after { content: "›"; margin-left: auto; color: var(--a); font-size: 18px; transition: transform .18s; }
.disclose[open] > summary::after { transform: rotate(90deg); }
.test-hand { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 5px; max-height: 210px; overflow: auto; padding: 2px; }
.test-hand button { padding: 0; border: 2px solid transparent; border-radius: 6px; background: none; cursor: pointer; }
.test-hand button[aria-pressed="true"] { border-color: var(--a2); box-shadow: 0 0 12px #8be1ff66; }
.test-hand img, .test-hand .nm { width: 100%; display: block; border-radius: 3px; aspect-ratio: 59/86; object-fit: cover; }
.test-hand .nm { font-size: 7px; padding: 2px; background: #16203a; overflow: hidden; color: var(--muted); }
.room-code { display: flex; justify-content: space-between; align-items: center; margin: 2px 0 12px; padding: 14px 16px; border-radius: 14px; background: var(--panel-3); border: 1px solid var(--line); }
.room-code span { color: var(--muted); font-size: 12px; font-weight: 700; }
.room-code b { font-size: 30px; font-weight: 800; letter-spacing: .16em; color: var(--a2); font-variant-numeric: tabular-nums; }
.code-input { font-size: 22px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; text-align: center; }
.waiting { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--a2); box-shadow: 0 0 0 0 #8be1ff88; animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px #8be1ff00; } 100% { box-shadow: 0 0 0 0 #8be1ff00; } }
.guest { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: #0f1a14; border: 1px solid #2b5b45; font-size: 13px; color: #c7f0da; }
.engine-line { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); background: #0c1016; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex: none; }
.dot.ready { background: var(--ok); box-shadow: 0 0 8px #5fd39a99; }
.dot.fail { background: var(--rival); }
.foot { text-align: center; color: #5d6779; font-size: 12px; margin-top: 26px; }
.foot a { color: #7f8ba3; text-decoration: none; }
.foot a:hover { color: var(--text); }

/* ---------- table layout ---------- */
#table { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 12px; padding: 10px 12px; height: calc(100vh - 55px); height: calc(100dvh - 55px); }
.info, .side { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.info { position: fixed; left: 12px; top: 66px; bottom: 12px; width: min(330px, calc(100vw - 24px)); z-index: 45; box-shadow: 0 20px 60px #000c; transform: translateX(-112%); opacity: 0; pointer-events: none; transition: transform .24s cubic-bezier(.2,.8,.2,1), opacity .2s; }
.info.open { transform: none; opacity: 1; pointer-events: auto; }
.info-art { position: relative; width: 100%; max-width: 240px; aspect-ratio: 86 / 59; margin: 0 auto 14px; }
.info-art .info-img { position: absolute; left: 50%; top: 50%; width: 68.6%; max-width: none; margin: 0; transform: translate(-50%, -50%) rotate(-90deg); }
.info-art.op .info-img { transform: translate(-50%, -50%) rotate(90deg); }
.info-body > .nm { }
.info-body { padding: 16px; overflow: auto; flex: 1; }
.close-info { position: absolute; right: 10px; top: 10px; z-index: 2; }
.info-img { width: 100%; max-width: 240px; display: block; margin: 0 auto 14px; border-radius: 8px; aspect-ratio: 59/86; object-fit: cover; background: #121a2b; box-shadow: 0 14px 36px #000a; }
.info-body > .nm { display: grid; place-items: center; width: 100%; max-width: 240px; aspect-ratio: 59/86; margin: 0 auto 14px; border-radius: 8px; background: url("./assets/meiocg-192.webp") center / 40% no-repeat, linear-gradient(160deg, #1d2a48, #0f1628); border: 1px solid #34436a; font-size: 0; }
.info-name { font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 2px; }
.pill { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; font-size: 11px; color: var(--muted); }
.pill.hi { color: var(--a2); border-color: #2c4a6a; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 7px; margin-top: 12px; }
.stat { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; background: var(--panel-3); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat b { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--a2); font-weight: 700; }
.stat .up { color: var(--ok); } .stat .down { color: #ff8d95; }
.info-text { font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; color: #d8dde6; margin-top: 14px; }
.info-extra { font-size: 12.5px; color: var(--muted); margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.info-link { display: inline-flex; margin-top: 14px; font-size: 13px; font-weight: 600; text-decoration: none; border: 1px solid #355b8e; background: #101b29; color: #dfeeff; border-radius: 10px; padding: 8px 12px; }
.info-link:hover { border-color: var(--a); }

.arena { display: grid; grid-template-rows: auto auto 1fr auto auto auto auto; justify-items: center; min-height: 0; position: relative; gap: 5px; }
.duelist { width: min(100%, calc(var(--z) * 7.6 + 70px)); display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 14px; background: #10141bcc; border: 1px solid var(--line); }
.duelist.active { border-color: var(--a); box-shadow: 0 0 0 1px var(--a)55, 0 0 24px #61a8ff22; }
.duelist.op.active { border-color: #7a3a42; box-shadow: 0 0 0 1px #7a3a4255, 0 0 24px #d2464f22; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; background: linear-gradient(140deg, #2a5ea8, #17263a); border: 1px solid #3a5f8f; }
.op .avatar { background: linear-gradient(140deg, #7a2a33, #241417); border-color: #7a3a42; }
.who { min-width: 0; flex: 1; display: grid; line-height: 1.2; }
.who b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: 12px; }
.lp { display: flex; align-items: center; gap: 10px; }
.lp-label { font-size: 10px; font-weight: 900; letter-spacing: .1em; color: var(--muted); }
.lp-num { font-size: 26px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; min-width: 3.3ch; text-align: right; position: relative; }
.lp-bar { width: 110px; height: 6px; border-radius: 6px; background: #ffffff12; overflow: hidden; }
.lp-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--a), var(--a2)); transition: width .5s ease; }
.op .lp-bar i { background: linear-gradient(90deg, #a8323b, var(--rival)); }
.lp-pop { position: absolute; right: 0; top: -8px; font-size: 18px; font-weight: 800; pointer-events: none; animation: pop 1.3s ease-out forwards; }
.lp-pop.minus { color: #ff6b75; } .lp-pop.plus { color: var(--ok); }
@keyframes pop { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-30px); opacity: 0; } }

/* ---------- the mat ---------- */
.mat-wrap { position: relative; align-self: center; }
.mat {
  display: grid; grid-template-columns: repeat(7, var(--z)); grid-template-rows: repeat(5, var(--z)); gap: calc(var(--z) * .08);
  padding: calc(var(--z) * .14); border-radius: 20px; position: relative; isolation: isolate;
  background:
    linear-gradient(180deg, #d2464f10 0%, transparent 40%, transparent 60%, #61a8ff12 100%),
    radial-gradient(ellipse at 50% 50%, #142038 0%, #0b0f17 72%);
  border: 1px solid var(--line-2); box-shadow: inset 0 0 70px #000b, 0 24px 60px #000a;
}
.mat::before { content: ""; position: absolute; inset: 18% 30%; z-index: -1; background: url("./assets/meiocg-512.webp") center / contain no-repeat; opacity: .06; pointer-events: none; }
.mat::after { content: ""; position: absolute; left: 4%; right: 4%; top: 50%; height: 1px; background: linear-gradient(90deg, transparent, #8be1ff40, transparent); pointer-events: none; }
.zone { position: relative; border-radius: 10px; display: grid; place-items: center; border: 1px solid #ffffff12; background: #ffffff04; transition: box-shadow .15s, background .15s; }
.zone.op.mz, .zone.op.sz { background: #d2464f08; border-color: #d2464f1c; }
.zone.me.mz, .zone.me.sz { background: #61a8ff09; border-color: #61a8ff1f; }
.zone.emz { border-style: dashed; border-color: #8be1ff3a; background: #8be1ff07; }
.zone.pz::before { content: "P"; position: absolute; left: 5px; bottom: 3px; font-size: 9px; font-weight: 800; color: #8be1ff70; }
.zone.pile { background: #00000038; border-color: #ffffff14; cursor: pointer; }
.zone .lbl { position: absolute; width: 100%; text-align: center; padding: 0 2px; font-size: clamp(7px, calc(var(--z) * .11), 10px); font-weight: 800; letter-spacing: .06em; color: #ffffff2e; pointer-events: none; text-transform: uppercase; }
.zone .cnt { position: absolute; right: -5px; bottom: -6px; z-index: 3; min-width: 22px; height: 18px; padding: 0 5px; border-radius: 9px; background: #0b1120; border: 1px solid var(--line-2); font-size: 11px; font-weight: 800; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.zone.free { cursor: pointer; border-color: var(--a2); box-shadow: inset 0 0 0 2px #8be1ff55, 0 0 16px #8be1ff55; background: #8be1ff14; }
.zone.free.picked { background: #8be1ff40; }

/* ---------- cards ---------- */
.card { width: var(--cw); height: var(--ch); border-radius: 4px; position: relative; flex: none; transition: transform .16s ease, box-shadow .16s; cursor: pointer; background: #121a2b; box-shadow: 0 3px 10px #0008; }
.card img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; display: block; }
.card .nm { position: absolute; inset: 0; padding: 3px; font-size: 9px; font-weight: 600; line-height: 1.15; color: #c7d1e6; overflow: hidden; border-radius: 4px; border: 1px solid #34436a; background: linear-gradient(160deg, #1d2a48, #0f1628); }
.card.def { transform: rotate(-90deg); }
.op .card.def { transform: rotate(90deg); }
.card.back { background: url("./assets/meiocg-192.webp") center / 62% no-repeat, radial-gradient(circle at 50% 45%, #1b3a6a 0%, #0c1426 62%, #070b16 100%); border: 1px solid #2f4d7c; }
.card.back::after { content: ""; position: absolute; inset: 3px; border: 1px solid #61a8ff33; border-radius: 2px; }
.op .card.back, .card.back.op-back { border-color: #5a2a33; }
.card.peek img { opacity: .4; filter: grayscale(.35); }
.card.peek::after { content: "SET"; position: absolute; top: 3px; left: 3px; font-size: 8px; font-weight: 900; letter-spacing: .06em; background: #000b; padding: 1px 4px; border-radius: 3px; color: var(--a2); }
.card.negated img { filter: grayscale(1) brightness(.75); }
.card.act { box-shadow: 0 0 0 2px var(--a2), 0 0 16px #8be1ffaa; }
.card.selectable { box-shadow: 0 0 0 2px var(--gold), 0 0 14px #f2c75c99; }
.card.selected { box-shadow: 0 0 0 3px var(--ok), 0 0 16px #5fd39aaa; }
.card .stat { position: absolute; left: 50%; bottom: -13px; transform: translateX(-50%); white-space: nowrap; font-size: 10px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; background: #050810eb; border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 5px; z-index: 2; letter-spacing: 0; display: block; color: var(--text); text-transform: none; }
.card.def .stat { transform: translateX(-50%) rotate(90deg); bottom: auto; top: 40%; left: 112%; }
.op .card.def .stat { transform: translateX(-50%) rotate(-90deg); }
.card .badge { position: absolute; top: -6px; right: -6px; z-index: 2; min-width: 18px; height: 18px; border-radius: 9px; background: var(--a); color: #04101f; font-size: 10px; font-weight: 800; line-height: 18px; text-align: center; padding: 0 4px; }
.card .badge.ctr { background: var(--gold); top: auto; bottom: -6px; right: auto; left: -6px; }

.hand { display: flex; justify-content: center; align-items: flex-end; min-height: calc(var(--ch) * .82); width: 100%; padding: 2px 8px; }
.hand .card { margin: 0 calc(var(--cw) * -.06); }
.my-hand .card { --lift: 0px; transform: translateY(var(--lift)); }
.my-hand .card:hover, .my-hand .card:focus-visible { --lift: -14px; z-index: 5; }
.op-hand { min-height: calc(var(--ch) * .62); }
.op-hand .card { width: calc(var(--cw) * .7); height: calc(var(--ch) * .7); }

.chain-stack { position: absolute; right: calc(var(--z) * -1.3); top: 50%; transform: translateY(-50%); list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.chain-stack li { position: relative; width: calc(var(--cw) * .9); aspect-ratio: 59/86; background: #121a2b; border-radius: 4px; box-shadow: 0 0 0 2px var(--a2), 0 0 14px #8be1ff66; cursor: pointer; }
.chain-stack li .nm { position: absolute; inset: 0; padding: 3px; font-size: 8px; line-height: 1.15; overflow: hidden; color: #c7d1e6; }
.chain-stack li img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; display: block; }
.chain-stack li b { z-index: 1; position: absolute; left: -8px; top: -8px; width: 22px; height: 22px; border-radius: 50%; background: var(--a2); color: #04101f; font-size: 12px; font-weight: 900; line-height: 22px; text-align: center; }

.turnbar { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; }
.turn-no { font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: .04em; min-width: 54px; text-align: right; }
.phases { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; border-radius: 999px; background: #10141bcc; border: 1px solid var(--line); }
.phases button { min-width: 42px; min-height: 30px; border-radius: 999px; border: 0; background: transparent; color: #5f6a7d; font-size: 12px; font-weight: 800; letter-spacing: .04em; cursor: default; }
.phases button.now { color: var(--text); background: var(--soft); box-shadow: inset 0 0 0 1px var(--a); }
.phases button.go { color: var(--text); background: var(--soft); box-shadow: inset 0 0 0 1px var(--a); cursor: pointer; animation: ping 1.8s ease-in-out infinite; }
.status { min-height: 20px; font-size: 13px; color: var(--muted); text-align: center; }
.status.mine { color: var(--a2); font-weight: 600; }
.loading { position: absolute; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px; background: #07090dd9; backdrop-filter: blur(6px); border-radius: var(--radius); color: var(--muted); font-size: 14px; }
.loading img { animation: breathe 1.8s ease-in-out infinite; filter: drop-shadow(0 0 16px #61a8ff66); }
@keyframes breathe { 50% { transform: scale(1.06); opacity: .8; } }

/* ---------- side ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 6px 6px 0; gap: 4px; }
.tabs button { flex: 1; min-height: 40px; background: none; border: 0; color: var(--muted); cursor: pointer; font-weight: 700; font-size: 13px; border-radius: 10px 10px 0 0; }
.tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--a); }
.log { list-style: none; margin: 0; padding: 10px 14px; overflow: auto; flex: 1; font-size: 13px; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.log li { color: #c9d2e3; line-height: 1.4; }
.log li.turn { color: var(--a2); font-weight: 800; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; letter-spacing: .02em; }
.log li.turn:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.log li.phase { color: #5f6a7d; font-size: 11.5px; }
.log li.chain { color: var(--gold); }
.log li.dmg { color: #ff9aa2; }
.log li.sys { color: var(--muted); font-style: italic; }
.log li .c { color: var(--text); font-weight: 600; cursor: pointer; text-decoration: underline dotted #ffffff40; text-underline-offset: 2px; }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat li b { color: var(--a2); }
.side-actions { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 10px; background: #0c1016; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #c9d2e3; cursor: pointer; }
.toggle input { width: 18px; height: 18px; min-height: 0; accent-color: var(--a); }
.ai-share { margin-top: 8px; }
#aiNote:empty { display: none; }

/* ---------- prompt sheet ---------- */
.sheet { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(780px, calc(100vw - 24px)); max-height: min(62vh, 580px); display: flex; flex-direction: column;
  background: #10141bf5; border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: 0 28px 80px #000d, 0 0 0 1px #61a8ff14; z-index: 40; backdrop-filter: blur(18px); }
.sheet.min .sheet-body, .sheet.min .sheet-text { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; }
.sheet-head h3 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.sheet-text { margin: 4px 16px 0; color: var(--muted); font-size: 13.5px; }
.sheet-body { overflow: auto; padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 16px 10px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 0 16px 16px; }
.opt { display: grid; justify-items: center; gap: 4px; width: calc(var(--cw) * 1.25 + 10px); min-width: 66px; font-size: 11px; color: var(--muted); text-align: center; }
.opt .card { width: max(var(--cw), 58px); height: max(var(--ch), 85px); }
.opt .card.def { transform: none; }
.opt.rot .card.def { transform: rotate(-90deg); }
.card .vw { position: absolute; top: -7px; left: -7px; z-index: 4; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid var(--a); background: var(--panel); color: var(--a2); font: italic 800 12px/20px Georgia, serif; cursor: pointer; }
.card .vw:hover { background: var(--soft); }
.card.def .vw { }
.opt .where { line-height: 1.25; }
.opt .amt { font-size: 12px; font-weight: 800; color: var(--gold); }
.opt .btn { white-space: normal; width: 100%; font-size: 11px; line-height: 1.2; padding: 6px; height: auto; min-height: 30px; }
.choice-list { display: grid; gap: 8px; width: 100%; }
.choice-list .btn { text-align: left; white-space: normal; padding: 11px 14px; height: auto; font-weight: 500; }
.sheet .chips { width: 100%; }
.announce { width: 100%; display: grid; gap: 10px; }
.announce-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 250px; overflow: auto; }
.announce-list button { display: flex; gap: 8px; align-items: center; text-align: left; padding: 5px; border-radius: 10px; border: 1px solid var(--line); background: #151b24; cursor: pointer; font-size: 13px; }
.announce-list button:hover { border-color: #527ca7; }
.announce-list img, .announce-list .nm { width: 30px; aspect-ratio: 59/86; border-radius: 2px; flex: none; }
.announce-list .nm { font-size: 0; background: #16203a; }
.counter-row { display: grid; justify-items: center; gap: 6px; }
.counter-row .row { gap: 6px; }
.counter-row .row button { width: 30px; min-height: 30px; border-radius: 8px; border: 1px solid var(--line); background: #151b24; cursor: pointer; }

/* ---------- menus, dialogs, result ---------- */
.menu { position: fixed; z-index: 50; min-width: 200px; max-width: 290px; background: #121925f7; border: 1px solid var(--line-2); border-radius: 14px; padding: 6px; box-shadow: 0 18px 50px #000d; display: grid; gap: 2px; backdrop-filter: blur(14px); }
.menu button { text-align: left; padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-size: 14px; font-weight: 600; color: #dfe6ef; }
.menu button:hover, .menu button:focus-visible { background: #1b2a42; }
.menu .menu-title { padding: 6px 12px 6px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dlg { width: min(780px, calc(100vw - 24px)); max-height: 82vh; border: 1px solid var(--line-2); border-radius: var(--radius); background: #10141bf8; color: var(--text); padding: 0; box-shadow: 0 30px 90px #000d; }
.dlg::backdrop { background: #000000b0; backdrop-filter: blur(3px); }
.pile-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.pile-head h3 { font-size: 18px; font-weight: 800; }
.pile-body { padding: 16px; display: flex; flex-wrap: wrap; gap: 16px 10px; overflow: auto; max-height: calc(82vh - 66px); }
.pile-body .empty { color: var(--muted); margin: 0; }
.import-body { padding: 16px; }
.result { position: fixed; inset: 0; background: #000000b8; display: grid; place-items: center; z-index: 60; backdrop-filter: blur(4px); }
.result-card { background: #10141bf8; border: 1px solid var(--line-2); border-radius: 22px; padding: 28px 30px 24px; text-align: center; width: min(380px, 90vw); display: grid; justify-items: center; box-shadow: 0 30px 90px #000d; }
.result-card img { filter: drop-shadow(0 0 18px #61a8ff66); margin-bottom: 8px; }
.result-card h2 { font-size: 40px; font-weight: 800; letter-spacing: -.04em; margin-bottom: 6px; }
.result-card h2.win { background: linear-gradient(90deg, var(--a2), var(--a)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-card p { color: var(--muted); margin: 0 0 20px; }
.result-card .grid2 { width: 100%; }
.toast { position: fixed; left: 50%; top: 68px; transform: translateX(-50%); background: #121925f7; border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 16px; z-index: 70; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; box-shadow: 0 14px 40px #000c; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; }

/* ---------- smaller screens ---------- */
@media (max-width: 1120px) {
  :root { --z: clamp(36px, min(calc((100vw - 350px) / 7.6), calc((100vh - 305px) / 7.6)), 96px); }
  #table { grid-template-columns: minmax(0, 1fr) 270px; }
}
@media (max-width: 780px) {
  :root { --z: min(calc((100vw - 22px) / 7.75), calc((100vh - 268px) / 8.1)); }
  .lobby-grid { grid-template-columns: 1fr; }
  .play-panel { order: -1; }
  .deck-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
  .hero { padding: 10px 0 18px; }
  #table { display: block; height: auto; padding: 6px 4px 14px; }
  .side { margin-top: 18px; max-height: 70vh; }
  .chain-stack { right: auto; left: 50%; top: auto; bottom: calc(100% + 6px); transform: translateX(-50%); display: flex; }
  .chain-stack li { width: calc(var(--cw) * .7); }
  .duelist { padding: 6px 10px; gap: 10px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .lp-num { font-size: 22px; }
  .lp-bar, .lp-label { display: none; }
  .card .stat { font-size: 8.5px; bottom: -11px; padding: 2px 3px; }
  .my-hand .card { width: calc(var(--cw) * 1.25); height: calc(var(--ch) * 1.25); margin: 0 calc(var(--cw) * -.1); }
  .top { padding: 8px 12px; }
}
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } .result-card .grid2, .side-actions .grid2 { grid-template-columns: 1fr 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes glow { 50% { filter: drop-shadow(0 0 7px var(--a)) drop-shadow(0 0 24px var(--glow)); } }
@keyframes ping { 50% { box-shadow: inset 0 0 0 1px var(--a), 0 0 14px var(--soft); } }
@keyframes sheetUp { from { opacity: 0; transform: translate(-50%, 18px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes popIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes zonePulse { 50% { box-shadow: inset 0 0 0 2px #8be1ff88, 0 0 22px #8be1ff88; } }
.hero h1, .hero .kicker, .hero .sub { animation: rise .5s ease both; }
.hero .kicker { animation-delay: .05s; } .hero h1 { animation-delay: .1s; } .hero .sub { animation-delay: .16s; }
.lobby-grid > .panel { animation: rise .5s ease both; } .lobby-grid > .play-panel { animation-delay: .08s; }
#table:not([hidden]) .duelist, #table:not([hidden]) .mat-wrap, #table:not([hidden]) .side { animation: rise .45s ease both; }
#table:not([hidden]) .mat-wrap { animation-delay: .06s; }
.sheet:not([hidden]) { animation: sheetUp .26s cubic-bezier(.2,.8,.2,1); }
.menu:not([hidden]), .result-card { animation: popIn .18s ease; }
.result:not([hidden]) { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.zone.free { animation: zonePulse 1.5s ease-in-out infinite; }
.card:hover { filter: brightness(1.12); }
.btn, .icon, .chips button, .seg button, .phases button { transition: transform .12s, border-color .15s, background .15s, color .15s, box-shadow .15s; }
.lp-num { transition: color .3s; }
.toast { transition: opacity .2s, transform .2s; }
.deck-grid img, .test-hand img { transition: transform .15s; }
.deck-grid img:hover { transform: translateY(-2px); }

/* ---------- embedded in the KodeX app: the app supplies the header ---------- */
.embed .top, .embed .hero-logo, .embed .hero .kicker, .embed .foot { display: none; }
.embed #lobby { padding-top: 6px; }
.embed .hero { padding: 8px 0 18px; }
.embed #table { height: 100vh; height: 100dvh; }
.embed .info { top: 12px; }
.embed .toast { top: 14px; }
.embed #offBack { display: none !important; }
.embed { --z: clamp(40px, min(calc((100vw - 410px) / 7.6), calc((100vh - 255px) / 7.6)), 104px); }
@media (max-width: 1120px) { .embed { --z: clamp(36px, min(calc((100vw - 350px) / 7.6), calc((100vh - 255px) / 7.6)), 96px); } }
@media (max-width: 780px) { .embed { --z: min(calc((100vw - 22px) / 7.75), calc((100vh - 215px) / 8.1)); } }
