:root {
  --bg: #08090c;
  --panel: #14161d;
  --panel-2: #1b1e28;
  --text: #e9e4da;
  --muted: #8f93a3;
  --accent: #d9b062;
  --blood: #8e1b26;
  --ember: #d4501a;
  --frost: #3a7fd0;
  --serif: "Cinzel", "Trajan Pro", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }
html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

#app { min-height: 100%; }

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 32px 24px 48px;
}

.logo { font-size: clamp(36px, 8vmin, 84px); letter-spacing: 0.04em; margin: 8px 0 4px; }
h2 { font-family: var(--serif); letter-spacing: 0.06em; margin: 0; font-size: clamp(26px, 5vmin, 48px); text-align: center; }
h3 { margin: 0 0 8px; }

.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0; }
.error { color: #ff8b8b; }
.good { color: #7bdc8a; }
.bad { color: #ff8b8b; }
.lines { text-align: center; margin: 0; line-height: 1.6; }

.menu-list, .stack {
  display: flex; flex-direction: column; gap: 12px; width: min(560px, 100%);
}

.menu-item, .btn {
  background: var(--panel);
  border: 2px solid #2a3040;
  border-radius: 14px;
  padding: 14px 20px;
  text-align: left;
  display: flex; flex-direction: column; gap: 2px;
}
.btn { align-items: center; text-align: center; }
.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 700; }
.btn:disabled { opacity: 0.45; }
.menu-item:disabled { opacity: 0.45; }
.menu-title { font-size: 22px; font-weight: 700; }
.menu-blurb { color: var(--muted); font-size: 14px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.panel { background: var(--panel); border-radius: 14px; padding: 18px 20px; width: min(720px, 100%); }

.toggle {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  width: 100%;
  background: var(--panel-2);
  border: 2px solid #2a3040;
  border-radius: 12px;
  padding: 10px 16px;
  margin-bottom: 8px;
  text-align: left;
}
.toggle .tname { display: flex; flex-direction: column; font-weight: 600; }
.toggle small { color: var(--muted); font-weight: 400; font-size: 13px; }
.toggle .state { font-weight: 700; color: var(--muted); white-space: nowrap; }
.toggle[aria-pressed="true"] { border-color: var(--accent); }
.toggle[aria-pressed="true"] .state { color: var(--accent); }

.counts { display: flex; gap: 28px; font-size: 18px; font-weight: 700; }
.counts .blue { color: #6fa3ff; }
.counts .red { color: #ff7a85; }

/* ---------------------------------------------------------------- cards */
.card {
  position: relative;
  width: 100%;
  aspect-ratio: 344 / 462;
  container-type: inline-size;
  border-radius: 7% / 5.2%;
  overflow: hidden;
  border: 2px solid var(--rim, #cfd6e6);
  background: var(--face, #444);
  color: #fff;
  user-select: none;
  --rim: #cfd6e6;
}
.card.owner-0 { --face: linear-gradient(160deg, #4d8bec, #1a3f86); }
.card.owner-1 { --face: linear-gradient(160deg, #db5862, #7c1b23); }
.card.tier-bronze { --rim: #c27a3b; }
.card.tier-silver { --rim: #e1e6f0; }
.card.tier-gold { --rim: #f3c64e; box-shadow: 0 0 10px rgba(243, 198, 78, 0.65); }
.card.back { background: repeating-linear-gradient(45deg, #2a2f3d 0 10px, #222633 10px 20px); --rim: #4a5168; }

.card .art { position: absolute; left: 5%; top: 11%; width: 90%; height: 80%; object-fit: cover; border-radius: 4%; opacity: 0.95; }
.card .cname {
  position: absolute; left: 0; right: 0; top: 3%;
  text-align: center; font-size: 8.5cqw; font-weight: 700; letter-spacing: 0.02em;
  text-shadow: 0 1px 2px #000;
}
.card .face-ph {
  position: absolute; left: 5%; top: 11%; width: 90%; height: 80%;
  border-radius: 4%; background: rgba(255, 255, 255, 0.1);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12%;
  font-size: 9cqw; opacity: 0.8; text-align: center;
}
.card .ranks {
  position: absolute; left: 8%; top: 13%;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, auto);
  width: 36%; text-align: center;
  font-size: 17cqw; font-weight: 800; line-height: 1;
  text-shadow: 0 0 4px #000, 0 1px 3px #000, 0 0 8px #000;
}
.card .ranks .top { grid-area: 1 / 2; }
.card .ranks .left { grid-area: 2 / 1; }
.card .ranks .right { grid-area: 2 / 3; }
.card .ranks .bottom { grid-area: 3 / 2; }
.card .el { position: absolute; top: 12%; right: 6%; font-size: 14cqw; text-shadow: none; }
.card .lvl {
  position: absolute; bottom: 2.5%; left: 50%; transform: translateX(-50%);
  width: 13cqw; height: 13cqw; border-radius: 50%;
  background: rgba(0, 0, 0, 0.65); border: 1px solid var(--rim);
  display: flex; align-items: center; justify-content: center;
  font-size: 8cqw; font-weight: 700;
}
.card .bonus {
  position: absolute; bottom: 3%; left: 6%;
  width: 16cqw; height: 16cqw; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 8.5cqw; font-weight: 800; border: 2px solid #fff;
}
.card .bonus.plus { background: #2f9a4a; }
.card .bonus.minus { background: #b02f2f; }
.card .count { position: absolute; bottom: 3%; right: 6%; font-size: 9cqw; font-weight: 700; background: rgba(0,0,0,0.6); padding: 0 5%; border-radius: 6px; }

.cardbtn { background: none; border: 0; padding: 0; border-radius: 8px; width: var(--gw, 120px); transition: transform 0.12s; }
.cardbtn:disabled { opacity: 1; }
.cardbtn:focus-visible { transform: scale(1.06); z-index: 3; position: relative; }
.cardbtn.selected .card { box-shadow: 0 0 0 4px var(--accent); }
.cardbtn.picked .card { box-shadow: 0 0 0 4px #7bdc8a; }

.grid { --gw: min(13vw, 17vh, 130px); display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; width: min(1200px, 100%); }
.grid .card { width: var(--gw); }

@keyframes flip { 0% { transform: rotateY(0); } 50% { transform: rotateY(90deg); } 100% { transform: rotateY(0); } }
@keyframes drop { from { transform: scale(1.2); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }
.card.flipped { animation: flip 0.5s ease; }
.card.placed { animation: drop 0.25s ease; }

/* ---------------------------------------------------------------- match */
.match { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px; }
.scorebar {
  display: flex; justify-content: space-between; align-items: center;
  width: min(1100px, 100%); font-size: clamp(15px, 2.6vmin, 24px); font-weight: 700;
}
.scorebar .blue { color: #6fa3ff; }
.scorebar .red { color: #ff7a85; }
.scorebar .msg { color: var(--accent); text-align: center; flex: 1; padding: 0 12px; font-size: 0.85em; }

.arena { --hw: min(11vw, 19vh); display: flex; align-items: center; justify-content: center; gap: 1.4vw; width: 100%; }

.hand { display: flex; flex-direction: column; align-items: center; width: var(--hw); flex: 0 0 auto; }
.hand .cardbtn, .hand > .card { --gw: var(--hw); width: var(--hw); }
.hand > * + * { margin-top: calc(var(--hw) * -0.74); }
.hand .cardbtn.selected { transform: translateX(-22%); z-index: 2; position: relative; }

.boardwrap {
  position: relative;
  width: min(60vw, 82vh * 1.3003);
  aspect-ratio: 2576 / 1981;
  border-radius: 10px;
  overflow: visible;
  background: #1a1c24;
}
.boardwrap .boardimg { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 10px; user-select: none; pointer-events: none; }
.boardwrap.noart { background: radial-gradient(circle at 20% 20%, #5a2a1a, #1a1c24 45%, #123038); }
.boardwrap.noart .slot { border: 2px dashed rgba(255, 255, 255, 0.28); }

.slot {
  position: absolute;
  padding: 0; margin: 0;
  background: transparent; border: 0;
  border-radius: 3%;
}
.slot .card { position: absolute; inset: 0; }
.slot:focus-visible { outline: 5px solid var(--accent); outline-offset: 2px; z-index: 4; }
.slot.armed:not(:disabled) { box-shadow: inset 0 0 0 3px rgba(242, 193, 78, 0.85); background: rgba(242, 193, 78, 0.12); }

.token {
  position: absolute; width: 3.8%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: 2px solid #fff; container-type: inline-size;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); pointer-events: none; z-index: 3;
}
.token span { font-size: 60cqw; line-height: 1; }
.token.el-earth { background: #8a6a3a; }
.token.el-fire { background: #d4501a; }
.token.el-holy { background: #cfc9a0; }
.token.el-thunder { background: #b9b814; }
.token.el-water { background: #1f58b8; }
.token.el-wind { background: #2f8f9a; }
.token.el-ice { background: #3a7fd0; }
.token.el-poison { background: #5a3a8a; }

.wheel {
  position: absolute; left: 20.15%; top: 14.44%; width: 11.5%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%; container-type: inline-size;
  background: radial-gradient(circle, rgba(30, 14, 6, 0.92), rgba(10, 5, 3, 0.92));
  border: 3px solid #e8c07a; pointer-events: none;
}
.wheel span { position: absolute; font-size: 12cqw; font-weight: 700; letter-spacing: 0.06em; color: rgba(255, 255, 255, 0.45); }
.wheel .w-diff { top: 10%; left: 50%; transform: translateX(-50%); }
.wheel .w-one { right: 8%; top: 50%; transform: translateY(-50%); }
.wheel .w-all { bottom: 10%; left: 50%; transform: translateX(-50%); }
.wheel .w-direct { left: 7%; top: 50%; transform: translateY(-50%); }
.wheel .on { color: var(--accent); text-shadow: 0 0 8px rgba(242, 193, 78, 0.9); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 1000px; }
.chip { background: var(--panel-2); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--text); }

.overlay { position: fixed; inset: 0; background: rgba(5, 6, 9, 0.78); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 5; }

@media (max-aspect-ratio: 1 / 1) {
  .arena { flex-direction: column; --hw: 17vw; gap: 10px; }
  .hand { flex-direction: row; width: auto; }
  .hand > * + * { margin-top: 0; margin-left: calc(var(--hw) * -0.5); }
  .hand .cardbtn.selected { transform: translateY(-18%); }
  .boardwrap { width: 96vw; }
  .grid { --gw: min(26vw, 120px); }
}

@media (prefers-reduced-motion: reduce) {
  .card.flipped, .card.placed { animation: none; }
}


/* ---------------------------------------------------------------- gothic shell: intro + main menu */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse 55% 70% at 0% 100%, rgba(212, 80, 26, 0.26), transparent 70%),
    radial-gradient(ellipse 55% 70% at 100% 0%, rgba(58, 127, 208, 0.22), transparent 70%),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35) 30%, rgba(0, 0, 0, 0.8) 100%),
    linear-gradient(rgba(5, 5, 9, 0.5), rgba(5, 5, 9, 0.5)),
    url("../assets/menu-bg.webp") center / cover no-repeat,
    var(--bg);
}

.intro {
  position: fixed; inset: 0; z-index: 20; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  text-align: center; padding: 24px; cursor: pointer;
  transition: opacity 0.9s ease;
}
.intro.leaving { opacity: 0; pointer-events: none; }
.intro .presents, .intro .tag, .intro .skip, .intro .big {
  opacity: 0; animation: fadeUp 1.6s ease forwards;
}
.intro .presents { font-family: var(--serif); font-size: clamp(16px, 3vmin, 28px); letter-spacing: 0.5em; text-transform: uppercase; color: #b9b2a3; animation-delay: 0.4s; }
.intro .presents b { display: block; margin-bottom: 14px; font-size: 1.7em; letter-spacing: 0.3em; color: var(--text); text-shadow: 0 0 22px rgba(142, 27, 38, 0.9); }
.intro .rule { width: min(360px, 60vw); height: 1px; background: linear-gradient(90deg, transparent, var(--blood), var(--frost), transparent); opacity: 0; animation: fadeUp 1.6s ease 1.6s forwards; }
.intro .big { font-family: var(--serif); font-size: clamp(40px, 11vmin, 120px); font-weight: 700; letter-spacing: 0.08em; animation-delay: 2.6s;
  background: linear-gradient(90deg, #f0894d, #e9e4da 50%, #7db4ff); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(0, 0, 0, 0.9)); }
.intro .tag { font-style: italic; color: #a39d8f; font-size: clamp(14px, 2.4vmin, 22px); animation-delay: 3.6s; }
.intro .skip { font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: #5f6272; animation-delay: 4.4s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.menu { min-height: 100vh; justify-content: center; gap: 30px; }
.menu .crest { font-family: var(--serif); font-size: clamp(11px, 1.8vmin, 15px); letter-spacing: 0.5em; text-transform: uppercase; color: var(--muted); margin: 0; }
.menu .logo {
  font-family: var(--serif); font-weight: 700; letter-spacing: 0.1em; margin: 0; text-align: center;
  background: linear-gradient(90deg, #f0894d, #e9e4da 50%, #7db4ff); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.9));
}
.menu .divider { width: min(420px, 70vw); height: 1px; background: linear-gradient(90deg, transparent, var(--blood), var(--accent), var(--frost), transparent); border: 0; margin: 0; }
.menu .menu-list { gap: 14px; }
.menu .menu-item {
  position: relative; text-align: center; align-items: center; padding: 18px 24px;
  background: linear-gradient(180deg, rgba(27, 30, 40, 0.92), rgba(12, 13, 18, 0.92));
  border: 1px solid #3b3f52; border-radius: 4px;
  box-shadow: inset 0 0 0 3px #0a0b0f, inset 0 0 0 4px #2a2d3b, 0 6px 18px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.menu .menu-item::before, .menu .menu-item::after {
  content: "\2726"; position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 14px; color: var(--accent); opacity: 0; transition: opacity 0.15s;
}
.menu .menu-item::before { left: 16px; }
.menu .menu-item::after { right: 16px; }
.menu .menu-item:not(:disabled):hover, .menu .menu-item:not(:disabled):focus-visible {
  transform: translateY(-2px); border-color: var(--accent); outline: none;
  box-shadow: inset 0 0 0 3px #0a0b0f, inset 0 0 0 4px var(--accent), 0 0 28px rgba(142, 27, 38, 0.55), 0 0 28px rgba(58, 127, 208, 0.25);
}
.menu .menu-item:not(:disabled):hover::before, .menu .menu-item:not(:disabled):hover::after,
.menu .menu-item:not(:disabled):focus-visible::before, .menu .menu-item:not(:disabled):focus-visible::after { opacity: 1; }
.menu .menu-title { font-family: var(--serif); font-size: clamp(20px, 3vmin, 28px); letter-spacing: 0.1em; }
.menu .menu-blurb { font-style: italic; }
.menu .menu-item:disabled { opacity: 1; filter: grayscale(0.6) brightness(0.8); background: #0c0d12; }
.menu .menu-item:disabled .menu-title::after { content: " \00b7 sealed"; font-size: 0.55em; letter-spacing: 0.25em; text-transform: uppercase; color: #c2414f; }
.menu .footer { font-family: var(--serif); font-size: 12px; letter-spacing: 0.4em; text-transform: uppercase; color: #5f6272; margin: 8px 0 0; text-align: center; }

/* shared gothic touches for the game screens */
.btn { font-family: var(--serif); letter-spacing: 0.06em; border-radius: 4px; }
.btn.primary { background: linear-gradient(180deg, #e2bd74, #b38b3e); }

@media (prefers-reduced-motion: reduce) {
  .intro .presents, .intro .tag, .intro .skip, .intro .big, .intro .rule { animation: none; opacity: 1; }
}
