:root {
  /* Neutral base; --accent/--accent-2 are overridden per game (see applyTheme). */
  --bg: #15171c;
  --bg-2: #1c1f26;
  --surface: #23272f;
  --surface-2: #2d323c;
  --border: #353b47;
  --text: #eceef2;
  --text-dim: #a0a7b4;
  --accent: #4b5a70;
  --accent-2: #8a9ab2;
  --good: #3fae6a;
  --warn: #e0a13a;
  --bad: #c43d3d;
  --card: #f7f5f0;
  --card-text: #1f232b;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 700px at 50% -15%, color-mix(in srgb, var(--accent) 30%, var(--bg)) 0%, var(--bg) 65%) fixed;
  transition: background-color .2s ease;
  color: var(--text);
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input, textarea, select { font: inherit; color: inherit; }

button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
button:active { transform: scale(0.97); background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: white;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent);
}
button.danger { background: var(--bad); border-color: transparent; color: white; }
button.ghost { background: transparent; }
button.small { padding: 8px 12px; font-size: 13px; }
button.full { width: 100%; }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease;
  color: var(--text);
}
input::placeholder, textarea::placeholder { color: rgba(160,167,180,0.6); }
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); }
button:focus-visible, .swatch:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 6px; font-weight: 600; letter-spacing: .03em; }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    max(env(safe-area-inset-top), 18px)
    22px
    max(env(safe-area-inset-bottom), 22px);
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 10px;
}
.header h1 {
  font-size: 22px; font-weight: 700; margin: 0;
  letter-spacing: .02em;
  color: var(--text);
}
.header .sub {
  font-size: 12px; color: var(--text-dim); font-weight: 500;
}
.header .actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 18px;
}

/* Lists / cards */
.section-title {
  font-size: 13px; color: var(--text-dim); margin: 18px 0 8px;
  text-transform: uppercase; letter-spacing: .12em;
}
.game-list { display: flex; flex-direction: column; gap: 10px; }
.game-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface) 55%);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent-2);
  border-radius: var(--radius);
  gap: 12px;
}
.game-row .meta { display: flex; flex-direction: column; min-width: 0; }
.game-row .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-row .ts { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.game-row .row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.empty {
  text-align: center; padding: 40px 16px; color: var(--text-dim);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

/* Form cards */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.deck-count {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
}
.deck-count button {
  padding: 12px 0; font-weight: 700;
}
.deck-count button.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent; color: white;
}

.deck-form { margin-bottom: 10px; }
.deck-form .deck-form-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.deck-form .deck-num {
  font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .12em;
}
.help { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Style picker swatches */
.style-picker {
  display: flex; gap: 8px; padding: 4px 0;
  flex-wrap: wrap;
}
.swatch {
  flex: 0 0 auto;
  width: 40px; height: 56px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative; overflow: hidden;
  transition: transform .12s ease, border-color .12s ease;
}
.swatch:active { transform: scale(0.95); }
.swatch.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-2) 30%, transparent);
}
.swatch .swatch-pattern { position: absolute; inset: 0; pointer-events: none; }

.fab-bar {
  position: sticky; bottom: 0; padding: 12px 0 max(env(safe-area-inset-bottom), 8px);
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
  display: flex; gap: 10px;
  margin-top: auto;
}

/* Game view */
.game-top {
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent-2) 35%, var(--border));
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  gap: 10px;
}
.game-top .player { display: flex; flex-direction: column; min-width: 0; }
.game-top .player .label { font-size: 11px; color: var(--accent-2); text-transform: uppercase; letter-spacing: .14em; }
.game-top .player .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.game-top .controls { display: flex; gap: 6px; }

.deck-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  margin-bottom: 16px;
}

/* ---- Deck backs ---- */
.deck {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow), inset 0 0 0 4px rgba(255,255,255,0.06), inset 0 0 0 5px rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease;
  color: var(--text);
}
.deck:active { transform: scale(0.98); }
.deck.empty-deck {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px dashed var(--border);
  box-shadow: none;
}
.deck .deck-name {
  font-weight: 800;
  font-size: 16px;
  text-align: center;
  padding: 14px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
  word-break: break-word;
  z-index: 2;
  position: relative;
}
.deck .deck-count-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.18);
  color: white; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 3px 8px;
  z-index: 3;
}
.deck .discard-badge {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.85); font-size: 10px; font-weight: 700;
  border-radius: 999px; padding: 3px 8px;
  letter-spacing: .08em; text-transform: uppercase;
  z-index: 3;
}

/* Pattern overlay */
.deck-pattern, .swatch-pattern {
  position: absolute; inset: 0; pointer-events: none;
  background-repeat: repeat;
}
.deck-pattern.plain, .swatch-pattern.plain { display: none; }
.deck-pattern.stripes, .swatch-pattern.stripes {
  background-image: repeating-linear-gradient(45deg,
    rgba(255,255,255,0.13) 0 8px, transparent 8px 16px);
}
.deck-pattern.dots, .swatch-pattern.dots {
  background-image: radial-gradient(circle, rgba(255,255,255,0.22) 1.5px, transparent 2px);
  background-size: 12px 12px;
}
.deck-pattern.cross, .swatch-pattern.cross {
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.12) 1px, transparent 1px),
    linear-gradient(-45deg, rgba(255,255,255,0.12) 1px, transparent 1px);
  background-size: 12px 12px;
}
.deck-pattern.weave, .swatch-pattern.weave {
  background-image:
    linear-gradient(90deg, rgba(255,255,255,0.10) 50%, transparent 50%),
    linear-gradient(0deg, rgba(255,255,255,0.10) 50%, transparent 50%);
  background-size: 14px 14px;
}
.deck-pattern.waves, .swatch-pattern.waves {
  background-image: repeating-radial-gradient(circle at 50% 50%,
    transparent 0 6px, rgba(255,255,255,0.10) 6px 8px);
}

/* Icon-based patterns (inline SVG data URIs).
   '%23' = '#' (URL-escaped, required in data: URIs). */
.deck-pattern.hearts, .swatch-pattern.hearts {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'><path d='M12 20s-7-4-9-8.5C1 6.5 4 4 7 4c2 0 4 1.5 5 3 1-1.5 3-3 5-3 3 0 6 2.5 4 7.5-2 4.5-9 8.5-9 8.5z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 28px 28px;
}
.deck-pattern.skulls, .swatch-pattern.skulls {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'><path fill-rule='evenodd' d='M12 3c-3.9 0-7 3.1-7 7v4c0 .6.4 1 1 1v3c0 .6.4 1 1 1h1.5v-2H10v2h4v-2h1.5v2H17c.6 0 1-.4 1-1v-3c.6 0 1-.4 1-1v-4c0-3.9-3.1-7-7-7zm-2.5 7.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3zm5 0a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 30px 30px;
}
.deck-pattern.flowers, .swatch-pattern.flowers {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24'><g fill='%23fff' fill-opacity='0.22'><circle cx='12' cy='5' r='3'/><circle cx='17.5' cy='9' r='3'/><circle cx='15.4' cy='15.5' r='3'/><circle cx='8.6' cy='15.5' r='3'/><circle cx='6.5' cy='9' r='3'/></g><circle cx='12' cy='10.5' r='2' fill='%23fff' fill-opacity='0.35'/></svg>");
  background-size: 36px 36px;
}
.deck-pattern.questions, .swatch-pattern.questions {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 24 24'><text x='12' y='19' font-family='Georgia,serif' font-size='22' font-weight='bold' text-anchor='middle' fill='%23fff' fill-opacity='0.26'>?</text></svg>");
  background-size: 28px 28px;
}
.deck-pattern.stars, .swatch-pattern.stars {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'><path d='M12 2l2.6 7.2H22l-6.2 4.5L18 21l-6-4.4L6 21l2.2-7.3L2 9.2h7.4z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 30px 30px;
}
.deck-pattern.moons, .swatch-pattern.moons {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 24 24'><path d='M16 4a8 8 0 1 0 4 14.5A6.5 6.5 0 0 1 16 4z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 28px 28px;
}
.deck-pattern.diamonds, .swatch-pattern.diamonds {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24'><path d='M12 2l8 10-8 10-8-10z' fill='%23fff' fill-opacity='0.22'/></svg>");
  background-size: 22px 22px;
}
.deck-pattern.spades, .swatch-pattern.spades {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 24 24'><path d='M12 2c-4 5-8 8-8 12a4 4 0 0 0 7 2.7c-.3 1.3-1 2.3-2 3.3h6c-1-1-1.7-2-2-3.3A4 4 0 0 0 20 14c0-4-4-7-8-12z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 28px 28px;
}
.deck-pattern.clubs, .swatch-pattern.clubs {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 24 24'><path d='M12 2a4 4 0 0 0-3 6.7A4 4 0 1 0 11 15c-.3 1.5-1 2.7-2 4h6c-1-1.3-1.7-2.5-2-4a4 4 0 1 0 2-6.3A4 4 0 0 0 12 2z' fill='%23fff' fill-opacity='0.24'/></svg>");
  background-size: 28px 28px;
}
.deck-pattern.bolts, .swatch-pattern.bolts {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 24 24'><path d='M13 2L4 14h6l-1 8 9-12h-6l1-8z' fill='%23fff' fill-opacity='0.26'/></svg>");
  background-size: 26px 26px;
}

/* Colors (deck back gradients) */
.deck-color-blue     { background: linear-gradient(160deg, #1ea3e6 0%, #07598a 100%); }
.deck-color-sky      { background: linear-gradient(160deg, #5fb6e6 0%, #1f7aad 100%); }
.deck-color-teal     { background: linear-gradient(160deg, #4dd0c1 0%, #1a7a73 100%); }
.deck-color-midnight { background: linear-gradient(160deg, #3a4880 0%, #0a0e2a 100%); }
.deck-color-slate    { background: linear-gradient(160deg, #738ba6 0%, #2c3e52 100%); }
.deck-color-forest   { background: linear-gradient(160deg, #4a8c5e 0%, #143821 100%); }
.deck-color-emerald  { background: linear-gradient(160deg, #34d36b 0%, #0d6a39 100%); }
.deck-color-purple   { background: linear-gradient(160deg, #a07cf7 0%, #4a229c 100%); }
.deck-color-magenta  { background: linear-gradient(160deg, #f06aa8 0%, #831843 100%); }
.deck-color-coral    { background: linear-gradient(160deg, #ff8a7a 0%, #c8493a 100%); }
.deck-color-crimson  { background: linear-gradient(160deg, #ec5050 0%, #7f1414 100%); }
.deck-color-wine     { background: linear-gradient(160deg, #a04960 0%, #421018 100%); }
.deck-color-orange   { background: linear-gradient(160deg, #fb923c 0%, #b54608 100%); }
.deck-color-gold     { background: linear-gradient(160deg, #f4c14a 0%, #966a0c 100%); }
.deck-color-cream    { background: linear-gradient(160deg, #f6ecd9 0%, #c4b69a 100%); color: #3d3331; }
.deck-color-cream .deck-name { color: #3d3331; text-shadow: none; }
.deck-color-cream .deck-count-badge,
.deck-color-cream .discard-badge { background: rgba(0,0,0,0.32); color: white; }
.deck-color-taupe    { background: linear-gradient(160deg, #b1a59b 0%, #6f635a 100%); }
.deck-color-brown    { background: linear-gradient(160deg, #6e5e58 0%, #2d2422 100%); }
.deck-color-dark     { background: linear-gradient(160deg, #454b57 0%, #16181d 100%); }

/* ---- Drawn card overlay ---- */
.card-overlay {
  position: fixed; inset: 0;
  background: rgba(12, 13, 16, 0.8);
  backdrop-filter: blur(6px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card-face {
  width: min(360px, 88vw);
  aspect-ratio: 2 / 3;
  background: linear-gradient(180deg, #ffffff, var(--card));
  border-top: 6px solid var(--accent);
  color: var(--card-text);
  border-radius: 18px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.55);
  display: flex; flex-direction: column;
  padding: 22px;
  text-align: center;
  position: relative;
  animation: cardPop .25s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes cardPop {
  from { transform: scale(0.86) rotate(-2deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}
.card-face .card-deck-name {
  position: absolute; top: 12px; left: 14px;
  font-size: 11px; color: var(--accent); font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
}
.card-text-wrap {
  flex: 1; display: flex;
  align-items: center; justify-content: center;
  width: 100%; min-height: 0;
  padding-top: 18px; /* leave room for deck name label */
}
.card-text {
  font-weight: 700;
  line-height: 1.3;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 28px; /* JS will adjust */
  max-width: 100%;
}
.card-actions {
  display: grid; gap: 8px;
  grid-template-columns: 1fr 1fr;
  width: min(360px, 88vw);
  margin-top: 16px;
}
.card-actions button { font-size: 13px; padding: 12px 10px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .15s ease;
}
.modal {
  width: 100%; max-width: 720px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 16px 22px max(env(safe-area-inset-bottom), 22px);
  max-height: 88dvh;
  overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0.5; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { margin: 0 0 12px; font-size: 18px; color: var(--text); }
.modal .actions-stack { display: grid; gap: 8px; }
.modal .grab {
  width: 40px; height: 4px; background: var(--border); border-radius: 2px;
  margin: -6px auto 12px;
}
.discard-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 50vh; overflow-y: auto;
}
.discard-list li {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}
.discard-list li.empty { color: var(--text-dim); text-align: center; font-style: italic; }

/* Toast */
#toast-root {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 80px; z-index: 80;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(35, 39, 47, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn .2s ease, toastOut .2s ease 1.6s forwards;
}
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* Misc */
.spacer { height: 12px; }
.center { text-align: center; }
.muted { color: var(--text-dim); }
.row-tight { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  background: var(--bg-2); color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
}
.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-list .row { gap: 6px; }
.player-list input { flex: 1; }

.checkbox-label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.checkbox-label input { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--accent); }

select { width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.download-link { display: inline-block; padding: 14px 20px; border-radius: 10px; background: var(--accent); color: white; font-weight: 700; text-decoration: none; }
.game-row { flex-wrap: wrap; }
.game-row .meta { flex: 1 1 180px; }
.game-row .row-actions { flex-wrap: wrap; }
.header .actions, .game-top .controls { flex-wrap: wrap; }
.game-top { flex-wrap: wrap; }
.game-top .player { flex: 1 1 150px; }
.card-editor-list { max-height: 55dvh; overflow-y: auto; margin: 12px 0; padding: 2px; }
.card-editor-row { padding: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; }
.card-editor-row textarea { min-height: 90px; user-select: text; }
.card-editor-row button { margin-top: 6px; }
#save-status { position: fixed; bottom: 0; left: 0; right: 0; z-index: 90; display: flex; justify-content: center; align-items: center; gap: 10px; padding: 5px 12px max(5px, env(safe-area-inset-bottom)); background: var(--bg-2); font-size: 12px; min-height: 28px; }
#save-status:empty { display: none; }
#save-status.error { border-top: 2px solid var(--warn); }
.app { padding-bottom: max(60px, env(safe-area-inset-bottom)); }
.fab-bar { bottom: 28px; }
.drawn-player { font-weight: 700; margin-bottom: 10px; text-align: center; overflow-wrap: anywhere; }
.card-overlay { padding-bottom: max(50px, env(safe-area-inset-bottom)); overflow-y: auto; }
.card-face { min-height: 0; flex-shrink: 1; }
.card-actions { flex-shrink: 0; }
.party-mode .app { max-width: 1200px; }
.party-mode .game-top .name { font-size: 28px; white-space: normal; }
.party-mode .deck-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.party-mode .deck { max-height: 65dvh; }
.party-mode .deck .deck-name { font-size: 24px; }
.party-mode .card-face { width: min(760px, 94vw); flex: 1; aspect-ratio: auto; max-height: 70dvh; }
.party-mode .card-actions { width: min(760px, 94vw); }
.party-mode .card-actions button { font-size: 18px; padding: 16px; }
.party-mode .drawn-player { font-size: 26px; }
@media (max-height: 550px) {
  .card-overlay { justify-content: flex-start; }
  .card-face, .party-mode .card-face { min-height: 150px; aspect-ratio: auto; }
  .card-actions { margin-top: 8px; }
  .card-actions button, .party-mode .card-actions button { padding: 8px; font-size: 14px; }
}

.hidden { display: none !important; }

@media (min-width: 600px) {
  .deck-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* Game color picker */
.theme-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.theme-swatch {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
}
.theme-swatch.active { border-color: var(--text); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent-2); }
.theme-swatch:active { background: linear-gradient(160deg, var(--accent-2), var(--accent)); }

.last-players { font-weight: 700; font-size: 16px; margin: 2px 0 14px; overflow-wrap: anywhere; }

/* Rules */
textarea.rules-input { font-family: inherit; min-height: 90px; user-select: text; }
.rules-text {
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; font-size: 15px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  max-height: 60dvh; overflow-y: auto; user-select: text;
}

/* History */
.history-filter { margin-bottom: 10px; }
.history-filter button.active { background: var(--accent); border-color: transparent; color: white; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 58dvh; overflow-y: auto; }
.history-draw { background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: 10px; padding: 10px 12px; }
.history-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; margin-bottom: 4px; }
.history-meta .tag { padding: 2px 8px; font-size: 11px; }
.history-result { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.history-result.open { color: var(--accent-2); }
.history-time { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.history-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.history-marker { display: flex; gap: 8px; padding: 4px 4px; font-size: 12px; font-weight: 700; color: var(--accent-2); text-transform: uppercase; letter-spacing: .08em; }

/* Turn hand-off card */
.turn-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(12, 13, 16, 0.82); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .15s ease; cursor: pointer;
}
.turn-card {
  width: min(360px, 88vw); aspect-ratio: 2 / 3; max-height: 86dvh;
  border-radius: 18px; padding: 22px;
  background: linear-gradient(160deg, var(--accent-2), var(--accent) 60%);
  box-shadow: 0 30px 60px rgba(0,0,0,0.55), inset 0 0 0 6px rgba(255,255,255,0.12);
  color: white; text-align: center;
  display: flex; flex-direction: column;
  animation: cardPop .25s cubic-bezier(.2,.9,.3,1.2);
}
.turn-label { font-size: 12px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; opacity: .85; }
.turn-name-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.turn-name {
  font-weight: 900; line-height: 1.05; text-transform: uppercase; overflow-wrap: anywhere;
  text-shadow: 0 3px 10px rgba(0,0,0,0.35); max-width: 100%;
}
.turn-go { background: rgba(0,0,0,0.25); border-color: rgba(255,255,255,0.3); color: white; }
.party-mode .turn-card { width: min(760px, 94vw); aspect-ratio: auto; height: 80dvh; }

textarea.card-list-input { min-height: 240px; max-height: 60dvh; user-select: text; }

/* ---- Heads Up ---- */
.headsup-steps { margin: 0 0 10px; padding-left: 20px; font-size: 14px; line-height: 1.5; }
.headsup-steps li { margin-bottom: 6px; }
.headsup-score { text-align: center; margin-bottom: 12px; }
.headsup-score-number { font-size: 56px; font-weight: 900; line-height: 1; color: var(--accent-2); }
.scoreboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scoreboard li { display: flex; justify-content: space-between; gap: 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.scoreboard-score { color: var(--accent-2); font-weight: 700; }

.headsup-overlay.count {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: rgba(12, 13, 16, 0.9);
}
.headsup-countdown { font-size: 28vmin; font-weight: 900; color: var(--accent-2); line-height: 1; }

body.headsup-playing { overflow: hidden; }
body.headsup-playing .app { max-width: none; padding: 0; }
body.headsup-playing #save-status { display: none; }
.headsup-round {
  position: fixed; inset: 0; z-index: 55;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 35%, var(--bg)), var(--bg));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(env(safe-area-inset-top), 12px) 16px max(env(safe-area-inset-bottom), 12px);
  text-align: center;
}
.headsup-bar { position: absolute; top: 0; left: 0; right: 0; height: 8px; background: rgba(255,255,255,0.12); }
.headsup-bar-fill { height: 100%; width: 100%; background: var(--accent-2); transition: width .1s linear; }
.headsup-clock { position: absolute; top: 14px; right: 18px; font-size: 32px; font-weight: 900; color: var(--text); text-shadow: 0 2px 8px rgba(0,0,0,0.5); }
.headsup-card {
  font-size: clamp(32px, 9vmax, 92px); font-weight: 900; line-height: 1.1; text-transform: uppercase;
  overflow-wrap: anywhere; max-width: 90vmax; z-index: 2; pointer-events: none;
  text-shadow: 0 4px 16px rgba(0,0,0,0.45);
}
.headsup-card.flash-correct { color: #8ef2a8; }
.headsup-card.flash-pass { color: #ffcf8a; }
.headsup-hint { position: absolute; bottom: 14px; left: 0; right: 0; font-size: 12px; color: var(--text-dim); z-index: 2; pointer-events: none; }
/* Tap targets: the whole top half is correct, the bottom half is pass. */
.headsup-half {
  position: absolute; left: 0; right: 0; height: 50%;
  background: transparent; border: none; border-radius: 0;
  color: rgba(255,255,255,0.28); font-size: 13px; font-weight: 800; letter-spacing: .18em;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 50px;
}
.headsup-half.bottom { top: 50%; align-items: flex-end; padding: 0 0 46px; }
.headsup-half.top { top: 0; }
.headsup-half:active { background: rgba(255,255,255,0.08); }
.headsup-quit { position: absolute; top: 10px; left: 12px; z-index: 3; color: var(--text-dim); }
/* Where the screen cannot be locked to landscape (iPhone, or auto-rotate off),
   turn the round sideways so it reads correctly with the phone held on its side. */
@media (orientation: portrait) {
  .headsup-round {
    inset: auto; top: 0; left: 100vw;
    width: 100vh; height: 100vw;
    width: 100dvh;
    transform-origin: top left; transform: rotate(90deg);
  }
}

.tilt-adjust { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--text-dim); }
.tilt-adjust span { flex: 1; }
.tilt-adjust button { min-width: 40px; font-size: 18px; padding: 4px 10px; }
input.tilt-range { width: 100%; accent-color: var(--accent-2); }
.add-deck { border-style: dashed; margin-bottom: 12px; }

/* ---- Trivia ---- */
.trivia-overlay { justify-content: flex-start; padding-top: max(env(safe-area-inset-top), 18px); }
.card-face.trivia-face { aspect-ratio: auto; min-height: 150px; height: 32dvh; flex-shrink: 0; }
.trivia-options { display: grid; gap: 8px; width: min(520px, 92vw); margin-top: 14px; }
.trivia-options.two { grid-template-columns: 1fr 1fr; }
.trivia-option {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 14px; font-size: 16px; line-height: 1.3; min-height: 54px;
  background: var(--surface); border: 2px solid var(--border); overflow-wrap: anywhere;
}
.trivia-options.two .trivia-option { justify-content: center; text-align: center; font-size: 18px; }
.trivia-letter {
  flex: 0 0 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 45%, var(--surface)); font-size: 13px; font-weight: 800;
}
.trivia-letter:empty { display: none; }
.trivia-option:disabled { opacity: 1; cursor: default; }
.trivia-option.correct { background: color-mix(in srgb, var(--good) 30%, var(--surface)); border-color: var(--good); }
.trivia-option.wrong { background: color-mix(in srgb, var(--bad) 30%, var(--surface)); border-color: var(--bad); }
.trivia-option.dim { opacity: .45 !important; }
.trivia-reveal { padding: 16px; font-size: 17px; }
.trivia-answer {
  padding: 16px; border-radius: 12px; text-align: center; font-size: 20px; font-weight: 800; overflow-wrap: anywhere;
  background: color-mix(in srgb, var(--accent) 25%, var(--surface)); border: 2px solid var(--accent-2);
}
.trivia-self { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trivia-self .trivia-option { justify-content: center; font-weight: 800; }
.trivia-verdict { margin-top: 12px; font-size: 20px; font-weight: 900; text-align: center; overflow-wrap: anywhere; width: min(520px, 92vw); }
.trivia-verdict.correct { color: #7ee2a0; }
.trivia-verdict.wrong { color: #ff9b94; }
.party-mode .trivia-options { width: min(900px, 94vw); }
.party-mode .trivia-option { font-size: 24px; padding: 18px; }
.party-mode .card-face.trivia-face { height: 36dvh; }
@media (min-width: 640px) { .trivia-options:not(.two) { grid-template-columns: 1fr 1fr; } }
.trivia-options.stack { grid-template-columns: 1fr !important; }

/* Heads Up: waiting for the phone to reach a forehead, and the results sheet */
.headsup-card.waiting { font-size: clamp(24px, 6vmax, 56px); color: var(--accent-2); }
.headsup-round.is-waiting .headsup-half { color: transparent; }
.headsup-results-top { display: grid; gap: 12px; }
.headsup-results .headsup-score { margin-bottom: 0; }
.headsup-results-list { margin-top: 14px; max-height: 40dvh; }
@media (orientation: landscape) and (max-height: 560px) {
  /* Sideways phone: score beside the buttons so everything fits without scrolling. */
  .headsup-results-top { grid-template-columns: auto 1fr; align-items: center; }
  .headsup-results .headsup-score-number { font-size: 44px; }
  .headsup-results-list { max-height: 30dvh; }
}
