:root {
  --eazo-safe-area-top: max(56px, env(safe-area-inset-top, 0px));
  --eazo-safe-area-bottom: max(34px, env(safe-area-inset-bottom, 0px));
  --ink: #f7ead0;
  --muted: #cbb98f;
  --brass: #b99143;
  --brass2: #eed292;
  --danger: #8d3d24;
  --display: "Bodoni 72 Condensed", "Didot", "Playfair Display", Georgia, serif;
  --sans: "Avenir Next", "Gill Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html {
  background: #0b0705;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-width: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 6%, rgba(255, 221, 156, 0.22), transparent 34%),
    linear-gradient(115deg, #100804, #32180d 34%, #160905 72%, #080503);
}
button {
  font: inherit;
  color: inherit;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }

/* Decorative material layers — never block controls */
.grain, .shine { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.grain {
  opacity: 0.12;
  mix-blend-mode: screen;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='.45'/%3E%3C/svg%3E");
}
.shine { background: linear-gradient(105deg, transparent 0 38%, rgba(255, 238, 194, 0.06) 45%, transparent 55%); }

.app {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  padding-top: var(--eazo-safe-area-top);
  padding-bottom: var(--eazo-safe-area-bottom);
  display: flex;
  flex-direction: column;
}
.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 0 14px 18px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0 10px;
}
.brand { min-width: 0; }
.kicker {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 {
  font-family: var(--display);
  font-size: clamp(26px, 8vw, 40px);
  line-height: 0.9;
  letter-spacing: 0.03em;
  margin: 0;
  text-transform: uppercase;
  text-shadow: 0 2px 0 #000;
}
.tools { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.seg {
  display: flex;
  border: 1px solid rgba(237, 205, 139, 0.42);
  border-radius: 999px;
  background: rgba(20, 12, 8, 0.58);
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 12px;
  min-height: 36px;
  color: #d8c597;
}
.seg button.active {
  background: linear-gradient(#f1d99a, #9b702d);
  color: #1a0d06;
  box-shadow: inset 0 1px 0 #fff4c0;
}
.binderBtn {
  border: 1px solid rgba(237, 205, 139, 0.35);
  border-radius: 999px;
  background: rgba(255, 250, 232, 0.09);
  padding: 0 14px;
  font-size: 12px;
  color: #f4dfaf;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  flex: 1;
  min-height: 0;
}

/* The walnut table with felt inlay */
.table {
  position: relative;
  border-radius: 28px;
  padding: 12px;
  background: radial-gradient(ellipse at center, #14513a 0, #0e3428 58%, #082019 100%);
  box-shadow:
    inset 0 0 0 12px rgba(54, 23, 10, 0.7),
    inset 0 0 0 13px rgba(214, 164, 76, 0.24),
    0 24px 70px #000b;
  min-width: 0;
}
.table::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 36px;
  background: repeating-linear-gradient(90deg, #3b1b0c 0 8px, #291105 8px 16px, #4c260f 16px 24px);
  z-index: -1;
  box-shadow: 0 20px 50px #000;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 4px 10px;
}
.pill {
  border: 1px solid rgba(235, 196, 121, 0.42);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 243, 208, 0.12), rgba(33, 18, 10, 0.42));
  padding: 7px 11px;
  font-size: 12px;
  color: #f9dfaa;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  white-space: nowrap;
}
.score {
  font-family: var(--display);
  font-size: 30px;
  line-height: 0.8;
  color: #f6d27c;
  letter-spacing: 0.02em;
}

.arena {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.deck {
  height: 92px;
  border-radius: 12px;
  background: linear-gradient(135deg, #231009, #3a1a0d);
  border: 1px solid rgba(246, 210, 124, 0.35);
  box-shadow: 0 10px 20px #0007, inset 0 0 0 5px rgba(12, 7, 5, 0.45), inset 0 0 0 6px rgba(222, 179, 94, 0.22);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  color: #d8bd7a;
  font-size: 10px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.4s;
}
.deck::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(237, 202, 132, 0.32);
  border-radius: 8px;
}
.deck .count {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  font-family: var(--display);
  font-size: 18px;
  color: #f3d98f;
}
.pileGlow { box-shadow: 0 0 26px rgba(238, 197, 92, 0.55), inset 0 0 0 5px rgba(12, 7, 5, 0.45); }

.cardZone { min-width: 0; display: flex; flex-direction: column; align-items: center; }
.duel {
  width: min(100%, 250px);
  position: relative;
  perspective: 1200px;
}
.brassTick {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 6;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 26px;
  color: #1b0d04;
  background: radial-gradient(circle at 35% 30%, #fff0be, #b8842f 70%, #7c5417);
  box-shadow: 0 6px 0 #3b230b, 0 10px 22px #000a;
  opacity: 0;
  pointer-events: none;
}
.brassTick.show { animation: tick 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }

.card {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 18px;
  background: #120b08;
  padding: 7px;
  box-shadow: 0 16px 36px #000b, 0 0 0 1px rgba(245, 218, 151, 0.35);
  transform-style: preserve-3d;
  transition: filter 0.35s;
}
.card.winner { filter: drop-shadow(0 0 22px rgba(250, 211, 103, 0.95)); }
.card.flip { animation: heavyFlip 0.82s cubic-bezier(0.2, 0.72, 0.08, 1); }
.card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 15px;
  border: 2px solid rgba(235, 190, 92, 0.7);
  box-shadow: inset 0 0 0 1px rgba(255, 246, 198, 0.35);
  pointer-events: none;
  z-index: 3;
}
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: linear-gradient(115deg, transparent 0 40%, rgba(255, 255, 232, 0.7) 48%, transparent 56%);
  opacity: 0;
  transform: translateX(-40%);
  pointer-events: none;
  z-index: 4;
}
.card.foil::after { animation: foil 0.7s ease; }

.photo {
  position: relative;
  height: 60%;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #2a1a12, #170d08);
}
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo.fallback {
  background: repeating-linear-gradient(45deg, #d8c7a4 0 10px, #cdbb93 10px 20px);
}
.photo.fallback::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed rgba(90, 60, 30, 0.5);
  border-radius: 8px;
}

.identity { padding: 8px 6px 4px; }
.name {
  font-family: var(--display);
  font-size: 20px;
  line-height: 0.95;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.tag { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Brass stat plate */
.stats {
  margin-top: 6px;
  display: grid;
  gap: 4px;
  border-radius: 10px;
  padding: 5px;
  background: linear-gradient(180deg, #d9ab55, #9a6f2c);
  box-shadow: inset 0 1px 0 rgba(255, 246, 200, 0.7), inset 0 -2px 4px rgba(60, 36, 10, 0.6);
}
.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid rgba(60, 36, 10, 0.45);
  border-radius: 7px;
  background: linear-gradient(180deg, #f0cf85, #c79646);
  color: #2a1706;
  box-shadow: inset 0 1px 0 rgba(255, 252, 230, 0.9);
  transition: transform 0.12s, filter 0.15s;
}
.stat:active { transform: scale(0.98); filter: brightness(1.08); }
.stat[disabled] { opacity: 0.85; cursor: default; }
.stat.picked { outline: 2px solid #fff2c4; background: linear-gradient(180deg, #ffe6a0, #d8a54f); }
.stat .label {
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.stat .val { font-family: var(--display); font-size: 24px; line-height: 1; }

.instruction {
  margin: 10px 4px 4px;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  color: #e7d4a6;
  max-width: 320px;
}
.statusText {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
  margin: 2px 4px 0;
}

/* Comparison view */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;
}
.compare .side { position: relative; }
.compare .who {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.compare .card { padding: 5px; }
.compare .name { font-size: 14px; }
.compare .cmpStat {
  margin-top: 5px;
  text-align: center;
  border-radius: 7px;
  padding: 5px;
  background: linear-gradient(180deg, #e7c274, #b1823b);
  color: #2a1706;
  box-shadow: inset 0 1px 0 rgba(255, 252, 230, 0.8);
}
.compare .cmpStat .label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.compare .cmpStat .val { font-family: var(--display); font-size: 26px; line-height: 1; }

/* Support column (round log / result) */
.support {
  border-radius: 22px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(18, 11, 7, 0.72), rgba(10, 7, 5, 0.84));
  border: 1px solid rgba(232, 190, 105, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.support h2 {
  font-family: var(--display);
  font-size: 26px;
  line-height: 0.9;
  margin: 0 0 10px;
  text-transform: uppercase;
}
.log { display: grid; gap: 8px; }
.logRow {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  border-radius: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  color: #dec891;
}
.logRow .tick {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(#ffe8a6, #98651d);
  color: #1b0d04;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 2px 0 #3b230b;
}
.logRow .who { font-family: var(--display); font-size: 16px; color: #f6d27c; }
.logRow.win-you { box-shadow: inset 0 0 0 1px rgba(246, 210, 124, 0.4); }
.logRow.win-house { box-shadow: inset 0 0 0 1px rgba(141, 61, 36, 0.5); }

/* Result state */
.result { display: none; }
.result.show { display: block; }
.hidden { display: none !important; }
.heroWin { width: min(200px, 62%); margin: 0 auto 10px; }
.resultLine { text-align: center; font-size: 13px; color: #e7d4a6; margin: 4px 0; }
.finalScore {
  font-family: var(--display);
  font-size: 46px;
  line-height: 0.8;
  color: #f6d27c;
  text-align: center;
  margin: 4px 0;
}
.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0 10px;
}
.action {
  min-height: 50px;
  border-radius: 12px;
  border: 1px solid rgba(60, 36, 10, 0.45);
  background: linear-gradient(180deg, #f0cf85, #c79646);
  color: #2a1706;
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 252, 230, 0.9);
}
.action.secondary {
  background: rgba(255, 250, 232, 0.08);
  color: #f4dfaf;
  border-color: rgba(237, 205, 139, 0.35);
  box-shadow: none;
}
.action:active { transform: translateY(1px); }
.wonLabel { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 8px 0 4px; }
.miniStrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 8px;
  scrollbar-width: thin;
}
.mini {
  flex: 0 0 46px;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  border: 1px solid rgba(235, 199, 116, 0.35);
  background: #1b100b;
  overflow: hidden;
}
.mini img { width: 100%; height: 100%; object-fit: cover; }

/* Binder modal */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--eazo-safe-area-top) 14px var(--eazo-safe-area-bottom);
  background: rgba(8, 5, 3, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.overlay.show { display: flex; }
.modal {
  width: min(680px, 100%);
  max-height: calc(100svh - var(--eazo-safe-area-top) - var(--eazo-safe-area-bottom));
  overflow: auto;
  border-radius: 26px;
  background:
    linear-gradient(145deg, #1b1310, #0a0705),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0 3px, transparent 3px 6px);
  border: 1px solid rgba(239, 198, 110, 0.28);
  box-shadow: 0 30px 80px #000, inset 0 0 0 6px rgba(0, 0, 0, 0.4), inset 0 0 0 8px rgba(120, 80, 40, 0.3);
  padding: 16px;
}
.modalHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modalHead h2 { font-family: var(--display); font-size: 30px; line-height: 0.9; margin: 0; text-transform: uppercase; }
.close {
  border: 1px solid rgba(236, 197, 114, 0.35);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0 15px;
  color: #f4dfaf;
  flex-shrink: 0;
}
.binderGrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.slot {
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}
.slot img { width: 100%; height: 100%; object-fit: cover; }
.slot.empty::after {
  content: attr(data-id);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(203, 185, 143, 0.5);
  font-family: var(--display);
  font-size: 16px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--eazo-safe-area-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  z-index: 40;
  background: linear-gradient(180deg, #1c130d, #0c0806);
  border: 1px solid rgba(237, 205, 139, 0.4);
  color: #f4dfaf;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Desktop */
@media (min-width: 760px) {
  .shell { padding-left: 24px; padding-right: 24px; }
  .layout {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
    align-items: start;
  }
  .table { padding: 18px; }
  .arena { grid-template-columns: 84px minmax(0, 1fr) 84px; }
  .deck { height: 130px; }
  .duel { width: min(100%, 340px); }
  .support { position: sticky; top: calc(var(--eazo-safe-area-top) + 12px); }
  h1 { font-size: 46px; }
  .actions { grid-template-columns: 1fr 1fr 1fr; }
  .name { font-size: 24px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .arena { grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 6px; }
  .deck { height: 78px; font-size: 9px; }
  .duel { width: min(100%, 220px); }
  .stat { padding: 0 9px; }
  .stat .label { font-size: 15px; }
  .stat .val { font-size: 21px; }
  .name { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@keyframes foil {
  0% { opacity: 0; transform: translateX(-55%); }
  42% { opacity: 1; }
  100% { opacity: 0; transform: translateX(60%); }
}
@keyframes heavyFlip {
  0% { transform: translateY(0) rotateY(0); }
  45% { transform: translateY(-10px) rotateY(92deg); }
  100% { transform: translateY(0) rotateY(0); }
}
@keyframes tick {
  0% { transform: translate(-50%, -50%) scale(0.4) rotate(-20deg); opacity: 0; }
  55% { transform: translate(-50%, -50%) scale(1.12) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
