/* Duel Realms — styles */

:root {
  --bg: #0b0d1c;
  --panel: #171c38;
  --panel-2: #20264d;
  --line: #333d78;
  --text: #eceeff;
  --muted: #9aa2cf;
  --accent: #f2c14e;
  --accent2: #7ea6ff;
  --danger: #ff5d6c;
  --good: #4fd18b;
  --display: 'Cinzel', Georgia, 'Times New Roman', serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
}
body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #2b2f6e 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 110%, #3a1d4f 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit;
  color: inherit;
}
.muted {
  color: var(--muted);
}

/* ------------------------------------------------------------------ elements (colour tokens) */
.el-fire { --el: #f0703f; --el-dark: #5c1e0f; }
.el-water { --el: #45a0f5; --el-dark: #0f2f57; }
.el-earth { --el: #c29a62; --el-dark: #3f2d17; }
.el-wind { --el: #4fd394; --el-dark: #0f4a30; }
.el-light { --el: #f2d35a; --el-dark: #5a4510; }
.el-dark { --el: #b07af0; --el-dark: #33195e; }
.el-spell { --el: #47c04a; --el-dark: #10401a; }
.el-trap { --el: #c054e6; --el-dark: #43145e; }

/* ------------------------------------------------------------------ buttons */
.btn {
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a3163, #222852);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.18);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.btn.primary {
  background: linear-gradient(180deg, #f8d77a, #e3a93c);
  color: #2b1d04;
  border-color: #f2c14e;
  font-weight: 800;
}
.btn.danger {
  background: linear-gradient(180deg, #e2566a, #b8364b);
  border-color: #ff7787;
  font-weight: 700;
}
.btn.ghost {
  background: transparent;
}
.btn.small {
  padding: 5px 10px;
  font-size: 13px;
}
.btn.big {
  font-size: 19px;
  padding: 14px 24px;
  min-width: min(300px, 80vw);
  font-family: var(--display);
  letter-spacing: 0.04em;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ cards */
/* Every card face is its picture (a Card Creator design or an uploaded picture); see render.js. */
.card {
  position: relative;
  flex: none;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.075);
  font-size: calc(var(--cw) * 0.118);
  line-height: 1.15;
  color: #f5f6ff;
  user-select: none;
  overflow: hidden;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
}
.card.xs { --cw: 64px; --ch: 93px; }
.card.sm { --cw: 116px; --ch: 168px; font-size: 11px; }
.card.md { --cw: 150px; --ch: 218px; font-size: 12.5px; }
.card.lg { --cw: 236px; --ch: 342px; font-size: 14px; }
.card.hand { --ch: calc(var(--slot) * 1); --cw: calc(var(--ch) * 0.69); }
.card.hand-opp { --ch: calc(var(--slot) * 0.62); --cw: calc(var(--ch) * 0.69); }

/* Category at a glance: Normal monsters have a yellowish-brown frame, Effect monsters a reddish-brown
   frame (attribute colour stays on the badge, level stars and art); Fusion / Ritual monsters keep the
   attribute-coloured frame. Effect / Fusion / Ritual all get a thin gold inner trim. */
.st b {
  font-weight: 600;
  opacity: 0.65;
  font-size: 0.78em;
  margin-right: 0.25em;
}
.st.up { color: var(--good); }
.st.down { color: #ff8a96; }

/* compact cards on the board */
.card.onboard .st b,
.card.hand .st b {
  display: none;
}
.card.onboard .st:last-child::before,
.card.hand .st:last-child::before {
  content: '/ ';
  opacity: 0.5;
}
.card.pos-def {
  transform: rotate(-90deg);
}
.card.pos-def .st:first-child { opacity: 0.55; }
.card.pos-def .st:last-child { color: #a8d4ff; }
.card.set:not(.back)::after {
  content: 'SET';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.85);
  background: repeating-linear-gradient(135deg, rgba(20, 16, 60, 0.74) 0 6px, rgba(32, 26, 84, 0.74) 6px 12px);
  border-radius: inherit;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  transition: opacity 0.15s;
}
.card.set:not(.back):hover::after {
  opacity: 0.2;
}
.card.equipped {
  box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.5), 0 3px 8px rgba(0, 0, 0, 0.45);
}
.card.is-def::after {
  content: 'DEF';
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 800;
  background: #224a7a;
  padding: 1px 5px;
  border-radius: 4px;
}

/* card back (original emblem) */
.card.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 214, 120, 0.6) 0 5%, transparent 6%),
    radial-gradient(circle at 50% 50%, transparent 0 21%, rgba(255, 214, 120, 0.35) 22% 23.5%, transparent 24.5%),
    repeating-conic-gradient(from 0deg at 50% 50%, #2a2266 0 15deg, #1d1850 15deg 30deg);
  border: 2px solid #8d7be6;
}
.back-emblem {
  position: absolute;
  inset: 26% 20%;
  border: 2px solid rgba(255, 214, 120, 0.45);
  border-radius: 14%;
  transform: rotate(45deg) scale(0.62);
}

/* ------------------------------------------------------------------ title screen */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  max-width: 1320px;
  margin: 0 auto;
}
.title-screen {
  display: grid;
  place-items: center;
  text-align: center;
}
.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  line-height: 0.9;
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
}
.logo-top {
  font-size: clamp(26px, 6vw, 52px);
  letter-spacing: 0.5em;
  margin-right: -0.5em;
  color: #cfd6ff;
}
.logo-bottom {
  font-size: clamp(52px, 13vw, 124px);
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff3c4, #f2c14e 45%, #b9782a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 24px rgba(242, 193, 78, 0.35));
}
.tagline {
  color: var(--muted);
  margin: 12px 0 28px;
  font-size: 16px;
}
.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.title-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin: 34px 0 0;
  color: var(--muted);
  flex-wrap: wrap;
}
.title-stats dt {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.title-stats dd {
  margin: 4px 0 0;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
}

/* ------------------------------------------------------------------ screen header */
.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.screen-head h2 {
  font-family: var(--display);
  margin: 0;
  font-size: 26px;
}
.head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.notice {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.notice.bad {
  background: rgba(255, 93, 108, 0.12);
  border: 1px solid rgba(255, 93, 108, 0.4);
  color: #ffc2c9;
}
.notice.ok {
  background: rgba(79, 209, 139, 0.1);
  border: 1px solid rgba(79, 209, 139, 0.35);
  color: #b9f3d3;
}
.notice.small {
  font-size: 12px;
  padding: 6px 10px;
  margin: 8px 0 0;
}

/* ------------------------------------------------------------------ ladder */
.opp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
/* rivals grouped by card set */
.opp-set + .opp-set {
  margin-top: 24px;
}
.opp-set-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 2px 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.opp-set-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 20px;
  letter-spacing: 0.03em;
  color: var(--accent);
}
.opp-set-head span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.opp-card {
  all: unset;
  display: flex;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--oc) 18%, var(--panel)), var(--panel));
  border: 1px solid color-mix(in srgb, var(--oc) 40%, var(--line));
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.opp-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.opp-card:focus-visible {
  outline: 2px solid var(--accent);
}
.opp-card.locked {
  filter: grayscale(0.85);
  opacity: 0.6;
  cursor: not-allowed;
}
.opp-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #0b0d18;
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--oc) 70%, white), var(--oc) 60%, color-mix(in srgb, var(--oc) 50%, black));
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.opp-name { font-weight: 800; font-size: 17px; }
.opp-title { color: var(--muted); font-size: 13px; }
.opp-blurb { font-size: 13px; margin: 6px 0 8px; color: #cdd2f5; line-height: 1.4; }
.opp-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; }
.diff { padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.diff-easy { background: #1f5b3f; color: #9ef0c4; }
.diff-normal { background: #25426f; color: #b7d2ff; }
.diff-hard { background: #6b3a1d; color: #ffd2a8; }
.diff-expert { background: #6a1f35; color: #ffb3c4; }
.won { color: var(--good); font-weight: 700; }

/* ------------------------------------------------------------------ deck builder */
.deck-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.tabs {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px;
  border-radius: 10px;
  flex-wrap: wrap;
}
.tab {
  all: unset;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}
.tab.on {
  background: var(--panel-2);
  color: var(--text);
}
.tab:focus-visible,
.chip-btn:focus-visible {
  outline: 2px solid var(--accent2);
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip-btn {
  all: unset;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  color: var(--muted);
}
.chip-btn.on {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}
.search {
  flex: 1 1 180px;
  min-width: 150px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
}
.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 12px;
}
.coll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 16px 10px;
}
/* deck builder: each card set's cards under the set's name */
.coll-set {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--line);
}
.coll-set:not(:first-child) {
  margin-top: 8px;
}
.coll-set b {
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.03em;
  color: var(--accent);
}
.coll-set span {
  color: var(--muted);
  font-size: 12px;
}
.coll-item {
  position: relative;
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding-top: 4px;
}
.coll-item .card {
  transition: transform 0.15s, box-shadow 0.15s;
}
.coll-item:hover .card {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}
.coll-item .own {
  position: absolute;
  top: -4px;
  right: 2px;
  background: #0b0d18;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 700;
}
.coll-item .indeck {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #2a1d05;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.deck-panel {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
}
.deck-detail {
  display: flex;
  justify-content: center;
  flex: none;
}
.deck-detail .detail-empty {
  padding: 24px;
}
.deck-summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}
.sum-row { display: flex; justify-content: space-between; font-size: 15px; }
.sum-row .ok { color: var(--good); font-weight: 800; }
.sum-row .bad { color: var(--danger); font-weight: 800; }
.sum-split { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); margin-top: 6px; }
.deck-list {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  min-height: 120px;
  flex: 1 1 auto;
}
.dg-head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 8px 4px 4px;
  display: flex;
  justify-content: space-between;
}
.deck-row {
  all: unset;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid var(--el);
  margin-bottom: 2px;
}
.deck-row:hover {
  background: rgba(255, 93, 108, 0.12);
}
.deck-row:focus-visible {
  outline: 2px solid var(--accent2);
}
.dr-count { font-weight: 800; }
.dr-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dr-meta { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ rules & settings */
.rules {
  max-width: 840px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}
.rules section,
.settings fieldset {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
}
.rules h3 {
  font-family: var(--display);
  margin: 0 0 8px;
  color: var(--accent);
}
.rules p,
.rules li {
  line-height: 1.6;
  color: #d6daf7;
}
.settings {
  max-width: 660px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}
.settings legend {
  padding: 0 6px;
  font-weight: 700;
  color: var(--accent);
}
.radio {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  cursor: pointer;
}

/* ------------------------------------------------------------------ duel layout */
.duel-host {
  position: fixed;
  inset: 0;
}
.duel {
  --sidebar: 300px;
  --slot: clamp(36px, min(calc((100vh - 172px) / 6.3), calc((100vw - var(--sidebar) - 44px) / 7.55)), 134px);
  --slot: clamp(36px, min(calc((100dvh - 172px) / 6.3), calc((100vw - var(--sidebar) - 44px) / 7.55)), 134px);
  --gap: calc(var(--slot) * 0.07);
  --ch: calc(var(--slot) * 0.94);
  --cw: calc(var(--ch) * 0.69);
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar);
}
.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 8px;
}
.board {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 18px;
  background: radial-gradient(ellipse at 50% 50%, rgba(80, 90, 190, 0.18), transparent 70%), rgba(10, 12, 28, 0.35);
  border: 1px solid rgba(140, 150, 255, 0.12);
}
.side {
  display: grid;
  gap: var(--gap);
  justify-content: center;
}
.row {
  display: grid;
  grid-template-columns: repeat(7, var(--slot));
  gap: var(--gap);
}
.slot {
  width: var(--slot);
  height: var(--slot);
  border-radius: calc(var(--slot) * 0.1);
  background: rgba(255, 255, 255, 0.025);
  border: 1px dashed rgba(170, 180, 255, 0.16);
  display: grid;
  place-items: center;
  position: relative;
}
.slot.filled {
  border-style: solid;
  border-color: rgba(170, 180, 255, 0.07);
}
.slot.z-field {
  background: rgba(80, 200, 160, 0.05);
}
.slot.pile.clickable {
  cursor: pointer;
}
.slot-label {
  font-size: calc(var(--slot) * 0.13);
  color: rgba(200, 205, 255, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pile-count {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: max(10px, calc(var(--slot) * 0.13));
  background: rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  padding: 0 5px;
  font-weight: 700;
  z-index: 2;
}
.hand {
  display: flex;
  justify-content: center;
  min-width: 0;
}
.my-hand {
  height: calc(var(--slot) * 1.04);
  align-items: flex-end;
  padding-top: 2px;
}
.my-hand .card {
  margin-left: calc(var(--cw) * var(--overlap, 0.04) * -1);
  transition: transform 0.15s ease;
}
.my-hand .card:first-child {
  margin-left: 0;
}
.my-hand .card:hover {
  transform: translateY(-14%);
  z-index: 3;
}
.opp-hand {
  height: calc(var(--slot) * 0.46);
  overflow: hidden;
  align-items: flex-end;
}
.opp-hand .card {
  margin-left: calc(var(--cw) * -0.22);
  transform: translateY(18%);
}
.opp-hand .card:first-child {
  margin-left: 0;
}

/* player bars */
.pbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: linear-gradient(180deg, var(--panel), #141936);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 48px;
  position: relative;
}
.pbar.hit {
  animation: hitFlash 0.5s ease;
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 12px;
  color: #0b0d18;
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--av) 80%, white), var(--av) 60%, color-mix(in srgb, var(--av) 50%, black));
  border: 2px solid rgba(255, 255, 255, 0.25);
  flex: none;
}
.avatar.active {
  box-shadow: 0 0 0 3px var(--accent), 0 0 18px rgba(242, 193, 78, 0.6);
}
.pinfo {
  flex: 1;
  min-width: 0;
}
.pname {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ptitle {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}
.lpbar {
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-top: 4px;
}
.lpfill {
  height: 100%;
  background: linear-gradient(90deg, #4fd18b, #a8e05f);
  transition: width 0.4s;
}
.lpbar.low .lpfill {
  background: linear-gradient(90deg, #ff5d6c, #ff9a5d);
}
.lp {
  position: relative;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 92px;
  justify-content: flex-end;
}
.lp-label {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--ui);
}
.lp-float {
  position: absolute;
  right: 0;
  top: -8px;
  font-weight: 800;
  font-size: 20px;
  pointer-events: none;
  animation: floatUp 0.9s ease forwards;
  font-family: var(--ui);
}
.lp-float.neg { color: var(--danger); }
.lp-float.pos { color: var(--good); }
.counts {
  display: flex;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

/* middle bar */
.midline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 0 4px;
}
.turn-info {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  min-width: 96px;
}
.turn-info b {
  color: var(--text);
}
.phases {
  display: flex;
  gap: 4px;
}
.chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid transparent;
}
.chip.on {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.phase-btns {
  display: flex;
  gap: 6px;
  min-width: 96px;
  justify-content: flex-end;
}
.target-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: center;
  font-size: 14px;
  flex-wrap: wrap;
}
.only-narrow {
  display: none;
}

/* highlights */
.card.can-act {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 14px 2px rgba(242, 193, 78, 0.55);
  cursor: pointer;
}
.my-hand .card.can-act {
  outline-offset: -2px;
  box-shadow: 0 0 12px rgba(242, 193, 78, 0.45), 0 3px 8px rgba(0, 0, 0, 0.45);
}
.card.targetable,
.avatar.targetable {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
  cursor: crosshair;
  animation: targetPulse 1s ease infinite;
}
.card.attacking {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.under-attack {
  animation: targetPulse 0.7s ease;
}

/* sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: rgba(12, 14, 30, 0.72);
  border-left: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
}
.detail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 400px;
  flex: none;
}
/* the duel's card preview (sidebar + tap-to-inspect sheet) shows the card alone, so it can run larger */
.detail .card.lg,
.overlay.sheet .card.lg { --cw: 272px; --ch: 394px; font-size: 16px; }
.detail-info {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}
.detail-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 40px 10px;
  text-align: center;
}
.chain-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  flex: none;
}
.chain-box:empty {
  display: none;
}
.chain-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--accent);
}
.chain-link {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 2px 0;
}
.cl-n {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex: none;
}
.chain-link.opp .cl-n { background: #6a2333; }
.chain-link.me .cl-n { background: #23436a; }
.log {
  flex: 1 1 auto;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.45;
  color: #c9cdf0;
  padding-right: 4px;
  min-height: 60px;
}
.log-line.turn {
  color: var(--accent);
  font-weight: 700;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(242, 193, 78, 0.22);
}
.log-line.turn:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.side-actions {
  display: flex;
  flex-wrap: wrap; /* longer labels in some languages take two rows */
  gap: 8px;
  justify-content: space-between;
  flex: none;
}

/* menus, modals, overlays */
.menu-layer {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
}
.card-menu {
  position: absolute;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  padding: 6px;
  background: #20264d;
  border: 1px solid #3a4486;
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  animation: modalIn 0.12s ease;
}
.menu-item {
  all: unset;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.1);
}
.menu-item.muted {
  color: var(--muted);
  font-size: 13px;
}
.modal-layer,
.overlay-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}
.overlay-layer {
  z-index: 70;
}
.modal-layer.open,
.overlay-layer.open {
  display: block;
}
.modal-backdrop,
.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 14, 0.6);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal,
.overlay {
  background: linear-gradient(180deg, #1d2346, #161b38);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  width: min(900px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.18s ease;
}
.yesno-modal,
.pos-modal,
.option-modal {
  width: min(520px, 100%);
}
/* popups can be moved by their title bar (duel-ui.js makeDraggable) */
.modal.drag-win {
  position: fixed;
  margin: 0;
}
.drag-handle {
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.drag-handle:active {
  cursor: grabbing;
}
/* small floating windows (Respond?, yes / no): the board stays visible and can still be pointed at */
.modal-layer.float,
.modal-layer.float .modal-backdrop {
  pointer-events: none;
  background: none;
}
.modal-layer.float .modal {
  pointer-events: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(242, 193, 78, 0.25);
}
.resp-modal,
.modal.yesno-modal {
  width: auto;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 14px;
}
.resp-modal .modal-head h3,
.yesno-modal .modal-head h3 {
  font-size: 16px;
}
.resp-modal .modal-sub {
  font-size: 12.5px;
}
.resp-modal .resp-list {
  gap: 10px;
  margin-top: 8px;
}
.resp-modal .resp-item {
  gap: 6px;
}
.resp-modal .modal-actions,
.yesno-modal .modal-actions {
  margin-top: 10px;
}
.overlay.sheet {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.modal-head h3,
.overlay h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 20px;
}
.modal-sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  width: 100%;
}
.modal-actions.left {
  justify-content: flex-start;
}
.sel-count {
  margin-right: auto;
  color: var(--muted);
  font-size: 13px;
}
.sel-grid,
.resp-list,
.pile-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}
.sel-item {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
}
.sel-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.sel-item.on {
  border-color: var(--accent);
  background: rgba(242, 193, 78, 0.12);
}
.sel-item:focus-visible {
  outline: 2px solid var(--accent2);
}
.sel-loc {
  font-size: 11px;
  color: var(--muted);
}
/* a choice among both duelists' cards: your opponent's cards above yours, as on the board */
.sel-groups {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.sel-group {
  --side: var(--accent2);
  border: 1px solid color-mix(in srgb, var(--side) 40%, transparent);
  border-radius: 14px;
  padding: 8px 10px 10px;
  background: color-mix(in srgb, var(--side) 6%, transparent);
}
.sel-group.theirs {
  --side: var(--danger);
}
.sel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--side);
}
.sel-head::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--side);
  box-shadow: 0 0 8px var(--side);
}
.sel-group .sel-grid {
  margin-top: 6px;
}
/* a choice among cards on the field: rows of seven zones in the board's order (duel-ui.js boardChoice) */
.sel-board {
  --ms: clamp(36px, calc((min(100vw, 900px) - 150px) / 7), 96px);
  display: grid;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}
.sel-row {
  display: grid;
  grid-template-columns: repeat(7, var(--ms));
  gap: 6px;
}
.sel-slot {
  position: relative;
  width: var(--ms);
  height: var(--ms);
  display: grid;
  place-items: center;
  border-radius: calc(var(--ms) * 0.1);
  border: 1px dashed rgba(170, 180, 255, 0.16);
  background: rgba(255, 255, 255, 0.025);
}
.sel-slot > span {
  font-size: max(9px, calc(var(--ms) * 0.13));
  color: rgba(200, 205, 255, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sel-slot.ctx {
  border-style: solid;
  border-color: rgba(170, 180, 255, 0.07);
}
.sel-slot.ctx .card {
  opacity: 0.35;
  filter: grayscale(0.6);
}
.sel-item.sel-slot {
  width: var(--ms);
  height: var(--ms);
  padding: 0;
  display: grid;
  place-items: center;
  border: 2px solid rgba(242, 193, 78, 0.5);
  border-radius: calc(var(--ms) * 0.1);
  background: rgba(242, 193, 78, 0.08);
}
.sel-item.sel-slot:hover {
  background: rgba(242, 193, 78, 0.16);
}
.sel-item.sel-slot.on {
  border-color: var(--accent);
  background: rgba(242, 193, 78, 0.22);
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(242, 193, 78, 0.5);
}
.card.sel {
  --ch: calc(var(--ms) * 0.94);
  --cw: calc(var(--ch) * 0.69);
  font-size: calc(var(--cw) * 0.118);
}
.resp-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.modal-card {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.pos-choices {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pos-btn {
  all: unset;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid transparent;
}
.pos-btn:hover,
.pos-btn:focus-visible {
  border-color: var(--accent);
}
.pos-btn.def .card {
  transform: rotate(-90deg);
  margin: -34px 34px;
}
.option-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
/* choosing a single duel or a best-of-3 match against a rival */
.choice-modal { max-width: 420px; }
.choice-modal .btn.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 10px 14px;
}
.choice-modal .btn.choice small { opacity: 0.8; font-weight: 400; }
/* rock-paper-scissors before a duel */
.rps-modal { max-width: 460px; text-align: center; }
.rps-score { font-size: 1.15em; font-weight: 800; margin: 10px 0 4px; }
.rps-last { margin: 4px 0 8px; opacity: 0.9; }
.rps-picks { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.rps-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 104px;
  padding: 12px 10px;
}
.rps-icon { font-size: 2.4em; line-height: 1; }
.match-note { font-weight: 700; margin: 6px 0 10px; }
.sheet-log {
  max-height: 50vh;
  width: 100%;
}
.result {
  text-align: center;
}
.result h2 {
  font-family: var(--display);
  font-size: 42px;
  margin: 4px 0;
}
.result.win h2 { color: var(--accent); }
.result.lose h2 { color: var(--danger); }
.result p { color: var(--muted); }
.result h4 { margin: 18px 0 10px; }
.reward-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.reward {
  position: relative;
  animation: rewardIn 0.5s ease both;
  animation-delay: calc(var(--i) * 0.15s);
}
.new-badge {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #2a1d05;
  font-weight: 900;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
}

/* banner, effects */
.banner-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}
.banner-layer.show {
  opacity: 1;
}
.banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 26px;
  border-radius: 16px;
  background: rgba(9, 11, 26, 0.92);
  border: 1px solid rgba(242, 193, 78, 0.6);
  box-shadow: 0 0 50px rgba(242, 193, 78, 0.25);
  animation: bannerIn 0.35s ease;
  max-width: 90%;
}
.banner .card {
  --cw: 92px;
  --ch: 133px;
  font-size: 9px;
}
.banner-text {
  font-family: var(--display);
  font-size: clamp(20px, 3.2vw, 34px);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.banner.turn .banner-text { color: var(--accent); }
.banner.negate { border-color: var(--danger); }
.banner.negate .banner-text { color: var(--danger); }
.fx-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
  overflow: visible;
}
.atk-line {
  stroke: var(--danger);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 10 8;
  animation: dash 0.6s linear infinite;
  filter: drop-shadow(0 0 6px rgba(255, 93, 108, 0.8));
}
.atk-head {
  fill: var(--danger);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 30px);
  opacity: 0;
  background: #20264d;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* animations */
.card.anim-pulse { animation: pulse 0.7s ease; }
.card.anim-draw { animation: drawIn 0.35s ease both; }
.card.anim-glow { animation: glow 0.8s ease; }
.card.anim-hit { animation: hit 0.35s ease; }
.slot.anim-lunge { animation: lunge 0.6s cubic-bezier(0.3, 0.7, 0.4, 1); z-index: 5; }
.slot.anim-destroy > .card { animation: shatter 0.42s ease forwards; }
.slot.anim-bounce > .card { animation: bounceOut 0.42s ease forwards; }
.slot.anim-fade > .card { animation: fadeAway 0.42s ease forwards; }

/* every piece in one hand (Exodia, duel-ui.js showHandWin): the pieces make up the body and light up */
.exodia-show {
  --xw: 120px; /* card width, set from the window size */
  --xh: calc(var(--xw) * 1.45);
  position: absolute;
  inset: 0;
  z-index: 55;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(ellipse 60% 55% at 50% 45%, rgba(255, 190, 60, 0.24), rgba(5, 5, 16, 0.9) 70%);
  animation: xsIn 0.35s ease both;
}
.exodia-show.out {
  animation: xsOut 0.4s ease forwards;
}
.xs-rays {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 160vmax;
  height: 160vmax;
  margin: -80vmax 0 0 -80vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255, 214, 120, 0.18) 0 6deg, transparent 6deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, transparent 42%);
  mask-image: radial-gradient(circle, #000 0, transparent 42%);
  opacity: 0;
}
.exodia-show.united .xs-rays {
  animation: xsSpin 9s linear infinite, xsShow 0.7s ease forwards;
}
.xs-body {
  position: absolute;
  left: 50%;
  top: 45%;
}
.xs-body::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  border: 3px solid rgba(255, 222, 140, 0.95);
  box-shadow: 0 0 22px rgba(255, 200, 90, 0.9);
  opacity: 0;
}
.exodia-show.united .xs-body::after {
  animation: xsWave 1s ease-out forwards;
}
.xs-piece {
  position: absolute;
  left: calc(var(--xw) / -2);
  top: calc(var(--xh) / -2);
}
.xs-piece .card {
  --cw: var(--xw);
  --ch: var(--xh);
  font-size: calc(var(--xw) * 0.118);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}
.exodia-show.united .xs-piece .card {
  animation: xsGlow 1.1s ease-in-out infinite alternate;
}
.xs-text {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 7%;
  text-align: center;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.exodia-show.named .xs-text {
  opacity: 1;
  transform: none;
}
.xs-text b {
  display: block;
  font-family: var(--display);
  font-size: clamp(26px, 4vw, 48px);
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 26px rgba(242, 193, 78, 0.75), 0 3px 10px rgba(0, 0, 0, 0.85);
}
.xs-text span {
  display: block;
  margin-top: 6px;
  font-size: clamp(14px, 1.6vw, 19px);
  color: #f6e7c6;
  text-shadow: 0 2px 8px #000;
}
@keyframes xsIn { from { opacity: 0; } }
@keyframes xsOut { to { opacity: 0; } }
@keyframes xsShow { to { opacity: 1; } }
@keyframes xsSpin { to { rotate: 360deg; } }
@keyframes xsWave { 0% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: 40; } }
@keyframes xsGlow {
  from { box-shadow: 0 0 10px 2px rgba(255, 196, 70, 0.55); }
  to { box-shadow: 0 0 36px 12px rgba(255, 214, 110, 0.95); }
}

/* the opening deal (duel-ui.js dealOpening): the Deck is riffled, then each card flies into the hand */
.deal-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 18;
}
.deal-fly {
  position: absolute;
}
.deal-spin {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  will-change: transform;
}
.deal-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.deal-face.deal-back {
  transform: rotateY(180deg);
}
.deal-face > .card {
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.55), 0 0 18px rgba(242, 193, 78, 0.35);
}
.card.deal-wait { visibility: hidden; }
.card.anim-land { animation: dealLand 0.36s ease-out; }
.slot.z-deck > .card.anim-deal-pop { animation: deckPop 0.2s ease; }
.slot.pile > .card.deck-half {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: calc(var(--ch) / -2) 0 0 calc(var(--cw) / -2);
  z-index: 1;
  pointer-events: none;
  animation: riffle 0.56s ease-in-out both;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--el, #fff) 80%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent, 0 0 26px 6px color-mix(in srgb, var(--el, #fff) 50%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes drawIn { from { translate: 0 60%; opacity: 0; } to { translate: 0 0; opacity: 1; } }
@keyframes glow { 0%, 100% { filter: none; } 40% { filter: brightness(1.6) drop-shadow(0 0 10px var(--el)); } }
@keyframes hit { 0%, 100% { translate: 0 0; } 20% { translate: -5% 0; } 40% { translate: 5% 0; } 60% { translate: -3% 0; } 80% { translate: 2% 0; } }
@keyframes lunge { 0%, 100% { translate: 0 0; } 45% { translate: var(--dx) var(--dy); } }
@keyframes shatter { 0% { opacity: 1; scale: 1; } 30% { filter: brightness(2) saturate(0); } 100% { opacity: 0; scale: 0.6; rotate: 8deg; } }
@keyframes bounceOut { to { opacity: 0; translate: 0 -40%; } }
@keyframes fadeAway { to { opacity: 0; scale: 0.9; filter: grayscale(1); } }
@keyframes floatUp { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 -34px; } }
@keyframes hitFlash { 0%, 100% { box-shadow: none; } 30% { box-shadow: 0 0 0 2px var(--danger), 0 0 30px rgba(255, 93, 108, 0.5); } }
@keyframes targetPulse { 0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 93, 108, 0.45); } 50% { box-shadow: 0 0 26px 8px rgba(255, 93, 108, 0.75); } }
@keyframes dash { to { stroke-dashoffset: -36; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes bannerIn { from { transform: scale(0.85); opacity: 0; } }
@keyframes dealLand {
  0% { scale: 1.07; box-shadow: 0 0 0 2px rgba(255, 214, 120, 0.9), 0 0 26px 6px rgba(242, 193, 78, 0.55); }
  100% { scale: 1; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45); }
}
@keyframes deckPop { 50% { translate: 0 -7%; } }
@keyframes riffle {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  28%, 46% { translate: calc(var(--side) * 58%) -8%; rotate: calc(var(--side) * 11deg); }
  72% { translate: calc(var(--side) * -10%) -3%; rotate: calc(var(--side) * -3deg); }
}
@keyframes rewardIn { from { opacity: 0; transform: rotateY(90deg) scale(0.8); } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------------ replays (duel-ui.js startReplay, js/replays.js) */
/* the board leaves room for the bar under it */
.duel.replay {
  --slot: clamp(36px, min(calc((100vh - 236px) / 6.3), calc((100vw - var(--sidebar) - 44px) / 7.55)), 134px);
  --slot: clamp(36px, min(calc((100dvh - 236px) / 6.3), calc((100vw - var(--sidebar) - 44px) / 7.55)), 134px);
  grid-template-rows: minmax(0, 1fr) auto;
}
.duel.replay > .board-wrap,
.duel.replay > .sidebar {
  grid-row: 1;
  min-height: 0;
}
.replay-bar {
  --p: 0%;
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: rgba(10, 12, 30, 0.94);
  border-top: 1px solid var(--line);
}
.rb-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}
.rb-btn {
  all: unset;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  color: #dfe4ff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.rb-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}
.rb-btn:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}
.rb-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.rb-btn.rb-play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border-color: transparent;
  background: var(--accent);
  color: #1b1305;
}
.rb-btn.rb-play:hover {
  background: #ffd56b;
}
.rb-btn.rb-play svg {
  width: 22px;
  height: 22px;
}
/* the timeline: a marker where each turn starts (yours blue, your opponent's red) */
.rb-track {
  position: relative;
  flex: 1;
  min-width: 120px;
  height: 34px;
}
.rb-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}
.rb-fill {
  width: var(--p);
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
}
.rb-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.rb-tick {
  all: unset;
  position: absolute;
  top: 5px;
  width: 4px;
  height: 24px;
  margin-left: -2px;
  border-radius: 2px;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0.7;
  z-index: 2;
}
.rb-tick.me {
  background: var(--accent2);
}
.rb-tick.opp {
  background: var(--danger);
}
.rb-tick:hover,
.rb-tick:focus-visible {
  opacity: 1;
  transform: scaleX(1.7);
}
.rb-range {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  z-index: 1;
}
.rb-range::-webkit-slider-runnable-track {
  height: 34px;
  background: transparent;
}
.rb-range::-moz-range-track {
  height: 34px;
  background: transparent;
}
.rb-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: 9px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 10px rgba(242, 193, 78, 0.6);
}
.rb-range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}
.rb-range:focus-visible {
  outline: none;
}
.rb-range:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--accent2);
}
.rb-info {
  display: grid;
  flex: none;
  min-width: 96px;
  line-height: 1.25;
}
.rb-info b {
  font-size: 14px;
}
.rb-info span {
  font-size: 12px;
  color: var(--muted);
}
.rb-speed {
  flex: none;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #dfe4ff;
  font: inherit;
}
/* the list of replays */
.replays-screen .replay-list {
  display: grid;
  gap: 10px;
  max-width: 860px;
  margin: 0 auto;
}
.replays-screen .hint {
  max-width: 860px;
  margin: 0 auto 14px;
}
.replay-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-left: 4px solid var(--oc);
}
.replay-row .opp-avatar {
  width: 44px;
  height: 44px;
  font-size: 15px;
}
.rr-body {
  flex: 1;
  min-width: 0;
}
.rr-body b {
  font-size: 16px;
  margin-right: 8px;
}
.rr-result {
  font-size: 12px;
  font-weight: 800;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.rr-result.win {
  background: rgba(79, 209, 139, 0.16);
  color: var(--good);
}
.rr-result.lose {
  background: rgba(255, 93, 108, 0.15);
  color: #ff8a96;
}
.rr-result.draw {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}
.rr-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.rr-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

/* ------------------------------------------------------------------ responsive */
@media (max-width: 700px) {
  .replay-bar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 8px 10px;
  }
  .replay-bar .rb-track {
    order: -1;
    flex-basis: 100%;
  }
  .duel.replay {
    --slot: clamp(36px, min(calc((100dvh - 280px) / 6.3), calc((100vw - var(--sidebar) - 44px) / 7.55)), 134px);
  }
  .replay-row {
    flex-wrap: wrap;
  }
  .rr-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
@media (max-width: 1100px) {
  .duel {
    --sidebar: 0px;
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    display: none;
  }
  .only-narrow {
    display: inline-flex;
  }
}
@media (max-width: 900px) {
  .deck-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .deck-panel {
    position: static;
    max-height: none;
    order: -1;
  }
  .deck-detail {
    display: none;
  }
  .deck-list {
    max-height: 260px;
  }
}
@media (max-width: 640px) {
  .screen {
    padding: 14px 16px;
  }
  .board {
    padding: 6px;
  }
  .board-wrap {
    padding: 4px;
  }
  .counts,
  .turn-info,
  .ptitle {
    display: none;
  }
  .lp {
    font-size: 17px;
    min-width: 64px;
  }
  .avatar {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }
  .pbar {
    min-height: 40px;
    gap: 8px;
  }
  .chip {
    padding: 3px 4px;
    font-size: 10px;
  }
  .phase-btns {
    min-width: 0;
  }
  .phase-btns .btn {
    padding: 6px 9px;
    font-size: 12px;
  }
  .card.md {
    --cw: 124px;
    --ch: 180px;
    font-size: 11px;
  }
  .coll-grid {
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  }
  .card.sm {
    --cw: 104px;
    --ch: 151px;
    font-size: 10px;
  }
}

/* ------------------------------------------------------------------ accounts & online play */
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.boot-screen {
  display: grid;
  place-items: center;
}
.account-bar {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 6px 14px;
  margin-bottom: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.account-bar b {
  color: var(--text);
}
.offline-note {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 22px;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
}
.auth-wrap {
  display: grid;
  place-items: start center;
  padding-top: 4vh;
}
.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.auth-card .tabs {
  justify-content: center;
}
.auth-field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.auth-field input {
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.auth-field input:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}
.auth-card .btn.big {
  min-width: 0;
  width: 100%;
}
.small-print {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}
.me-chip {
  align-self: center;
  font-size: 14px;
  color: var(--muted);
}
.me-chip b {
  color: var(--accent);
}
.online-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  min-width: 0;
}
.panel h3 {
  font-family: var(--display);
  color: var(--accent);
  margin: 0 0 8px;
  font-size: 17px;
}
.panel h3 + .muted {
  margin-top: 0;
}
.panel h3:not(:first-child) {
  margin-top: 18px;
}
.panel .count {
  color: var(--muted);
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 400;
}
.panel .btn.big {
  min-width: 0;
  width: 100%;
}
.btn.searching {
  background: linear-gradient(180deg, #2a3163, #222852);
  color: var(--text);
  border-color: var(--accent);
  animation: searching 1.6s ease-in-out infinite;
}
@keyframes searching {
  50% {
    box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.18);
  }
}
.player-list {
  display: grid;
  gap: 6px;
}
/* the lobby chat */
.chat-log {
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  font-size: 14px;
  line-height: 1.35;
}
.chat-log .muted {
  margin: auto 0;
  text-align: center;
}
.chat-line {
  position: relative;
  padding: 2px 22px 2px 6px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.chat-line.me {
  background: rgba(126, 166, 255, 0.1);
}
.chat-time {
  margin-right: 6px;
  font-size: 11px;
  color: var(--muted);
}
.chat-name {
  margin-right: 6px;
}
.chat-del {
  all: unset;
  position: absolute;
  top: 1px;
  right: 4px;
  padding: 0 4px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
}
.chat-line:hover .chat-del,
.chat-del:focus-visible {
  opacity: 1;
}
.chat-del:hover {
  color: var(--danger);
}
.chat-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.chat-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  font: inherit;
}
.chat-input:focus {
  outline: 2px solid var(--accent2);
  outline-offset: -1px;
}
.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: 'name rating btn' 'status status btn';
  align-items: center;
  gap: 2px 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.pr-name {
  grid-area: name;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pr-rating {
  grid-area: rating;
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}
.player-row .status-chip {
  grid-area: status;
}
.player-row .btn {
  grid-area: btn;
}
.status-chip {
  font-size: 12px;
  color: var(--muted);
}
.status-chip.s-queue {
  color: var(--accent2);
}
.status-chip.s-duel {
  color: #ffb3c4;
}
.invite-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  font-size: 14px;
}
.invite-card.out {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}
.ic-actions {
  display: flex;
  gap: 6px;
}
.leaderboard {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 4px;
  font-size: 14px;
}
.leaderboard li {
  padding: 3px 0;
}
.leaderboard li.muted {
  list-style: none;
  margin-left: -22px;
}
.leaderboard li > span {
  display: inline-block;
  min-width: 46%;
}
.leaderboard li b {
  color: var(--accent);
  margin-right: 8px;
}
.leaderboard li small {
  color: var(--muted);
}
.leaderboard li.me > span {
  color: var(--accent2);
  font-weight: 700;
}
.history {
  display: grid;
  gap: 4px;
  font-size: 14px;
}
.history-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 4px 0;
}
.history-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-row.r-win b,
.rating-change.up b {
  color: var(--good);
}
.history-row.r-loss b,
.rating-change.down b {
  color: var(--danger);
}
.history-row small {
  color: var(--muted);
}
.rating-change {
  font-size: 16px;
  margin: 4px 0 0;
}
.opp-avatar img,
.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.opp-avatar:has(img),
.avatar:has(img) {
  overflow: hidden;
}
@media (max-width: 1000px) {
  .online-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .online-layout .panel:first-child {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .online-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .account-bar {
    font-size: 13px;
  }
}

/* ------------------------------------------------------------------ cards shown as one full picture */
.card.face.full {
  padding: 0;
  border: none;
  background: #05060d;
  border-radius: calc(var(--cw) * 0.045);
}
.c-full {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
  user-select: none;
  -webkit-user-drag: none;
}
.card.full .c-live {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 3%;
  display: flex;
  justify-content: center;
  gap: 0.35em;
  padding: 0.1em 0.3em;
  border-radius: 0.4em;
  background: rgba(6, 8, 20, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 800;
  font-size: 0.9em;
  line-height: 1.3;
  color: #fff;
}
.card.full:not(.onboard) .c-live {
  justify-content: space-between;
  font-size: 0.8em;
  padding: 0.25em 0.6em;
}

/* deck builder: cards you don't own yet */
.coll-item.unowned .card {
  filter: grayscale(0.85) brightness(0.6);
}
.coll-item .notown {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a2f55;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ narrator settings */
.voice-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}
.voice-select,
.lang-select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 8px;
  max-width: 100%;
}
.lang-select {
  font-size: 15px;
  min-width: 200px;
}

/* a resolved Spell/Trap waiting for the End Phase */
.card.lingering::after {
  content: 'This turn';
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  padding: 0.12em 0.5em;
  border-radius: 999px;
  font-size: calc(var(--cw) * 0.12);
  line-height: 1.2;
  pointer-events: none;
  font-weight: 800;
  white-space: nowrap;
  color: #2b1d04;
  background: rgba(242, 193, 78, 0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

/* a resolved Spell/Trap that stays on the field for some turns: how many are left */
.card .c-badge {
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  padding: 0.12em 0.5em;
  border-radius: 999px;
  font-size: calc(var(--cw) * 0.12);
  line-height: 1.2;
  pointer-events: none;
  font-weight: 800;
  white-space: nowrap;
  color: #04202b;
  background: rgba(124, 214, 242, 0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

/* card sets: deck cards whose set isn't in play */
.deck-row.off { opacity: 0.7; }
.deck-row.off .dr-name { text-decoration: line-through; text-decoration-color: rgba(255, 93, 108, 0.7); }
.deck-row.off .dr-meta { color: var(--danger); }
.notice-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; width: 100%; }

/* a card whose design is still being drawn (a moment after the cards load) */
.card.face.full.pending {
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #262b4f, #12152b);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 3px 8px rgba(0, 0, 0, 0.45);
}
.c-pending {
  padding: 0 8%;
  text-align: center;
  font-weight: 700;
  font-size: 0.9em;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.72);
  overflow-wrap: anywhere;
}
/* a card's details beside its picture */
.card-info {
  display: grid;
  gap: 4px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}
.card-info b {
  font-family: var(--display);
  font-size: 15px;
}
.card-info .ci-type,
.card-info .ci-stats {
  color: var(--muted);
  font-size: 12px;
}
.card-info p {
  margin: 2px 0;
  white-space: pre-line;
}

/* ------------------------------------------------------------------ 3D duel arena (Settings → Duel view) */
/* In 2D the field wrapper takes no space of its own; in 3D the whole field tilts like a table. */
.field {
  display: contents;
}
.duel.view-3d .board-wrap {
  background:
    radial-gradient(ellipse 55% 35% at 50% 6%, rgba(120, 140, 255, 0.2), transparent 70%),
    radial-gradient(ellipse 75% 45% at 50% 100%, rgba(242, 160, 78, 0.18), transparent 70%),
    radial-gradient(ellipse 40% 60% at 0% 50%, rgba(242, 120, 60, 0.08), transparent 70%),
    radial-gradient(ellipse 40% 60% at 100% 50%, rgba(242, 120, 60, 0.08), transparent 70%),
    linear-gradient(180deg, #06071a 0%, #13113a 45%, #0c0a20 100%);
}
.duel.view-3d .board {
  background: none;
  border-color: transparent;
  perspective: 1500px;
  perspective-origin: 50% 20%;
}
.duel.view-3d .field {
  display: grid;
  gap: 4px;
  padding: calc(var(--slot) * 0.14) calc(var(--slot) * 0.22);
  border-radius: 24px;
  transform: translateZ(-40px) rotateX(24deg);
  transform-origin: 50% 55%;
  transform-style: preserve-3d;
  background:
    radial-gradient(ellipse 65% 55% at 50% 50%, rgba(255, 210, 140, 0.11), transparent 75%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px calc(var(--slot) + var(--gap))),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px calc(var(--slot) + var(--gap))),
    linear-gradient(180deg, #1a1834, #29254d 50%, #1a1834);
  border: 2px solid rgba(242, 193, 78, 0.38);
  box-shadow:
    0 0 0 7px rgba(18, 16, 38, 0.92),
    0 0 0 8px rgba(242, 193, 78, 0.22),
    0 34px 70px rgba(0, 0, 0, 0.65),
    inset 0 0 50px rgba(0, 0, 0, 0.5);
}
.duel.view-3d .side,
.duel.view-3d .row,
.duel.view-3d .slot {
  transform-style: preserve-3d;
}
.duel.view-3d .slot {
  background: rgba(8, 8, 22, 0.5);
  border: 1px solid rgba(242, 193, 78, 0.22);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.65);
}
.duel.view-3d .slot.z-field {
  background: rgba(40, 140, 110, 0.14);
}
/* cards stand off the table, cast a shadow, and rise when you point at them */
.duel.view-3d .slot > .card {
  --lift: 7px;
  transform: translateZ(var(--lift));
  filter: drop-shadow(0 calc(var(--slot) * 0.08) calc(var(--slot) * 0.06) rgba(0, 0, 0, 0.6));
  transition: transform 0.18s ease;
}
.duel.view-3d .slot > .card.pos-def {
  transform: translateZ(var(--lift)) rotate(-90deg);
}
.duel.view-3d .slot:hover > .card,
.duel.view-3d .slot > .card.can-act:hover {
  --lift: 26px;
}
/* the middle bar (phases, Battle, End Turn) stands up from the table like a sign, facing you */
.duel.view-3d .midline {
  transform: translateZ(2px) rotateX(-24deg);
  transform-origin: 50% 100%;
}
.duel.view-3d .my-hand .card {
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.55));
}
@media (prefers-reduced-motion: reduce) {
  .duel.view-3d .slot > .card {
    transition: none;
  }
}
