:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2738;
  --line: #2c3850;
  --text: #e6e9f0;
  --muted: #8d97ab;
  --accent: #f0b429;
  --p0: #4aa3ff;
  --p1: #ff6b6b;
  /* Cards scale with the window so the whole table fits without scrolling. */
  --card-h: clamp(48px, calc((100vh - 170px) / 7.6), 112px);
  --card-w: calc(var(--card-h) * 0.69);
  --gap: clamp(4px, calc(var(--card-h) * 0.08), 8px);
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at center, #18223a 0%, var(--bg) 70%);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button {
  font: inherit;
  background: var(--accent);
  color: #1b1b1b;
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: rgba(10, 14, 22, .6);
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.brand .tag { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 8px; }
.turninfo { flex: 1; text-align: center; color: var(--muted); }
.turninfo b { color: var(--text); }
.top-actions { display: flex; gap: 8px; }

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: clamp(160px, 18vw, 260px) 1fr clamp(210px, 22vw, 320px); gap: 10px; padding: 10px;
}
.detail, .rightcol { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-height: 0; }
.detail { padding: 14px; overflow: auto; }
.detail-empty { color: var(--muted); }
.detail h2 { margin: 0 0 4px; font-size: 17px; }
.detail .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.detail .stats { font-weight: 700; margin: 6px 0; }
.detail .text { white-space: pre-wrap; font-size: 13px; }
.detail .big { width: 100%; height: auto; aspect-ratio: 59 / 86; margin-bottom: 10px; }
.detail .big .name { font-size: 15px; }

.rightcol { display: flex; flex-direction: column; overflow: hidden; }
.prompt { padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 54px; }
.prompt .who { font-weight: 800; }
.prompt .who.p0 { color: var(--p0); }
.prompt .who.p1 { color: var(--p1); }
.prompt .error { color: var(--danger); margin-top: 4px; font-size: 13px; }
.actions { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); max-height: 45%; overflow: auto; }
.actions .action { text-align: left; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.actions .action b { color: var(--accent); }
.actions .phase-buttons { display: flex; gap: 6px; margin-top: 4px; }
.actions .phase-buttons button { flex: 1; }
.log { flex: 1; overflow: auto; padding: 10px 14px; font-size: 12.5px; color: #c8cede; }
.log .turn { color: var(--accent); font-weight: 700; margin-top: 8px; }
.log .phase { color: var(--muted); }
.log .win { color: var(--accent); font-weight: 800; font-size: 14px; margin-top: 8px; }

/* ---------------- table */
.table { display: flex; flex-direction: column; justify-content: center; gap: var(--gap); min-width: 0; overflow: auto; }
.side { display: flex; flex-direction: column; gap: var(--gap); padding: var(--gap); border-radius: 12px; border: 2px solid transparent; }
.side.deciding { border-color: rgba(240, 180, 41, .5); background: rgba(240, 180, 41, .04); }
.side-top { flex-direction: column-reverse; }
.row { display: grid; grid-template-columns: repeat(8, var(--card-w)); gap: var(--gap); justify-content: center; }
.side-top .row.field { direction: rtl; }
.hand { display: flex; gap: var(--gap); justify-content: center; min-height: calc(var(--card-h) * .9); flex-wrap: wrap; }
.hand .card { width: calc(var(--card-w) * .92); height: calc(var(--card-h) * .92); }
.playerbar { display: flex; justify-content: center; align-items: center; gap: 14px; font-weight: 700; }
.playerbar .name.p0 { color: var(--p0); }
.playerbar .name.p1 { color: var(--p1); }
.lp { font-variant-numeric: tabular-nums; background: #0b0f18; border: 1px solid var(--line); padding: 2px 10px; border-radius: 20px; }
.lp.low { color: var(--danger); }
.emz-row { display: grid; grid-template-columns: repeat(8, var(--card-w)); gap: var(--gap); justify-content: center; }

.zone {
  width: var(--card-w); height: var(--card-h); border: 1px dashed #34415d; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; position: relative; direction: ltr;
}
.zone .label { color: #4f5d7a; font-size: 10px; text-align: center; padding: 2px; }
.zone.empty-slot { border: 0; }
.zone.pile { border-style: solid; }
.count {
  position: absolute; bottom: -6px; right: -6px; background: #0b0f18; border: 1px solid var(--line);
  border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 700; z-index: 2;
}

/* ---------------- cards */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 5px; position: relative;
  border: 2px solid rgba(0, 0, 0, .55); padding: 4px; display: flex; flex-direction: column;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .5); color: #1b1b1b; overflow: hidden; cursor: default;
  transition: transform .12s, box-shadow .12s;
}
.card .name { font-weight: 700; font-size: clamp(7px, calc(var(--card-h) * 0.1), 10px); line-height: 1.1; max-height: 3.4em; overflow: hidden; }
.card .stars { font-size: 8px; color: #b3261e; margin-top: 2px; letter-spacing: -1px; }
.card .art { flex: 1; margin: 3px 0; border-radius: 3px; background: rgba(0, 0, 0, .15); }
.card .atkdef { font-size: 9px; font-weight: 700; text-align: right; }
.card .kind { font-size: 8.5px; font-weight: 700; text-align: right; }
.card.def { transform: rotate(90deg) scale(.9); }
.card.frame-normal { background: linear-gradient(#e8cf7f, #c9a94f); }
.card.frame-effect { background: linear-gradient(#e59a5c, #c4703a); }
.card.frame-spell { background: linear-gradient(#4fb39b, #2f8f7a); color: #fff; }
.card.frame-trap { background: linear-gradient(#c8669d, #a8457e); color: #fff; }
.card.frame-fusion { background: linear-gradient(#a27bd0, #7d4fa8); color: #fff; }
.card.frame-ritual { background: linear-gradient(#7b9de0, #4a6fb5); color: #fff; }
.card.frame-synchro { background: linear-gradient(#f4f4f4, #d6d6d6); }
.card.frame-xyz { background: linear-gradient(#4a4a4a, #222); color: #fff; }
.card.frame-link { background: linear-gradient(#4d82d6, #2a5aa8); color: #fff; }
.card.frame-token { background: linear-gradient(#bbb, #888); }
.card.back {
  background: repeating-linear-gradient(45deg, #5a3a1f 0 6px, #4a2f19 6px 12px);
  border-color: #2d1c0e; color: #f0dcb4; align-items: center; justify-content: center;
}
.card.back .peek { font-size: 8.5px; text-align: center; opacity: .85; font-style: italic; }
.card.back .swirl { width: 60%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(#c97a2b, #6b3b12 60%, transparent 62%); }
.card.actionable { box-shadow: 0 0 0 3px var(--accent), 0 0 14px rgba(240, 180, 41, .7); cursor: pointer; }
.card.actionable:hover { transform: translateY(-3px); }
.card.def.actionable:hover { transform: rotate(90deg) scale(.9) translateX(-3px); }
.card.selected { box-shadow: 0 0 0 3px #3ddc84, 0 0 14px rgba(61, 220, 132, .8); }
.card .mats { position: absolute; top: 2px; right: 3px; font-size: 9px; background: #000a; color: #fff; border-radius: 6px; padding: 0 4px; }

/* ---------------- popup + modal */
.popup {
  position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 150px; box-shadow: 0 8px 24px #000a;
}
.popup button { text-align: left; }
.popup .detail-line { font-size: 11px; color: var(--muted); padding: 0 4px 4px; max-width: 260px; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 14, .55); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 40px;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  max-width: min(900px, 92vw); max-height: 70vh; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 40px #000c;
}
.modal-title { font-weight: 700; font-size: 16px; white-space: pre-wrap; }
.modal-title .who.p0 { color: var(--p0); }
.modal-title .who.p1 { color: var(--p1); }
.modal-title .error { color: var(--danger); font-size: 13px; font-weight: 500; }
.modal-body { overflow: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.modal-body.buttons { flex-direction: column; flex-wrap: nowrap; }
.modal-body .choice-btn { text-align: left; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.modal-body .choice-btn .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 90px; cursor: pointer; }
.tile .where { font-size: 10.5px; color: var(--muted); text-align: center; }
.tile .card { pointer-events: none; }
.modal-footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.modal-footer .counter { margin-right: auto; color: var(--muted); }

.winner { position: fixed; inset: 0; background: rgba(5, 8, 14, .75); z-index: 40; display: flex; align-items: center; justify-content: center; }
.winner-box { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; padding: 30px 40px; text-align: center; }
.winner-text { font-size: 26px; font-weight: 800; margin-bottom: 16px; }

.footer { text-align: center; color: #56627c; font-size: 11px; padding: 4px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }

.card .stars.rank { color: #111; }
.frame-xyz .stars.rank { color: #f0b429; }
.zone.pick { border: 2px solid var(--accent); background: rgba(240, 180, 41, .15); cursor: pointer; box-shadow: 0 0 12px rgba(240, 180, 41, .5); }
.zone.pick:hover { background: rgba(240, 180, 41, .3); }
.chainmode {
  background: #0b0f18; color: var(--muted); border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 11px; font-weight: 400; padding: 2px 4px;
}
.playerbar { flex-wrap: wrap; }

/* ---------------- start screen / lobby */
.lobby { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1c2844 0%, #0b0f18 75%); }
.lobby-box { width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 30px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px #000c; }
.lobby-box h1 { margin: 0; font-size: 34px; letter-spacing: 1px; color: var(--accent); }
.lobby-box h2 { margin: 0; font-size: 19px; }
.lobby-box p { margin: 0; }
.lobby-box .error { color: var(--danger); }
.small { font-size: 12px; }
.field-label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.text-input { font: inherit; background: #0b0f18; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.text-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row button { flex: 1; padding: 10px 14px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .text-input { flex: 1; min-width: 0; font-size: 13px; }
.offline { font-size: 11px; font-weight: 600; color: var(--danger); border: 1px solid var(--danger); border-radius: 10px; padding: 0 6px; }
.waiting { color: var(--muted); }

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 4px; background: #0b0f18; border-radius: 8px; padding: 3px; }
.tab { flex: 1; background: transparent; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel-2); color: var(--text); }
.user-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-bar .link-button { margin-left: auto; }
.link-button { background: none; color: var(--muted); text-decoration: underline; padding: 2px 4px; font-weight: 400; }

/* ---------------- menus: home, starters, packs, deck editor */
.lobby-box { max-height: 94vh; overflow: auto; }
.lobby-box.wide { width: min(1400px, 97vw); height: 94vh; }
.lobby-box.wide h1 { display: none; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-grid button { padding: 12px; }
.menu-grid button:first-child { grid-column: 1 / -1; font-size: 16px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(240, 180, 41, .12);
  border: 1px solid rgba(240, 180, 41, .5); border-radius: 10px; padding: 10px 14px; }
.notice { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.starter-list, .pack-list { display: flex; flex-direction: column; gap: 12px; }
.starter, .pack { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.starter h3, .pack h3 { margin: 0; }
.starter p, .pack p { margin: 0; }
.card-list { margin: 0; padding-left: 18px; columns: 2; font-size: 13px; }
.screen-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.screen-top h2 { margin: 0 auto 0 0; }
.screen-top .deck-select, .screen-top .deck-name { font: inherit; background: #0b0f18; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; }
.screen-top .deck-name { flex: 1; min-width: 160px; }
.deck-status { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.deck-status .good { color: #3ddc84; font-weight: 700; }
.deck-status .bad { color: var(--danger); font-weight: 700; }
.problems { margin: 0; padding-left: 18px; color: var(--danger); font-size: 13px; }
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px 1fr 1fr; gap: 12px; }
.editor > * { min-height: 0; }
.menu-detail { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; font-size: 13px; }
.menu-detail h2 { font-size: 15px; margin: 0 0 4px; }
.menu-detail .meta { color: var(--muted); font-size: 12px; white-space: pre-wrap; margin-bottom: 6px; }
.menu-detail .stats { font-weight: 700; margin: 4px 0; }
.menu-detail .text { white-space: pre-wrap; }
.menu-detail .big { width: 100%; height: auto; aspect-ratio: 59 / 86; margin-bottom: 8px; }
.editor-deck, .editor-collection { display: flex; flex-direction: column; gap: 8px; overflow: auto; background: rgba(0, 0, 0, .15); border-radius: 10px; padding: 10px; }
.editor-deck h3 { margin: 4px 0 0; font-size: 14px; }
.editor-collection .tile-grid { overflow: auto; }
.collection-tools { display: flex; flex-direction: column; gap: 6px; }
.filters { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.filter-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 10px; padding: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.filter-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.filter-field > span:first-child { min-width: 64px; }
.filter-field.range { flex-wrap: wrap; }
.filter-select { background: var(--panel); color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px; font-size: 12px; max-width: 160px; }
.text-input.num { width: 72px; padding: 3px 6px; font-size: 12px; }
.chip:disabled { opacity: .5; cursor: default; }
.chip { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); padding: 3px 10px; font-size: 12px; font-weight: 600; border-radius: 14px; }
.chip.active { background: var(--accent); color: #1b1b1b; border-color: var(--accent); }
.tile-grid { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; --card-h: 86px; --card-w: 59px; }
.tile.mini { width: auto; }
.tile.mini .card { cursor: pointer; }
.tile.mini:hover .card { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--accent); }
.tile.used-up { opacity: .38; }
.pack-reveal { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; --card-h: 150px; --card-w: 104px; padding: 10px 0; }
.reveal-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.reveal-tile.hidden-card { cursor: pointer; }
.reveal-tile.hidden-card:hover .card { transform: translateY(-4px); box-shadow: 0 0 16px rgba(240, 180, 41, .6); }
.reveal-tile .card .name { font-size: 12px; }
.reveal-tile.rarity-ultra .card, .reveal-tile.rarity-secret .card { box-shadow: 0 0 18px rgba(240, 180, 41, .8); }
.reveal-tile.rarity-super .card { box-shadow: 0 0 14px rgba(120, 200, 255, .7); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tag { font-size: 10.5px; font-weight: 700; border-radius: 8px; padding: 1px 6px; background: var(--panel-2); border: 1px solid var(--line); }
.tag.new { color: #3ddc84; border-color: #3ddc84; }
.tag.maxed { color: var(--muted); }
.rarity-rare { color: #9ecbff; }
.rarity-super { color: #7fe3ff; }
.rarity-ultra { color: var(--accent); }
.rarity-secret { color: #ff8ef0; }
.lobby-box.wide .menu-detail:only-of-type { max-height: 260px; }

/* ---------------- card artwork */
.card.has-img { padding: 0; background: #111; border-color: #000; }
.card .art-img { width: 100%; height: 100%; object-fit: cover; border-radius: 3px; display: block; user-select: none; }
.card .stat-overlay { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, .78); color: #fff;
  font-size: clamp(7px, calc(var(--card-h) * .095), 11px); font-weight: 700; text-align: center; padding: 1px 0; }

.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
button.admin { border-color: var(--accent); color: var(--accent); }

/* Card preview size on menu screens */
.menu-detail .big { width: 100%; max-width: 190px; margin: 0 auto 8px; display: flex; }
.menu-detail.side { display: grid; grid-template-columns: 150px 1fr; column-gap: 14px; align-items: start; min-height: 120px; flex-shrink: 0; }
.menu-detail.side .big { grid-row: 1 / span 6; max-width: 150px; margin: 0; }
.menu-detail.side > :not(.big) { grid-column: 2; }

.card .counters { position: absolute; top: 2px; left: 2px; right: 2px; text-align: center; font-size: clamp(7px, calc(var(--card-h) * .09), 10px);
  font-weight: 800; background: rgba(120, 40, 160, .9); color: #fff; border-radius: 6px; padding: 0 3px; z-index: 3; }

/* ---------------- revealed cards panel */
.reveal {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 25;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 12px 40px #000c; display: flex; flex-direction: column; gap: 10px; max-width: min(700px, 92vw);
}
.reveal .reveal-title { font-weight: 700; }
.reveal .reveal-cards { display: flex; gap: 8px; flex-wrap: wrap; }
.reveal .reveal-footer { display: flex; justify-content: flex-end; }

/* ---------------- declare a card name */
.modal-body.declare { display: flex; flex-direction: column; gap: 8px; min-width: min(420px, 85vw); }
.modal-body.declare input { padding: 8px 10px; font-size: 15px; }
.declare-list { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }

/* ---- Pack Maker (admin) */
.pm-editor { grid-template-columns: 230px 1.1fr 1fr; }
.pm-name { min-width: 220px; }
.pm-desc { width: 100%; min-height: 44px; resize: vertical; font: inherit; font-size: 13px; }
.pm-art { display: flex; align-items: center; gap: 10px; }
.pm-art-frame { width: 96px; height: 140px; border: 2px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; padding: 4px; }
.pm-art-frame img { width: 100%; height: 100%; object-fit: cover; }
.pm-list { border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: rgba(0, 0, 0, .12); }
.pm-list.target { border-color: var(--accent); }
.pm-list-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; cursor: pointer; font-size: 13px; }
.drop-here { outline: 2px solid var(--accent); outline-offset: 2px; background: rgba(240, 180, 41, .08); }
.pm-shop-row { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pm-shop-row h3, .pm-shop-row p { margin: 0; }
.pm-slots { display: flex; gap: 10px; align-items: stretch; }
.pm-slots.wrap { flex-wrap: wrap; }
.pm-slot { width: 160px; min-height: 230px; border: 2px dashed var(--line); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 6px; }
.pm-slot.empty { color: var(--muted); text-align: center; }
.pm-pack { width: 140px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: grab; background: rgba(0, 0, 0, .18); border-radius: 8px; padding: 6px; }
.pm-pack.draft { opacity: .55; cursor: not-allowed; }
.pm-pack-art { width: 100px; height: 146px; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .25); }
.pm-pack-art img { width: 100%; height: 100%; object-fit: cover; }
.pack-art { width: 120px; height: 175px; object-fit: cover; border-radius: 8px; align-self: center; }

/* ---- banlist */
.tile.mini { position: relative; }
.ban-badge { position: absolute; top: 2px; left: 2px; min-width: 16px; height: 16px; border-radius: 50%; font-size: 11px; font-weight: 800; line-height: 16px; text-align: center; color: #fff; box-shadow: 0 0 0 2px #000; pointer-events: none; }
.ban-badge.ban-forbidden { background: #c62828; }
.ban-badge.ban-limited { background: #e65100; }
.ban-badge.ban-semiLimited { background: #f9a825; color: #1b1b1b; }
.ban-title.ban-forbidden { color: #ef5350; }
.ban-title.ban-limited { color: #ff9800; }
.ban-title.ban-semiLimited { color: #fdd835; }

/* ---- standings */
.standings { border-collapse: collapse; width: 100%; max-width: 640px; font-size: 14px; }
.standings th, .standings td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.standings th { color: var(--muted); font-weight: 600; }
.standings td:first-child, .standings th:first-child { width: 48px; }
.standings tr.me td { background: rgba(240, 180, 41, .15); font-weight: 700; }
.standings tr.gap td { color: var(--muted); border-bottom: none; }
.standings-search { max-width: 320px; }

/* ---- duel clock */
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }
.clock.running { color: var(--text); }
.clock.low { color: #ef5350; }

/* ---- main page: news + tutorial */
.news { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.news-head { display: flex; align-items: center; gap: 12px; }
.news-head h2 { margin: 0; }
.news-post { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.news-post h3 { margin: 0 0 2px; }
.news-editor { display: flex; flex-direction: column; gap: 8px; }
.news-body { min-height: 140px; resize: vertical; font: inherit; }
.md { max-width: 760px; line-height: 1.5; }
.md h3 { margin: 18px 0 6px; }
.md p { margin: 6px 0; }
.md ul { margin: 4px 0 8px; padding-left: 22px; }
.md code { background: rgba(0, 0, 0, .3); padding: 1px 5px; border-radius: 4px; }
.card-id { margin-top: 8px; }

/* ---- chat */
.chat { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; max-width: 760px; }
.chat-list { height: 220px; overflow-y: auto; background: rgba(0, 0, 0, .2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.chat-line { padding: 1px 0; }
.chat-time { color: var(--muted); font-size: 11px; margin-right: 6px; }
.chat-name.me { color: var(--accent); }
.chat-admin { background: none; border: none; color: var(--muted); font-size: 11px; padding: 0 4px; cursor: pointer; opacity: .6; }
.chat-admin:hover { opacity: 1; color: #ef5350; }
.chat-form { display: flex; gap: 6px; }
.chat-input { flex: 1; }

/* ---- bug reports */
.bug-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.bug-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(520px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.bug-box h2 { margin: 0; }
.bug-text { min-height: 140px; resize: vertical; font: inherit; }
.bug-report-text { white-space: pre-wrap; }
.bug-context { max-height: 260px; overflow: auto; background: rgba(0, 0, 0, .3); padding: 8px; border-radius: 6px; font-size: 11px; white-space: pre-wrap; }

.home-note { margin-top: 16px; background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 8px 14px; font-size: 14px; }

/* =================================================================== phones (narrow screens) */
.sheet-close { display: none; }
@media (max-width: 760px) {
  /* 8 zones per row fill the screen width */
  :root {
    --gap: 3px;
    --card-w: calc((100vw - 16px - 7 * var(--gap) - 12px) / 8);
    --card-h: calc(var(--card-w) / 0.69);
  }
  html, body { height: auto; min-height: 100%; }
  body { font-size: 14px; }
  button { padding: 8px 10px; }

  /* top bar */
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .brand { font-size: 15px; }
  .brand .tag { display: none; }
  .turninfo { order: 3; flex-basis: 100%; font-size: 12px; }
  .top-actions { margin-left: auto; gap: 4px; }
  .top-actions button { padding: 5px 8px; font-size: 12px; }

  /* duel: board on top, then the question + actions + log; card text in a bottom panel */
  .layout { display: flex; flex-direction: column; gap: 6px; padding: 4px; }
  .table { order: 1; overflow: visible; }
  .rightcol { order: 2; min-height: 0; }
  .actions { max-height: none; }
  .log { max-height: 220px; }
  .side { padding: 2px; }
  .playerbar { gap: 6px; font-size: 12px; }
  .playerbar .muted { font-size: 11px; }
  .chainmode { max-width: 100%; }
  .hand { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding-bottom: 4px; }
  .hand .card { flex: 0 0 auto; width: calc(var(--card-w) * 1.25); height: calc(var(--card-h) * 1.25); }
  .card { padding: 2px; border-width: 1px; border-radius: 3px; }
  .card .name { font-size: 6.5px; }
  .card .atkdef, .card .kind { font-size: 6.5px; }
  .card .stars { font-size: 5px; }
  .count { font-size: 9px; padding: 0 4px; right: -4px; bottom: -4px; }
  .zone .label { font-size: 7px; }

  .detail, .menu-detail {
    display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 55vh; overflow: auto;
    border-radius: 14px 14px 0 0; padding: 12px 14px 18px; box-shadow: 0 -10px 30px #000c;
  }
  .detail.sheet-open, .menu-detail.sheet-open { display: block; }
  .detail .big, .menu-detail .big { width: 38%; float: left; margin: 0 12px 6px 0; }
  .sheet-close { display: block; margin: 0 0 8px auto; padding: 4px 10px; font-size: 12px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }

  .popup { max-width: 92vw; }
  .modal-backdrop { padding-bottom: 8px; }
  .modal { max-width: 96vw; max-height: 80vh; padding: 12px; }
  .tile { width: 70px; }
  .winner-box { padding: 20px; margin: 0 12px; }
  .winner-text { font-size: 20px; }
  .reveal { max-width: 96vw; }

  /* menus fill the phone screen and scroll as one page */
  .lobby { align-items: flex-start; overflow-y: auto; }
  .lobby-box, .lobby-box.wide { width: 100vw; max-height: none; height: auto; min-height: 100vh; border-radius: 0; padding: 14px; border: 0; }
  .lobby-box h1 { font-size: 26px; }
  .menu-grid button { padding: 10px 8px; font-size: 13px; }
  .menu-grid button:first-child { font-size: 15px; }
  .editor, .pm-editor { display: flex; flex-direction: column; }
  .editor-deck, .editor-collection { overflow: visible; }
  .editor-collection .tile-grid { overflow: visible; }
  .tile-grid { --card-h: 74px; --card-w: 51px; }
  .filter-panel { grid-template-columns: 1fr; }
  .filter-select { max-width: 60vw; }
  .screen-top .deck-name { min-width: 0; }
  .card-list { columns: 1; }
  .chat-list { height: 180px; }
  .standings { font-size: 12px; }
  .standings th, .standings td { padding: 4px 6px; }
  .pack-art { width: 96px; height: 140px; }
  .pack-reveal { gap: 6px; --card-h: 120px; --card-w: 83px; }
  .bug-box { width: 96vw; }
}

/* Sign-up codes, forgot password, add email */
.auth-form h3 { margin: 0; }
.auth-links { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.auth-links .link-button { padding-left: 0; }
.add-email { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.add-email p { margin: 4px 0 8px; }
.add-email-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-email-form .text-input { flex: 1 1 200px; min-width: 0; }

/* Admin: players */
.player-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.player-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; text-align: left; background: var(--panel-2); color: inherit; border: 1px solid var(--line); font-weight: 400; }
.player-row:hover { border-color: var(--accent); }
.tag.bad { color: #ff6b6b; border-color: #ff6b6b; }
.player-detail .facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0; }
.player-detail .button-row { flex-wrap: wrap; align-items: center; }
.player-detail .button-row .text-input { flex: 1 1 200px; width: auto; min-width: 0; }
button.danger { background: #c0392b; color: #fff; }
.danger-zone { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }
.danger-zone summary { cursor: pointer; color: var(--danger); }
.danger-zone .button-row .text-input { flex: 1 1 200px; width: auto; min-width: 0; }
.rules-box { width: min(680px, 94vw); max-height: 88vh; }
.rules-body { overflow-y: auto; padding-right: 6px; }
.rules-body h3 { margin: 14px 0 6px; }
.rules-body h3:first-child { margin-top: 0; }
.footer a.rules-link, .auth-form a.rules-link { color: var(--accent); }

/* Beta and maintenance */
.brand .beta-tag { color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.maintenance-banner { background: #3a2a0a; border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.beta-note { margin: 8px 0 0; }
