:root {
  --ink: #0c100e;
  --felt: #141c16;
  --bone: #e8dfc8;
  --bone-dim: rgba(232, 223, 200, 0.55);
  --blood: #9a2f24;
  --blood-hot: #c44738;
  --moss: #3d5c45;
  --gold: #c4a46a;
  --line: rgba(232, 223, 200, 0.14);
  --card-face: #f3ead4;
  --card-ink: #1a1814;
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --W: #e8e0c8;
  --U: #6a8aaa;
  --B: #5a4a62;
  --R: #b04a38;
  --G: #4a7a52;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--bone);
  font-family: var(--font-body);
  background: var(--ink);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(196, 164, 106, 0.16), transparent 55%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(154, 47, 36, 0.18), transparent 50%),
    radial-gradient(ellipse 45% 35% at 90% 70%, rgba(61, 92, 69, 0.22), transparent 50%),
    linear-gradient(165deg, #0a0e0b 0%, #152019 45%, #0c100e 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.55);
  backdrop-filter: blur(8px);
}

.back, .ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--bone-dim);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

.brand {
  font-family: var(--font-display);
  letter-spacing: 0.28em;
  font-size: 0.85rem;
  color: var(--gold);
}

.top-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.screen {
  padding: clamp(1rem, 3vw, 2rem);
  animation: rise 0.55s ease both;
}

.screen[hidden] { display: none !important; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.menu-hero, .end-block {
  max-width: 36rem;
  margin: clamp(1.5rem, 8vh, 4rem) auto;
  text-align: center;
}

#screen-end {
  position: relative;
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.end-stage {
  position: relative;
  width: min(100%, 52rem);
  margin: 0 auto;
}

.end-art {
  position: absolute;
  inset: -8% -6% auto;
  height: min(52vh, 28rem);
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  z-index: 0;
  animation: endArtIn 0.7s ease both;
}

.end-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.04);
  filter: saturate(1.05) contrast(1.05);
}

.end-art-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 12, 10, 0.15) 0%, rgba(8, 12, 10, 0.55) 55%, rgba(8, 12, 10, 0.92) 100%),
    radial-gradient(ellipse 70% 50% at 50% 20%, transparent 30%, rgba(8, 12, 10, 0.35) 100%);
  pointer-events: none;
}

#end-stage[data-outcome="win"] .end-art {
  border-color: rgba(196, 164, 106, 0.45);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(196, 164, 106, 0.18);
}

#end-stage[data-outcome="lose"] .end-art {
  border-color: rgba(154, 47, 36, 0.5);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(154, 47, 36, 0.2);
}

#end-stage[data-outcome="lose"] .end-art img {
  filter: saturate(0.85) contrast(1.08) brightness(0.88);
}

#screen-end .end-block {
  position: relative;
  z-index: 1;
  margin-top: min(38vh, 20rem);
  padding: 1.25rem 1rem 0.5rem;
  max-width: 36rem;
}

#end-stage[data-outcome="win"] #end-title {
  color: var(--gold);
  text-shadow: 0 0 48px rgba(196, 164, 106, 0.35);
}

#end-stage[data-outcome="lose"] #end-title {
  color: #e8b0a4;
  text-shadow: 0 0 40px rgba(154, 47, 36, 0.4);
}

@keyframes endArtIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .end-art {
    inset: -4% -2% auto;
    height: min(40vh, 16rem);
    border-radius: 14px;
  }
  #screen-end .end-block {
    margin-top: min(32vh, 14rem);
  }
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold);
}

.menu-hero h1, .end-block h1 {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 12vw, 5.8rem);
  line-height: 0.92;
  letter-spacing: 0.06em;
  color: var(--bone);
  text-shadow: 0 0 48px rgba(196, 164, 106, 0.22);
}

.lead {
  margin: 0 auto 1.5rem;
  max-width: 34ch;
  color: var(--bone-dim);
  line-height: 1.5;
  font-size: 1.1rem;
}

.deck-select {
  margin: 0 auto 1.25rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 12, 10, 0.55);
  text-align: left;
  max-width: 36rem;
}

.deck-select legend {
  padding: 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 18rem;
  overflow: auto;
  padding-right: 0.15rem;
}

.deck-btn.theme-vampire[aria-selected="true"] {
  border-color: rgba(160, 40, 70, 0.85);
  background: linear-gradient(160deg, rgba(50, 10, 20, 0.95), rgba(18, 8, 12, 0.95));
}

.deck-btn.theme-loup[aria-selected="true"] {
  border-color: rgba(120, 150, 70, 0.85);
  background: linear-gradient(160deg, rgba(28, 36, 14, 0.95), rgba(12, 16, 8, 0.95));
}

.deck-btn.theme-mage[aria-selected="true"] {
  border-color: rgba(90, 140, 200, 0.85);
  background: linear-gradient(160deg, rgba(16, 28, 50, 0.95), rgba(10, 14, 24, 0.95));
}

.deck-btn {
  appearance: none;
  border: 1px solid rgba(232, 223, 200, 0.16);
  border-radius: 10px;
  background: rgba(12, 18, 14, 0.85);
  color: var(--bone-dim);
  font: inherit;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 0.2rem;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.deck-btn:hover {
  border-color: rgba(232, 223, 200, 0.4);
  transform: translateY(-1px);
}

.deck-btn[aria-selected="true"] {
  border-color: rgba(196, 71, 56, 0.75);
  background: rgba(40, 16, 14, 0.85);
  color: var(--bone);
}

.deck-btn .dk-tag {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(196, 164, 106, 0.7);
}

.deck-btn .dk-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: inherit;
}

.deck-btn .dk-colors {
  font-size: 0.78rem;
  opacity: 0.75;
}

.deck-btn.theme-dbz[aria-selected="true"] {
  border-color: rgba(255, 180, 40, 0.85);
  background: linear-gradient(160deg, rgba(60, 30, 10, 0.9), rgba(20, 12, 8, 0.92));
  box-shadow: inset 0 0 0 1px rgba(255, 160, 40, 0.2);
}

.deck-btn.theme-goldorak[aria-selected="true"] {
  border-color: rgba(220, 170, 40, 0.9);
  background: linear-gradient(160deg, rgba(70, 18, 12, 0.95), rgba(12, 28, 14, 0.95));
  box-shadow: inset 0 0 0 1px rgba(40, 160, 70, 0.25);
}

.deck-btn.theme-seiya[aria-selected="true"] {
  border-color: rgba(212, 175, 80, 0.95);
  background: linear-gradient(160deg, rgba(36, 28, 70, 0.95), rgba(18, 12, 28, 0.95));
  box-shadow: inset 0 0 0 1px rgba(180, 140, 255, 0.22);
}

.deck-btn.theme-pokemon[aria-selected="true"] {
  border-color: rgba(255, 203, 5, 0.95);
  background: linear-gradient(160deg, rgba(40, 80, 170, 0.95), rgba(16, 28, 64, 0.95));
  box-shadow: inset 0 0 0 1px rgba(255, 203, 5, 0.28);
}

.deck-btn.theme-custom[aria-selected="true"] {
  border-color: rgba(196, 164, 106, 0.9);
  background: linear-gradient(160deg, rgba(40, 32, 18, 0.95), rgba(14, 12, 8, 0.95));
}

/* ——— Deck builder ——— */
.builder-screen {
  padding: clamp(0.75rem, 2vw, 1.25rem);
  max-width: 1200px;
  margin: 0 auto;
}

.builder {
  display: grid;
  gap: 0.75rem;
}

.builder-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.builder-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  letter-spacing: 0.05em;
}

.builder-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.5rem;
}

.builder-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.builder-field input,
.builder-field select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 14, 12, 0.9);
  color: var(--bone);
  font: inherit;
  font-size: 0.92rem;
  letter-spacing: 0;
  text-transform: none;
  padding: 0.5rem 0.6rem;
}

.builder-stats {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.builder-stats.ok { color: #8fbf8a; }
.builder-stats.bad { color: var(--blood-hot); }

.builder-panels {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 0.75rem;
  min-height: 50vh;
}

.builder-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 12, 10, 0.65);
  padding: 0.65rem;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.5rem;
  min-height: 0;
}

.builder-panel h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.builder-grid {
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr));
  gap: 0.45rem;
  align-content: start;
  max-height: min(58vh, 32rem);
  padding: 0.15rem;
}

.builder-deck-list {
  overflow: auto;
  display: grid;
  gap: 0.35rem;
  align-content: start;
  max-height: min(58vh, 32rem);
}

.builder-row {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 0.45rem;
  align-items: center;
  border: 1px solid rgba(232, 223, 200, 0.12);
  border-radius: 10px;
  padding: 0.3rem;
  background: rgba(0, 0, 0, 0.22);
}

.builder-row img {
  width: 3.2rem;
  height: 2.15rem;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.35);
}

.builder-row .br-meta {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.builder-row .br-name {
  font-family: var(--font-display);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.builder-row .br-sub {
  font-size: 0.72rem;
  color: var(--bone-dim);
}

.builder-row .br-ops {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.builder-row .br-ops button,
.builder-card-ops button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(20, 24, 20, 0.9);
  color: var(--bone);
  border-radius: 6px;
  width: 1.7rem;
  height: 1.7rem;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.builder-row .br-ops button:hover,
.builder-card-ops button:hover {
  border-color: var(--gold);
}

.builder-card-wrap {
  position: relative;
}

.builder-card-wrap .card {
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 7;
  pointer-events: none;
}

.builder-card-ops {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  z-index: 3;
}

.builder-card-ops .qty {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--bone);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  line-height: 1.7rem;
}

.builder-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

.builder-hint {
  margin: 0;
  color: var(--bone-dim);
  font-size: 0.9rem;
}

.builder-foot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

@media (max-width: 860px) {
  .builder-panels { grid-template-columns: 1fr; }
  .builder-grid,
  .builder-deck-list { max-height: 40vh; }
}

/* Network lobby */
.net-hero { max-width: 28rem; }
.net-field { text-align: left; margin: 0 auto 1rem; max-width: 20rem; }
.net-actions {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.net-join {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}
.net-code-input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 14, 12, 0.9);
  color: var(--bone);
  font: inherit;
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  padding: 0.65rem;
}
.net-lobby {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: rgba(8, 12, 10, 0.55);
  margin-bottom: 1rem;
  text-align: left;
}
.net-code-display {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}
.net-code-display strong {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  color: var(--gold);
  font-size: 1.4rem;
}
.net-status { margin: 0 0 0.75rem; color: var(--bone-dim); }
#net-error { color: var(--blood-hot); min-height: 1.2em; }

.deck-blurb {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--bone-dim);
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.75rem;
}

@media (max-width: 520px) {
  .deck-grid { grid-template-columns: 1fr; }
}

.btn, .ghost-btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.4rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn {
  background: linear-gradient(180deg, var(--blood-hot), var(--blood));
  color: var(--bone);
  box-shadow: 0 10px 28px rgba(154, 47, 36, 0.35);
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--bone-dim);
}

.rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
  text-align: left;
  color: var(--bone-dim);
  font-size: 0.95rem;
}

.rules li {
  padding: 0.55rem 0.75rem;
  border-left: 2px solid rgba(154, 47, 36, 0.7);
  background: rgba(0, 0, 0, 0.2);
}

/* ——— Board ——— */
.duel {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 0.65rem;
}

.seat {
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(196, 164, 106, 0.06), transparent 55%),
    rgba(12, 18, 14, 0.72);
  padding: 0.7rem;
}

.seat-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0.25rem 0.35rem;
}

.seat-name {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  color: var(--gold);
}

.life {
  font-family: var(--font-display);
  font-size: 1.85rem;
  color: var(--bone);
  min-width: 2ch;
  text-align: right;
}

.life.hurt { color: var(--blood-hot); animation: pulse 0.35s ease; }

@keyframes pulse {
  from { transform: scale(1.15); }
  to { transform: scale(1); }
}

.zone-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin: 0.35rem;
}

.pile {
  min-width: 3.4rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 0.1rem;
  text-align: center;
}

.pile span {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.pile b {
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.mana {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 1.6rem;
  align-items: center;
}

.pip {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: grid;
  place-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #111;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.pip.W { background: var(--W); }
.pip.U { background: var(--U); color: #fff; }
.pip.B { background: var(--B); color: #fff; }
.pip.R { background: var(--R); color: #fff; }
.pip.G { background: var(--G); color: #fff; }
.pip.C { background: #9a9488; }

.battlefield {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 7.2rem;
  padding: 0.35rem;
  align-content: flex-start;
}

.mid {
  text-align: center;
  padding: 0.35rem 0.5rem 0.55rem;
}

.phase {
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.prompt {
  margin: 0 0 0.55rem;
  color: var(--bone-dim);
  font-size: 0.98rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.actions .btn {
  padding: 0.55rem 1rem;
  font-size: 0.92rem;
  box-shadow: none;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  min-height: 10.5rem;
  padding: 0.5rem 0.2rem 0.7rem;
}

/* Cards */
.card {
  --accent: #6a6258;
  --frame: #2c2418;
  width: 7.6rem;
  height: 10.6rem;
  border-radius: 10px;
  border: 2px solid var(--frame);
  background:
    linear-gradient(165deg, rgba(255, 248, 230, 0.95), rgba(236, 222, 190, 0.98) 40%, #e2d2b0);
  color: var(--card-ink);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 10px 22px rgba(0, 0, 0, 0.4);
  padding: 0.32rem;
  display: grid;
  grid-template-rows: auto minmax(3.8rem, 1.4fr) auto minmax(0, 1.45rem);
  gap: 0.18rem;
  cursor: default;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, outline 0.15s ease;
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: left;
  user-select: none;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(196, 164, 106, 0.35);
}

.card.tiny {
  width: 6.4rem;
  height: 9rem;
  font-size: 0.6rem;
}

.card.playable {
  cursor: pointer;
  outline: 2px solid rgba(196, 164, 106, 0.75);
  outline-offset: 2px;
}

.card.playable:hover,
.card.selectable:hover {
  transform: translateY(-7px) scale(1.03);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.card.selectable { cursor: pointer; }
.card.selected {
  outline: 2px solid var(--blood-hot);
  outline-offset: 2px;
  transform: translateY(-9px);
}

.card.tapped {
  transform: rotate(12deg);
  opacity: 0.88;
}

.card.attacking {
  outline: 2px solid var(--blood-hot);
  outline-offset: 2px;
  transform: translateY(-10px);
}

.card.blocking {
  outline: 2px solid var(--U);
  outline-offset: 2px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.2rem;
  align-items: flex-start;
  padding: 0.05rem 0.05rem 0;
  position: relative;
  z-index: 1;
}

.card-name {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.card-cost {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.card-cost .pip {
  width: 0.95rem;
  height: 0.95rem;
  font-size: 0.55rem;
}

.card-art {
  border-radius: 6px;
  border: 1px solid rgba(40, 30, 18, 0.5);
  background: #0a0806;
  min-height: 0;
  overflow: hidden;
  position: relative;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 2px 8px rgba(0, 0, 0, 0.25);
}

.card-art::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 28%, transparent 70%, rgba(0, 0, 0, 0.28));
}

.card-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  image-rendering: auto;
}

.card-type {
  font-size: 0.55rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(26, 24, 20, 0.7);
  border-top: 1px solid rgba(26, 24, 20, 0.14);
  border-bottom: 1px solid rgba(26, 24, 20, 0.14);
  padding: 0.1rem 0;
  background: linear-gradient(90deg, transparent, rgba(196, 164, 106, 0.12), transparent);
}

.card-text {
  font-size: 0.58rem;
  color: rgba(26, 24, 20, 0.86);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  padding-right: 1.6rem;
}

.card.tiny .card-text {
  -webkit-line-clamp: 2;
  font-size: 0.52rem;
}

.card-pt {
  position: absolute;
  right: 0.28rem;
  bottom: 0.28rem;
  background: linear-gradient(180deg, #2a2218, #14100c);
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 0.78rem;
  padding: 0.12rem 0.4rem;
  border-radius: 5px;
  min-width: 2.3rem;
  text-align: center;
  border: 1px solid rgba(196, 164, 106, 0.45);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

.card[data-color="W"] { --accent: #8a8068; --frame: #6a5a38; }
.card[data-color="U"] { --accent: #3a5a72; --frame: #2a4058; }
.card[data-color="B"] { --accent: #3a2a42; --frame: #2a1a32; }
.card[data-color="R"] { --accent: #6a2820; --frame: #5a2018; }
.card[data-color="G"] { --accent: #2a4a32; --frame: #1a3824; }
.card[data-color="C"] { --accent: #4a4840; --frame: #3a3830; }
.card[data-color="M"] { --accent: #5a4030; --frame: #4a3020; }

/* Rules dialog */
.rules-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: #121814;
  color: var(--bone);
  width: min(36rem, calc(100vw - 1.5rem));
  max-height: min(85vh, 40rem);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.rules-dialog::backdrop {
  background: rgba(4, 8, 6, 0.72);
  backdrop-filter: blur(4px);
}

.rules-sheet {
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: min(85vh, 40rem);
}

.rules-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.75rem;
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--line);
  align-items: start;
}

.rules-head .eyebrow { grid-column: 1; }
.rules-head h2 {
  margin: 0;
  grid-column: 1;
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.06em;
  color: var(--bone);
}

.rules-head .ghost {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
}

.rules-body {
  overflow: auto;
  padding: 0.85rem 1.15rem 1rem;
  display: grid;
  gap: 0.95rem;
  text-align: left;
}

.rules-body h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.rules-body p,
.rules-body li {
  margin: 0;
  color: var(--bone-dim);
  line-height: 1.5;
  font-size: 0.95rem;
}

.rules-body ul,
.rules-body ol {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.rules-body strong { color: var(--bone); }

.rules-foot {
  padding: 0.75rem 1.1rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.log-panel {
  position: fixed;
  right: 0.75rem;
  bottom: 0.75rem;
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: 40vh;
  overflow: auto;
  background: rgba(8, 12, 10, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  z-index: 20;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.log-panel[hidden] { display: none !important; }

.log-panel h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  color: var(--gold);
}

#log-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--bone-dim);
  font-size: 0.82rem;
  display: grid;
  gap: 0.3rem;
}

@media (max-width: 720px) {
  .card {
    width: 5.8rem;
    height: 8.2rem;
    font-size: 0.58rem;
  }
  .card.tiny {
    width: 5.2rem;
    height: 7.3rem;
  }
  .card-name { font-size: 0.6rem; }
  .life { font-size: 1.5rem; }
  .battlefield { min-height: 5.5rem; }
}
:root {
  --ink: #0c100e;
  --felt: #141c16;
  --bone: #e8dfc8;
  --bone-dim: rgba(232, 223, 200, 0.55);
  --blood: #9a2f24;
  --blood-hot: #c44738;
  --moss: #3d5c45;
  --gold: #c4a46a;
  --line: rgba(232, 223, 200, 0.14);
  --card-face: #f3ead4;
  --card-ink: #1a1814;
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --W: #e8e0c8;
  --U: #6a8aaa;
  --B: #5a4a62;
  --R: #b04a38;
  --G: #4a7a52;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--bone);
  font-family: var(--font-body);
  background: var(--ink);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(196, 164, 106, 0.16), transparent 55%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(154, 47, 36, 0.18), transparent 50%),
    radial-gradient(ellipse 45% 35% at 90% 70%, rgba(61, 92, 69, 0.22), transparent 50%),
    linear-gradient(165deg, #0a0e0b 0%, #152019 45%, #0c100e 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.55);
  backdrop-filter: blur(8px);
}

.back, .ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--bone-dim);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

.brand {
  font-family: var(--font-display);
  letter-spacing: 0.28em;
  font-size: 0.85rem;
  color: var(--gold);
}

.top-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.screen {
  padding: clamp(1rem, 3vw, 2rem);
  animation: rise 0.55s ease both;
}

.screen[hidden] { display: none !important; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.menu-hero, .end-block {
  max-width: 36rem;
  margin: clamp(1.5rem, 8vh, 4rem) auto;
  text-align: center;
}

#screen-end {
  position: relative;
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.end-stage {
  position: relative;
  width: min(100%, 52rem);
  margin: 0 auto;
}

.end-art {
  position: absolute;
  inset: -8% -6% auto;
  height: min(52vh, 28rem);
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  z-index: 0;
  animation: endArtIn 0.7s ease both;
}

.end-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.04);
  filter: saturate(1.05) contrast(1.05);
}

.end-art-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 12, 10, 0.15) 0%, rgba(8, 12, 10, 0.55) 55%, rgba(8, 12, 10, 0.92) 100%),
    radial-gradient(ellipse 70% 50% at 50% 20%, transparent 30%, rgba(8, 12, 10, 0.35) 100%);
  pointer-events: none;
}

#end-stage[data-outcome="win"] .end-art {
  border-color: rgba(196, 164, 106, 0.45);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(196, 164, 106, 0.18);
}

#end-stage[data-outcome="lose"] .end-art {
  border-color: rgba(154, 47, 36, 0.5);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(154, 47, 36, 0.2);
}

#end-stage[data-outcome="lose"] .end-art img {
  filter: saturate(0.85) contrast(1.08) brightness(0.88);
}

#screen-end .end-block {
  position: relative;
  z-index: 1;
  margin-top: min(38vh, 20rem);
  padding: 1.25rem 1rem 0.5rem;
  max-width: 36rem;
}

#end-stage[data-outcome="win"] #end-title {
  color: var(--gold);
  text-shadow: 0 0 48px rgba(196, 164, 106, 0.35);
}

#end-stage[data-outcome="lose"] #end-title {
  color: #e8b0a4;
  text-shadow: 0 0 40px rgba(154, 47, 36, 0.4);
}

@keyframes endArtIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .end-art {
    inset: -4% -2% auto;
    height: min(40vh, 16rem);
    border-radius: 14px;
  }
  #screen-end .end-block {
    margin-top: min(32vh, 14rem);
  }
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold);
}

.menu-hero h1, .end-block h1 {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 12vw, 5.8rem);
  line-height: 0.92;
  letter-spacing: 0.06em;
  color: var(--bone);
  text-shadow: 0 0 48px rgba(196, 164, 106, 0.22);
}

.lead {
  margin: 0 auto 1.5rem;
  max-width: 34ch;
  color: var(--bone-dim);
  line-height: 1.5;
  font-size: 1.1rem;
}

.deck-select {
  margin: 0 auto 1.25rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 12, 10, 0.55);
  text-align: left;
  max-width: 36rem;
}

.deck-select legend {
  padding: 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 18rem;
  overflow: auto;
  padding-right: 0.15rem;
}

.deck-btn.theme-vampire[aria-selected="true"] {
  border-color: rgba(160, 40, 70, 0.85);
  background: linear-gradient(160deg, rgba(50, 10, 20, 0.95), rgba(18, 8, 12, 0.95));
}

.deck-btn.theme-loup[aria-selected="true"] {
  border-color: rgba(120, 150, 70, 0.85);
  background: linear-gradient(160deg, rgba(28, 36, 14, 0.95), rgba(12, 16, 8, 0.95));
}

.deck-btn.theme-mage[aria-selected="true"] {
  border-color: rgba(90, 140, 200, 0.85);
  background: linear-gradient(160deg, rgba(16, 28, 50, 0.95), rgba(10, 14, 24, 0.95));
}

.deck-btn {
  appearance: none;
  border: 1px solid rgba(232, 223, 200, 0.16);
  border-radius: 10px;
  background: rgba(12, 18, 14, 0.85);
  color: var(--bone-dim);
  font: inherit;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 0.2rem;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.deck-btn:hover {
  border-color: rgba(232, 223, 200, 0.4);
  transform: translateY(-1px);
}

.deck-btn[aria-selected="true"] {
  border-color: rgba(196, 71, 56, 0.75);
  background: rgba(40, 16, 14, 0.85);
  color: var(--bone);
}

.deck-btn .dk-tag {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(196, 164, 106, 0.7);
}

.deck-btn .dk-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: inherit;
}

.deck-btn .dk-colors {
  font-size: 0.78rem;
  opacity: 0.75;
}

.deck-btn.theme-dbz[aria-selected="true"] {
  border-color: rgba(255, 180, 40, 0.85);
  background: linear-gradient(160deg, rgba(60, 30, 10, 0.9), rgba(20, 12, 8, 0.92));
  box-shadow: inset 0 0 0 1px rgba(255, 160, 40, 0.2);
}

.deck-btn.theme-goldorak[aria-selected="true"] {
  border-color: rgba(220, 170, 40, 0.9);
  background: linear-gradient(160deg, rgba(70, 18, 12, 0.95), rgba(12, 28, 14, 0.95));
  box-shadow: inset 0 0 0 1px rgba(40, 160, 70, 0.25);
}

.deck-btn.theme-seiya[aria-selected="true"] {
  border-color: rgba(212, 175, 80, 0.95);
  background: linear-gradient(160deg, rgba(36, 28, 70, 0.95), rgba(18, 12, 28, 0.95));
  box-shadow: inset 0 0 0 1px rgba(180, 140, 255, 0.22);
}

.deck-btn.theme-pokemon[aria-selected="true"] {
  border-color: rgba(255, 203, 5, 0.95);
  background: linear-gradient(160deg, rgba(40, 80, 170, 0.95), rgba(16, 28, 64, 0.95));
  box-shadow: inset 0 0 0 1px rgba(255, 203, 5, 0.28);
}

.deck-btn.theme-custom[aria-selected="true"] {
  border-color: rgba(196, 164, 106, 0.9);
  background: linear-gradient(160deg, rgba(40, 32, 18, 0.95), rgba(14, 12, 8, 0.95));
}

/* ——— Deck builder ——— */
.builder-screen {
  padding: clamp(0.75rem, 2vw, 1.25rem);
  max-width: 1200px;
  margin: 0 auto;
}

.builder {
  display: grid;
  gap: 0.75rem;
}

.builder-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.builder-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  letter-spacing: 0.05em;
}

.builder-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.5rem;
}

.builder-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.builder-field input,
.builder-field select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 14, 12, 0.9);
  color: var(--bone);
  font: inherit;
  font-size: 0.92rem;
  letter-spacing: 0;
  text-transform: none;
  padding: 0.5rem 0.6rem;
}

.builder-stats {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.builder-stats.ok { color: #8fbf8a; }
.builder-stats.bad { color: var(--blood-hot); }

.builder-panels {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 0.75rem;
  min-height: 50vh;
}

.builder-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 12, 10, 0.65);
  padding: 0.65rem;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.5rem;
  min-height: 0;
}

.builder-panel h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.builder-grid {
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr));
  gap: 0.45rem;
  align-content: start;
  max-height: min(58vh, 32rem);
  padding: 0.15rem;
}

.builder-deck-list {
  overflow: auto;
  display: grid;
  gap: 0.35rem;
  align-content: start;
  max-height: min(58vh, 32rem);
}

.builder-row {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 0.45rem;
  align-items: center;
  border: 1px solid rgba(232, 223, 200, 0.12);
  border-radius: 10px;
  padding: 0.3rem;
  background: rgba(0, 0, 0, 0.22);
}

.builder-row img {
  width: 3.2rem;
  height: 2.15rem;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.35);
}

.builder-row .br-meta {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.builder-row .br-name {
  font-family: var(--font-display);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.builder-row .br-sub {
  font-size: 0.72rem;
  color: var(--bone-dim);
}

.builder-row .br-ops {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.builder-row .br-ops button,
.builder-card-ops button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(20, 24, 20, 0.9);
  color: var(--bone);
  border-radius: 6px;
  width: 1.7rem;
  height: 1.7rem;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.builder-row .br-ops button:hover,
.builder-card-ops button:hover {
  border-color: var(--gold);
}

.builder-card-wrap {
  position: relative;
}

.builder-card-wrap .card {
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 7;
  pointer-events: none;
}

.builder-card-ops {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  z-index: 3;
}

.builder-card-ops .qty {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--bone);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  line-height: 1.7rem;
}

.builder-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

.builder-hint {
  margin: 0;
  color: var(--bone-dim);
  font-size: 0.9rem;
}

.builder-foot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

@media (max-width: 860px) {
  .builder-panels { grid-template-columns: 1fr; }
  .builder-grid,
  .builder-deck-list { max-height: 40vh; }
}

/* Network lobby */
.net-hero { max-width: 28rem; }
.net-field { text-align: left; margin: 0 auto 1rem; max-width: 20rem; }
.net-actions {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.net-join {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}
.net-code-input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 14, 12, 0.9);
  color: var(--bone);
  font: inherit;
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  padding: 0.65rem;
}
.net-lobby {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: rgba(8, 12, 10, 0.55);
  margin-bottom: 1rem;
  text-align: left;
}
.net-code-display {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}
.net-code-display strong {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  color: var(--gold);
  font-size: 1.4rem;
}
.net-status { margin: 0 0 0.75rem; color: var(--bone-dim); }
#net-error { color: var(--blood-hot); min-height: 1.2em; }

.deck-blurb {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--bone-dim);
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.75rem;
}

@media (max-width: 520px) {
  .deck-grid { grid-template-columns: 1fr; }
}

.btn, .ghost-btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.4rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn {
  background: linear-gradient(180deg, var(--blood-hot), var(--blood));
  color: var(--bone);
  box-shadow: 0 10px 28px rgba(154, 47, 36, 0.35);
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--bone-dim);
}

.rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
  text-align: left;
  color: var(--bone-dim);
  font-size: 0.95rem;
}

.rules li {
  padding: 0.55rem 0.75rem;
  border-left: 2px solid rgba(154, 47, 36, 0.7);
  background: rgba(0, 0, 0, 0.2);
}

/* ——— Board ——— */
.duel {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 0.65rem;
}

.seat {
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(196, 164, 106, 0.06), transparent 55%),
    rgba(12, 18, 14, 0.72);
  padding: 0.7rem;
}

.seat-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0.25rem 0.35rem;
}

.seat-name {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  color: var(--gold);
}

.life {
  font-family: var(--font-display);
  font-size: 1.85rem;
  color: var(--bone);
  min-width: 2ch;
  text-align: right;
}

.life.hurt { color: var(--blood-hot); animation: pulse 0.35s ease; }

@keyframes pulse {
  from { transform: scale(1.15); }
  to { transform: scale(1); }
}

.zone-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin: 0.35rem;
}

.pile {
  min-width: 3.4rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 0.1rem;
  text-align: center;
}

.pile span {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.pile b {
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.mana {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 1.6rem;
  align-items: center;
}

.pip {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: grid;
  place-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #111;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.pip.W { background: var(--W); }
.pip.U { background: var(--U); color: #fff; }
.pip.B { background: var(--B); color: #fff; }
.pip.R { background: var(--R); color: #fff; }
.pip.G { background: var(--G); color: #fff; }
.pip.C { background: #9a9488; }

.battlefield {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 7.2rem;
  padding: 0.35rem;
  align-content: flex-start;
}

.mid {
  text-align: center;
  padding: 0.35rem 0.5rem 0.55rem;
}

.phase {
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.prompt {
  margin: 0 0 0.55rem;
  color: var(--bone-dim);
  font-size: 0.98rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.actions .btn {
  padding: 0.55rem 1rem;
  font-size: 0.92rem;
  box-shadow: none;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  min-height: 10.5rem;
  padding: 0.5rem 0.2rem 0.7rem;
}

/* Cards */
.card {
  --accent: #6a6258;
  --frame: #2c2418;
  width: 7.6rem;
  height: 10.6rem;
  border-radius: 10px;
  border: 2px solid var(--frame);
  background:
    linear-gradient(165deg, rgba(255, 248, 230, 0.95), rgba(236, 222, 190, 0.98) 40%, #e2d2b0);
  color: var(--card-ink);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 10px 22px rgba(0, 0, 0, 0.4);
  padding: 0.32rem;
  display: grid;
  grid-template-rows: auto minmax(3.8rem, 1.4fr) auto minmax(0, 1.45rem);
  gap: 0.18rem;
  cursor: default;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, outline 0.15s ease;
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: left;
  user-select: none;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(196, 164, 106, 0.35);
}

.card.tiny {
  width: 6.4rem;
  height: 9rem;
  font-size: 0.6rem;
}

.card.playable {
  cursor: pointer;
  outline: 2px solid rgba(196, 164, 106, 0.75);
  outline-offset: 2px;
}

.card.playable:hover,
.card.selectable:hover {
  transform: translateY(-7px) scale(1.03);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.card.selectable { cursor: pointer; }
.card.selected {
  outline: 2px solid var(--blood-hot);
  outline-offset: 2px;
  transform: translateY(-9px);
}

.card.tapped {
  transform: rotate(12deg);
  opacity: 0.88;
}

.card.attacking {
  outline: 2px solid var(--blood-hot);
  outline-offset: 2px;
  transform: translateY(-10px);
}

.card.blocking {
  outline: 2px solid var(--U);
  outline-offset: 2px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.2rem;
  align-items: flex-start;
  padding: 0.05rem 0.05rem 0;
  position: relative;
  z-index: 1;
}

.card-name {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.card-cost {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.card-cost .pip {
  width: 0.95rem;
  height: 0.95rem;
  font-size: 0.55rem;
}

.card-art {
  border-radius: 6px;
  border: 1px solid rgba(40, 30, 18, 0.5);
  background: #0a0806;
  min-height: 0;
  overflow: hidden;
  position: relative;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 2px 8px rgba(0, 0, 0, 0.25);
}

.card-art::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 28%, transparent 70%, rgba(0, 0, 0, 0.28));
}

.card-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  image-rendering: auto;
}

.card-type {
  font-size: 0.55rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(26, 24, 20, 0.7);
  border-top: 1px solid rgba(26, 24, 20, 0.14);
  border-bottom: 1px solid rgba(26, 24, 20, 0.14);
  padding: 0.1rem 0;
  background: linear-gradient(90deg, transparent, rgba(196, 164, 106, 0.12), transparent);
}

.card-text {
  font-size: 0.58rem;
  color: rgba(26, 24, 20, 0.86);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  padding-right: 1.6rem;
}

.card.tiny .card-text {
  -webkit-line-clamp: 2;
  font-size: 0.52rem;
}

.card-pt {
  position: absolute;
  right: 0.28rem;
  bottom: 0.28rem;
  background: linear-gradient(180deg, #2a2218, #14100c);
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 0.78rem;
  padding: 0.12rem 0.4rem;
  border-radius: 5px;
  min-width: 2.3rem;
  text-align: center;
  border: 1px solid rgba(196, 164, 106, 0.45);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

.card[data-color="W"] { --accent: #8a8068; --frame: #6a5a38; }
.card[data-color="U"] { --accent: #3a5a72; --frame: #2a4058; }
.card[data-color="B"] { --accent: #3a2a42; --frame: #2a1a32; }
.card[data-color="R"] { --accent: #6a2820; --frame: #5a2018; }
.card[data-color="G"] { --accent: #2a4a32; --frame: #1a3824; }
.card[data-color="C"] { --accent: #4a4840; --frame: #3a3830; }
.card[data-color="M"] { --accent: #5a4030; --frame: #4a3020; }

/* Rules dialog */
.rules-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: #121814;
  color: var(--bone);
  width: min(36rem, calc(100vw - 1.5rem));
  max-height: min(85vh, 40rem);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.rules-dialog::backdrop {
  background: rgba(4, 8, 6, 0.72);
  backdrop-filter: blur(4px);
}

.rules-sheet {
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: min(85vh, 40rem);
}

.rules-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.75rem;
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--line);
  align-items: start;
}

.rules-head .eyebrow { grid-column: 1; }
.rules-head h2 {
  margin: 0;
  grid-column: 1;
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.06em;
  color: var(--bone);
}

.rules-head .ghost {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
}

.rules-body {
  overflow: auto;
  padding: 0.85rem 1.15rem 1rem;
  display: grid;
  gap: 0.95rem;
  text-align: left;
}

.rules-body h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.rules-body p,
.rules-body li {
  margin: 0;
  color: var(--bone-dim);
  line-height: 1.5;
  font-size: 0.95rem;
}

.rules-body ul,
.rules-body ol {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.rules-body strong { color: var(--bone); }

.rules-foot {
  padding: 0.75rem 1.1rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.log-panel {
  position: fixed;
  right: 0.75rem;
  bottom: 0.75rem;
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: 40vh;
  overflow: auto;
  background: rgba(8, 12, 10, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  z-index: 20;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.log-panel[hidden] { display: none !important; }

.log-panel h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  color: var(--gold);
}

#log-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--bone-dim);
  font-size: 0.82rem;
  display: grid;
  gap: 0.3rem;
}

@media (max-width: 720px) {
  .card {
    width: 5.8rem;
    height: 8.2rem;
    font-size: 0.58rem;
  }
  .card.tiny {
    width: 5.2rem;
    height: 7.3rem;
  }
  .card-name { font-size: 0.6rem; }
  .life { font-size: 1.5rem; }
  .battlefield { min-height: 5.5rem; }
}
