:root {
  --bg: #0a0506;
  --card: #120b0b;
  --card-line: #2b1d1d;
  --amber: #e0a040;
  --blood: #b3001b;
  --blood-hot: #ff2d55;
  --bone: #efe4cc;
  --muted: #a8968f;
  --neon-green: #7ed321;
  --neon-red: #ff2d55;
  --neon-cyan: #22d3ee;
  --neon-purple: #a855f7;
  --neon-amber: #f59e0b;
  --title: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --gore: 'Creepster', Impact, sans-serif;
  --metal: 'Anton', Impact, 'Arial Narrow Bold', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--bone); font-family: var(--serif); font-size: 17px; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
[hidden] { display: none !important; }
a { color: var(--amber); }
#board { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; }

.btn {
  font: 700 0.95rem/1 var(--title); letter-spacing: 0.02em; color: var(--bone);
  background: var(--card); border: 2px solid var(--card-line); border-radius: 14px;
  padding: 0.9rem 1.2rem; cursor: pointer; transition: transform 80ms, border-color 120ms;
}
.btn:hover { border-color: #4a3030; }
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .card-btn:focus-visible, .seg button:focus-visible, input:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.btn.primary { background: linear-gradient(180deg, #c8102e, #7a0012); border-color: #ff2d55; box-shadow: 0 0 18px rgba(255, 45, 85, 0.35); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 0.8rem; padding: 0.6rem 0.9rem; }

.screen {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-r)) calc(1rem + var(--safe-b)) calc(1rem + var(--safe-l));
  background: radial-gradient(ellipse 90% 55% at 50% 0%, rgba(120, 8, 24, 0.5), transparent 70%), rgba(10, 5, 6, 0.82);
  overflow-y: auto; touch-action: pan-y;
}
.panel {
  width: min(540px, 100%); max-height: 100%; overflow-y: auto;
  background: rgba(14, 8, 9, 0.96); border: 2px solid var(--card-line); border-radius: 20px;
  padding: 1.4rem 1.4rem 1.2rem; box-shadow: 0 0 60px rgba(224, 16, 47, 0.16), 0 20px 60px rgba(0, 0, 0, 0.7);
}
h2 { font: 900 1.8rem/1.1 var(--title); margin: 0 0 1rem; text-shadow: 0 0 18px rgba(255, 45, 85, 0.25); }
h3 { font: 700 1.1rem/1.2 var(--title); margin: 0 0 0.6rem; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 0.92rem; }
.row { display: flex; gap: 0.75rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1.2rem; }
.row.left { justify-content: flex-start; margin-top: 0.6rem; }
.row.tight { margin-top: 0; margin-bottom: 0.8rem; }
.err { color: #ff6b81; min-height: 1.2em; margin: 0.6rem 0 0; }

.title-screen { align-items: flex-start; background: radial-gradient(ellipse 85% 42% at 50% 12%, rgba(150, 10, 30, 0.7), rgba(40, 6, 10, 0.6) 55%, transparent 80%), rgba(10, 5, 6, 0.94); }
.title-wrap { width: min(470px, 100%); margin: 0 auto; padding-top: 0.4rem; display: grid; justify-items: center; gap: 1rem; }
.title-art { width: 100%; height: auto; border-radius: 14px; border: 3px solid #050304; box-shadow: 0 0 0 2px #3a1a22, 0 0 50px 8px rgba(224, 16, 47, 0.4), 0 18px 40px rgba(0, 0, 0, 0.7); }
.best-pill { display: flex; align-items: baseline; gap: 0.6rem; cursor: pointer; background: rgba(20, 6, 8, 0.85); color: var(--amber); border: 2px solid rgba(224, 160, 64, 0.6); border-radius: 999px; padding: 0.55rem 1.3rem; font-family: var(--serif); }
.best-pill b { font: 900 1.5rem/1 var(--title); color: #ffcf6a; }
.pill-sub { font-size: 0.95rem; color: #d9a45a; }
.cards { width: 100%; display: grid; gap: 0.75rem; }
.card-btn { display: flex; align-items: center; gap: 1.1rem; width: 100%; text-align: left; cursor: pointer; background: rgba(14, 9, 9, 0.94); border: 2px solid var(--card-line); border-radius: 18px; padding: 0.85rem 1.1rem; color: var(--bone); transition: transform 90ms, border-color 150ms; }
.card-btn:hover { border-color: #4a3030; }
.card-btn:active { transform: scale(0.985); }
.ico { flex: none; width: 3.3rem; height: 3.3rem; border-radius: 12px; border: 2px solid; display: grid; place-items: center; background: #080506; }
.ico svg { width: 1.7rem; height: 1.7rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.green { color: var(--neon-green); border-color: var(--neon-green); box-shadow: 0 0 12px rgba(126, 211, 33, 0.45); }
.ico.red { color: var(--neon-red); border-color: var(--neon-red); box-shadow: 0 0 12px rgba(255, 45, 85, 0.45); }
.ico.cyan { color: var(--neon-cyan); border-color: var(--neon-cyan); box-shadow: 0 0 12px rgba(34, 211, 238, 0.45); }
.ico.purple { color: var(--neon-purple); border-color: var(--neon-purple); box-shadow: 0 0 12px rgba(168, 85, 247, 0.45); }
.ico.amber { color: var(--neon-amber); border-color: var(--neon-amber); box-shadow: 0 0 12px rgba(245, 158, 11, 0.45); }
.card-txt { display: grid; gap: 0.2rem; min-width: 0; }
.card-title { font: 900 1.35rem/1.05 var(--title); color: #fff; }
.card-sub { font-size: 1.02rem; color: var(--muted); }
.acct-chip { font-size: 0.95rem; text-align: center; }
.acct-chip .who { color: var(--bone); }
.brand-foot { margin: 0 0 1rem; color: var(--muted); font-size: 0.92rem; text-align: center; }

.field { display: block; margin: 1rem 0 0.4rem; font: 700 0.85rem/1 var(--title); color: var(--amber); letter-spacing: 0.04em; }
.seg { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.seg button { flex: 1 1 0; min-width: 2.6rem; padding: 0.65rem 0.6rem; border-radius: 12px; border: 2px solid var(--card-line); background: #0d0708; color: var(--bone); font: 700 1rem/1 var(--serif); cursor: pointer; }
.seg button.on { border-color: var(--blood-hot); background: #2a070f; box-shadow: 0 0 12px rgba(255, 45, 85, 0.35); color: #fff; }
.seg.locked button { pointer-events: none; opacity: 0.75; }
input[type=text], input:not([type]), #nameInput, #codeInput { width: 100%; padding: 0.8rem 0.9rem; border-radius: 12px; border: 2px solid var(--card-line); background: #0d0708; color: var(--bone); font: 600 1.1rem/1 var(--serif); }
#codeInput { text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--metal); }
.join-row { display: flex; gap: 0.6rem; }
.join-row input { flex: 1; }
input[type=range] { width: 100%; accent-color: var(--blood-hot); }
.check { display: flex; gap: 0.6rem; align-items: center; margin-top: 1rem; font-size: 1.05rem; }
.code { font-family: var(--metal); letter-spacing: 0.18em; color: var(--blood-hot); }

.lobby-list, .results { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.45rem; }
.lobby-list li, .results li { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.8rem; border: 2px solid var(--card-line); border-radius: 12px; background: #0d0708; }
.dot { width: 1.05rem; height: 1.05rem; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; background: currentColor; }
.tag { margin-left: auto; font-size: 0.85rem; color: var(--muted); }
.results li.win { border-color: var(--amber); box-shadow: 0 0 14px rgba(224, 160, 64, 0.3); }
.score-line { font: 900 1.3rem/1.2 var(--title); color: #ffcf6a; text-align: center; min-height: 1.2em; }
.friend-list { display: grid; gap: 0.4rem; }
.friend-list button { display: flex; justify-content: space-between; align-items: center; padding: 0.55rem 0.8rem; border-radius: 12px; border: 2px solid var(--card-line); background: #0d0708; color: var(--bone); font: 600 1rem/1 var(--serif); cursor: pointer; }
.friend-list .on { color: var(--neon-green); font-size: 0.85rem; }
.how { padding-left: 1.2rem; display: grid; gap: 0.55rem; line-height: 1.45; }
.how b { color: var(--amber); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-stack { position: absolute; top: calc(0.5rem + var(--safe-t)); left: calc(0.5rem + var(--safe-l)); right: calc(0.5rem + var(--safe-r)); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.hud-top { width: 100%; display: flex; gap: 0.5rem; align-items: flex-start; }
.menu-btn { pointer-events: auto; flex: none; width: 2.8rem; height: 2.8rem; border-radius: 12px; border: 2px solid var(--card-line); background: rgba(14, 8, 9, 0.9); color: var(--bone); font-size: 1rem; cursor: pointer; }
#players { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1; }
#players li { display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.6rem; border-radius: 999px; border: 2px solid var(--card-line); background: rgba(14, 8, 9, 0.88); font: 600 0.92rem/1 var(--serif); max-width: 48%; }
#players li .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 7.5rem; }
#players li b { font: 400 1.05rem/1 var(--metal); }
#players li.turn { border-color: currentColor; box-shadow: 0 0 12px currentColor; }
#players li.out { opacity: 0.4; text-decoration: line-through; }
#players li .dot { width: 0.8rem; height: 0.8rem; }
.ff-btn { pointer-events: auto; align-self: center; margin-top: 0.5rem; padding: 0.55rem 1.3rem; border-radius: 999px; border: 2px solid #ffcf6a; background: rgba(40, 24, 6, 0.92); color: #ffcf6a; font: 800 1rem/1 inherit; letter-spacing: 0.03em; cursor: pointer; box-shadow: 0 0 18px rgba(255, 207, 106, 0.35); animation: ffPulse 1.6s ease-in-out infinite; }
.ff-btn:active { transform: scale(0.96); }
@keyframes ffPulse { 50% { box-shadow: 0 0 28px rgba(255, 207, 106, 0.6); } }
.turn-bar { display: flex; gap: 0.7rem; align-items: baseline; padding: 0.45rem 1rem; border-radius: 999px; background: rgba(14, 8, 9, 0.9); border: 2px solid var(--card-line); white-space: nowrap; }
#turnText { font: 900 1.1rem/1 var(--title); }
#moveText { font-size: 0.85rem; }
#timerBar { width: 60%; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
#timerFill { display: block; height: 100%; background: var(--blood-hot); width: 100%; transition: width 0.25s linear; }
#toast { position: fixed; left: 50%; bottom: calc(1.2rem + var(--safe-b)); transform: translateX(-50%) translateY(150%); opacity: 0; visibility: hidden; background: rgba(14, 8, 9, 0.96); border: 2px solid var(--blood-hot); border-radius: 12px; padding: 0.7rem 1.1rem; z-index: 40; transition: transform 0.25s, opacity 0.25s, visibility 0.25s; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: min(520px, 100%); background: #120b0b; border: 2px solid var(--card-line); border-radius: 20px 20px 0 0; padding: 1.3rem 1.3rem calc(1.3rem + var(--safe-b)); }

@media (max-height: 560px) and (orientation: landscape) {
  .title-wrap { width: min(760px, 100%); grid-template-columns: 1fr 1fr; align-items: start; }
  .title-art { grid-row: span 3; }
}
#gfxSel { width: 100%; padding: 0.7rem 0.8rem; border-radius: 12px; border: 2px solid var(--card-line); background: #0d0708; color: var(--bone); font: 600 1rem var(--serif); }
.how.sp { list-style: none; padding-left: 0; }
