/* THE DECK. A green card table and real-looking playing cards. The secret menu keeps the original site's look. */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #333333;
  --muted: #777777;
  --flavor: #666666;
  --rule: #eeeeee;
  --border: #dddddd;
  --border-strong: #cccccc;
  --hover: #f5f5f5;
  --primary: #428bca;
  --primary-hover: #3071a9;
  --primary-border: #357ebd;
  --warning: #f0ad4e;
  --warning-hover: #ec971f;
  --warning-border: #eea236;
  --danger: #d9534f;
  --chip-bg: #e6f0f9;
  --chip-text: #2a6496;
  --notice-bg: #d9edf7;
  --notice-border: #bce8f1;
  --notice-text: #31708f;
  --permalink: #88ccee;
  --red-suit: #d0021b;
  --focus: rgba(66, 139, 202, 0.55);
  --toast-bg: rgba(30, 30, 30, 0.92);
  --toast-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141414;
    --panel: #1d1d1d;
    --text: #e6e6e6;
    --muted: #9b9b9b;
    --flavor: #a9a9a9;
    --rule: #2b2b2b;
    --border: #3a3a3a;
    --border-strong: #4a4a4a;
    --hover: #262626;
    --primary: #4a90d9;
    --primary-hover: #5fa0e6;
    --primary-border: #3f83cc;
    --chip-bg: #1e3247;
    --chip-text: #a8cdf3;
    --notice-bg: #142c3a;
    --notice-border: #1f4a60;
    --notice-text: #9fd3ec;
    --red-suit: #ff5c63;
    --toast-bg: rgba(240, 240, 240, 0.95);
    --toast-text: #141414;
  }
}

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif;
  font-size: 16px;
  line-height: 1.42857;
}

body:has(dialog[open]) { overflow: hidden; }

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- the card table: felt, playing cards and piles ---------- */

:root {
  --felt-1: #2b8a55;
  --felt-2: #1b6440;
  --felt-3: #0b3722;
  --on-felt: #f4f7f1;
  --on-felt-muted: rgba(255, 255, 255, 0.72);
  --gold: #f2c14e;
  --gold-text: #2c1d00;
  --card-paper: #fffdf7;
  --card-ink: #23201c;
  --card-red: #c8102e;
  --card-frame: #e8dfcd;
  --back-1: #1f4f8f;
  --back-2: #3a72b8;
}

body {
  background: radial-gradient(ellipse 130% 85% at 50% 0%, var(--felt-1), var(--felt-2) 55%, var(--felt-3)) fixed var(--felt-2);
  color: var(--on-felt);
}
body.viewing { overflow: hidden; }

.screen { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}
/* The left end stays clear for the invisible secret menu button. */
.topbar-spacer { flex: 0 0 64px; }
.gear-btn { display: grid; place-items: center; width: 38px; height: 36px; padding: 0; }
.home-gear { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 2; }
#home { position: relative; }
@media (max-width: 420px) { .code-word { display: none; } }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.topbar-title { flex: 1; text-align: center; font: 700 18px/1 Georgia, "Times New Roman", serif; letter-spacing: 0.14em; }

.back-btn, .icon-btn, .code-pill {
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--on-felt);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.back-btn:hover, .icon-btn:hover, .code-pill:hover { background: rgba(0, 0, 0, 0.32); }
.icon-btn { padding: 4px 12px; font-size: 20px; line-height: 1.2; }
.code-pill { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.code-pill b { color: var(--gold); letter-spacing: 0.14em; }
.code-share { margin-left: 4px; font-size: 13px; opacity: 0.75; }

.btn-block { display: block; width: 100%; }
.btn.btn-gold {
  border-color: #b8862a;
  background: linear-gradient(#f7d36b, #e8b23a);
  color: var(--gold-text);
  font-weight: 700;
  box-shadow: 0 3px 0 #94691a;
}
.btn.btn-gold:not(:disabled):hover { filter: brightness(1.06); }
.btn.btn-gold:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 #94691a; }
.btn.btn-light { border-color: rgba(0, 0, 0, 0.2); background: var(--card-paper); color: var(--card-ink); font-weight: 600; }
.btn.btn-light:not(:disabled):hover { background: #f1ece0; }
.btn.btn-ghost { border-color: rgba(255, 255, 255, 0.4); background: transparent; color: var(--on-felt); }
.btn.btn-ghost:not(:disabled):hover { background: rgba(255, 255, 255, 0.1); }
.btn.btn-danger { border-color: #8f0b21; background: var(--card-red); color: #fff; font-weight: 600; }
.btn-link.light { color: var(--on-felt-muted); }

/* ----- playing cards ----- */

.pc {
  --w: 260px;
  position: relative;
  flex-shrink: 0;
  width: var(--w);
  aspect-ratio: 5 / 7;
  border-radius: calc(var(--w) * 0.065);
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}
.pc-face {
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: var(--card-paper);
  color: var(--card-ink);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 8px 22px rgba(0, 0, 0, 0.35);
}
.pc-face::before {
  content: "";
  position: absolute;
  inset: 4cqi;
  border: max(1px, 0.5cqi) solid var(--card-frame);
  border-radius: 3.5cqi;
  pointer-events: none;
}
.pc-corner { position: absolute; width: 10.5cqi; height: 12.1cqi; overflow: visible; }
.pc-corner.tl { top: 5.5cqi; left: 6cqi; }
.pc-corner.br { right: 6cqi; bottom: 5.5cqi; transform: rotate(180deg); }
.pc-body {
  position: absolute;
  inset: 17cqi 10cqi 15cqi;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  font-size: 6.6cqi;
  line-height: 1.32;
  text-align: center;
  overflow-wrap: anywhere;
}
.pc-title { margin: 0 0 0.45em; font: 700 1.5em/1.12 Georgia, "Times New Roman", serif; }
.pc-text, .pc-flavor { width: 100%; }
.pc p { margin: 0 0 0.45em; }
.pc p:last-child { margin-bottom: 0; }
.pc ol, .pc ul { margin: 0.3em 0; padding-left: 1.2em; text-align: left; }
.pc-flavor { margin-top: 0.5em; color: #6d655a; font-size: 0.88em; font-style: italic; }
.pc .red-suit { color: var(--card-red); }
.pc a { color: var(--back-1); }
.pc .permalink { position: absolute; top: 4cqi; right: 7cqi; color: transparent; font-size: 8cqi; text-decoration: none; }
.pc:hover .permalink, .pc .permalink:focus-visible { color: #8a94a8; }
.pc-missing .pc-body { color: #888; font-style: italic; }

.pc-mini { --w: 72px; }
.pc-mini .pc-body { inset: 20cqi 9cqi 18cqi; font-size: 11cqi; }
.pc-mini .pc-title {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 1.15em;
  line-height: 1.12;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}
.pc-mini .pc-corner { width: 14cqi; height: 16.2cqi; }

.pc-back {
  border: 1px solid rgba(0, 0, 0, 0.35);
  background: var(--back-1);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 6px 16px rgba(0, 0, 0, 0.35);
}
.pc-back::before {
  content: "";
  position: absolute;
  inset: 5cqi;
  border: 1.4cqi solid var(--card-paper);
  border-radius: 4cqi;
  background: var(--back-1) url("../img/back.svg") center / 100% 100% no-repeat;
}
.pc-emblem {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 3cqi 5cqi;
  border-radius: 3cqi;
  background: var(--card-paper);
  color: var(--back-1);
  font: 900 9cqi/1.05 Georgia, serif;
  letter-spacing: 0.06em;
  text-align: center;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1cqi var(--back-1), 0 0 0 1.6cqi var(--card-paper);
}

/* Turning a card over: the back faces up first, then it flips to show the face. */
.flip { display: inline-block; perspective: 1400px; }
.flip.fresh { animation: deal-in 0.35s ease-out; }
.flip-inner {
  position: relative;
  display: grid;
  transform: rotateY(180deg);
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.2, 0.75, 0.25, 1);
}
.flip.up .flip-inner { transform: rotateY(0); }
.flip-inner > .pc { grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-inner > .flip-back { transform: rotateY(180deg); }
@keyframes deal-in {
  from { opacity: 0.2; transform: translateY(40px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

/* ----- piles ----- */

.piles { display: flex; justify-content: center; gap: 30px; margin: 4px 0 12px; }
.pile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 84px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.pile:disabled { cursor: default; }
.pile .pc { --w: 84px; }
.pile-stack { position: relative; border-radius: calc(84px * 0.065); transition: transform 0.15s; }
.pile-stack .pc { box-shadow: none; }
.pile-stack.active { animation: nudge 2.4s ease-in-out infinite; }
.pile:not(:disabled):hover .pile-stack { transform: translateY(-3px); }
.pile-empty { width: 84px; aspect-ratio: 5 / 7; border: 2px dashed rgba(255, 255, 255, 0.3); border-radius: 6px; }
.pile-label { color: var(--on-felt-muted); font-size: 13px; }
.can-draw .pile-label { color: var(--gold); font-weight: 700; }
.discard-top { transform: rotate(4deg); }
@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ----- home ----- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(26px + env(safe-area-inset-top)) 16px 16px;
  text-align: center;
}
.logo {
  margin: 12px 0 6px;
  color: var(--card-paper);
  font: 900 clamp(42px, 13vw, 66px)/1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.08em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.28);
}
.tagline { margin: 0 0 12px; color: var(--on-felt-muted); font-size: 17px; }
.home-deck { position: relative; width: 240px; height: 178px; margin: 6px auto 16px; }
.home-deck .hd { --w: 102px; position: absolute; top: 12px; left: 50%; margin-left: -51px; transition: transform 0.35s ease; }
.hd1 { transform: translateX(-54px) rotate(-17deg); }
.hd2 { transform: translateX(-18px) rotate(-6deg); }
.hd3 { transform: translate(18px, 3px) rotate(6deg); }
.hd4 { transform: translate(54px, 10px) rotate(17deg); }
.home-deck:hover .hd1 { transform: translateX(-66px) rotate(-22deg); }
.home-deck:hover .hd4 { transform: translate(66px, 12px) rotate(22deg); }

.panel {
  width: 100%;
  max-width: 360px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.22);
  text-align: left;
}
.panel .field-label { color: var(--on-felt-muted); font-weight: 600; }
.panel #name-input { width: 100%; margin-bottom: 12px; }
.join-row { display: flex; gap: 8px; margin-top: 10px; }
.join-row input { flex: 1; min-width: 0; font-weight: 700; letter-spacing: 0.2em; text-align: center; }
.join-row .btn { padding-inline: 20px; }
.home-msg { margin: 10px 0 0; color: var(--gold); font-size: 14px; text-align: center; }
.home-msg:empty { display: none; }
.or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--on-felt-muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.18); }
.how { max-width: 360px; margin: 16px auto 0; color: var(--on-felt-muted); font-size: 14px; line-height: 1.45; }
.felt-footer { padding: 12px 10px calc(12px + env(safe-area-inset-bottom)); color: var(--on-felt-muted); font-size: 13px; text-align: center; }
.felt-footer a { color: inherit; }

/* ----- one phone ----- */

.solo {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom));
}
.card-stage { display: flex; justify-content: center; margin: 2px 0 18px; }
.card-stage .pc { --w: min(78vw, 330px, calc((100dvh - 330px) / 1.4 * 1)); }
.card-slot {
  display: grid;
  place-items: center;
  width: min(78vw, 330px, calc((100dvh - 330px) / 1.4));
  aspect-ratio: 5 / 7;
  padding: 20px;
  border: 2px dashed rgba(255, 255, 255, 0.28);
  border-radius: 18px;
  color: var(--on-felt-muted);
}
#draw-button { min-width: 220px; }
.notice {
  max-width: 420px;
  margin: 0 0 10px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--on-felt);
  text-align: center;
}

/* ----- lobby ----- */

.room-status { margin: 0 16px 8px; padding: 8px 12px; border-radius: 10px; background: rgba(0, 0, 0, 0.3); font-size: 14px; text-align: center; }
.lobby, .table { width: 100%; max-width: 640px; margin: 0 auto; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }
.room-heading { margin: 6px 0 10px; font: 700 22px/1.2 Georgia, serif; }
.lobby-players { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; padding: 0; list-style: none; }
.lobby-players li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
}
.lobby-players li.away { opacity: 0.6; }
.lp-name { font-size: 17px; font-weight: 700; }
.lobby-players .btn-link { margin-left: auto; color: var(--on-felt-muted); font-size: 14px; }
.lobby-players .btn-link.danger { color: #ffb4b4; }
.lobby-players .btn-link + .btn-link { margin-left: 0; }
.tag { padding: 2px 7px; border-radius: 999px; background: var(--gold); color: var(--gold-text); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.tag.you { background: var(--card-paper); color: var(--card-ink); }
.tag.away { background: rgba(255, 255, 255, 0.2); color: var(--on-felt); }
.tag.relay { background: #2a5bd7; color: #fff; }
.rules-panel {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  text-align: left;
}
.rules-help { margin: 0 0 10px; color: var(--on-felt-muted); font-size: 14px; }
.rule-groups, .rule-style { display: flex; flex-direction: column; gap: 8px; }
.rule-style { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.rule-check { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.rule-check input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--gold); }
.rule-check small { margin-left: auto; color: var(--on-felt-muted); white-space: nowrap; }
.rule-check:has(input:disabled) { cursor: default; }
.lobby-wait { margin: 12px 0 0; color: var(--on-felt-muted); text-align: center; }
.area-label { margin: 0 0 8px; color: var(--on-felt-muted); font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }

/* ----- the table ----- */

.players-strip { display: flex; gap: 8px; margin: 0 -16px 10px; padding: 2px 16px 6px; overflow-x: auto; list-style: none; scrollbar-width: none; }
.players-strip::-webkit-scrollbar { display: none; }
.seat { flex: 0 0 auto; min-width: 92px; padding: 7px 12px; border: 2px solid transparent; border-radius: 12px; background: rgba(0, 0, 0, 0.22); }
.seat.turn { border-color: var(--gold); background: rgba(242, 193, 78, 0.16); }
.seat.away { opacity: 0.5; }
.seat.me .seat-name { color: var(--gold); }
.seat-name { display: block; font-size: 15px; font-weight: 700; white-space: nowrap; }
.seat-info { display: block; color: var(--on-felt-muted); font-size: 12px; white-space: nowrap; }
.looking { color: var(--gold); }
.crown { margin-right: 4px; color: var(--gold); }
.mini-back { display: inline-block; width: 9px; height: 12px; margin-right: 4px; border: 1px solid var(--card-paper); border-radius: 2px; background: var(--back-2); vertical-align: -2px; }
.turn-banner { margin: 4px 0 12px; font: 700 18px/1.3 Georgia, serif; text-align: center; }
.turn-banner.mine { color: var(--gold); }
.turn-actions { display: flex; justify-content: center; margin: 0 0 12px; }
.turn-actions:not(:has(> :not([hidden]))) { display: none; }
#end-turn-btn { min-width: 200px; }
.pending-pill {
  display: block;
  margin: 0 auto 12px;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: var(--gold-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  animation: nudge 1.6s ease-in-out infinite;
}
.table-area, .hand-area { margin-bottom: 12px; padding: 10px 12px 12px; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px; background: rgba(0, 0, 0, 0.16); }
.card-strip { display: flex; gap: 10px; padding: 4px 2px 6px; overflow-x: auto; }
.card-btn { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; gap: 4px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.card-btn .pc { --w: 76px; transition: transform 0.15s; }
.card-btn:hover .pc, .card-btn:focus-visible .pc { transform: translateY(-5px); }
.card-by { max-width: 76px; overflow: hidden; color: var(--on-felt-muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.hand .card-btn + .card-btn { margin-left: -20px; }
.hand .card-btn:nth-child(odd) .pc { transform: rotate(-2deg); }
.hand .card-btn:nth-child(even) .pc { transform: rotate(2deg) translateY(2px); }
.hand .card-btn:hover .pc { transform: translateY(-6px); }
.area-empty { margin: 4px 0; color: var(--on-felt-muted); font-size: 14px; }
.hand-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.hand-head .area-label { margin: 0; }
.game-log { display: flex; flex-direction: column; gap: 2px; margin: 0 0 12px; padding: 0; color: var(--on-felt-muted); font-size: 13px; text-align: center; list-style: none; }
.game-log li:first-child { color: var(--on-felt); font-size: 14px; }

/* ----- settings ----- */

dialog.settings {
  width: min(440px, calc(100% - 24px));
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background: color-mix(in srgb, var(--felt-3) 88%, #000);
  color: var(--on-felt);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
dialog.settings::backdrop { background: rgba(0, 0, 0, 0.5); }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.settings-head h2 { margin: 0; font: 700 22px/1.2 Georgia, serif; }
.settings .close { color: var(--on-felt); opacity: 0.7; }
.settings-note { margin: 12px 0 16px; color: var(--on-felt-muted); font-size: 13px; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 12px 10px; }
.swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.swatch-felt {
  position: relative;
  width: 100%;
  aspect-ratio: 1.35;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: radial-gradient(ellipse 130% 90% at 50% 0%, var(--sw1), var(--sw2) 55%, var(--sw3));
}
.swatch:hover .swatch-felt { transform: translateY(-2px); }
.swatch[aria-pressed="true"] .swatch-felt { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.swatch[aria-pressed="true"] .swatch-felt::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.swatch-custom:not(.has-color) .swatch-felt { background: conic-gradient(#e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935); }
.swatch-custom input { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.menu .swatch-felt { border-color: rgba(0, 0, 0, 0.15); }

/* ----- the card viewer ----- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: color-mix(in srgb, var(--felt-3) 78%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.viewer-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; max-width: 420px; margin: auto; }
.viewer-label { margin: 0; color: var(--on-felt); font: 700 18px/1.3 Georgia, serif; text-align: center; }
.viewer-card .pc { --w: min(76vw, 320px, calc((100dvh - 250px) / 1.4)); }
.viewer-card:empty { display: none; }
.viewer-small .pc { --w: 110px; }
.viewer-body { width: 100%; }
.viewer-body:empty { display: none; }
.viewer-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.viewer-actions .btn { flex: 1 1 130px; min-height: 46px; font-size: 16px; }
.viewer-actions .btn-link { flex-basis: 100%; padding: 6px; font-size: 14px; text-align: center; }
.give-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.give-list .btn { min-height: 48px; font-size: 16px; text-align: left; }
.give-list small { color: #666; font-weight: 400; }
.viewer-note { margin: 0; color: var(--on-felt-muted); font-size: 14px; text-align: center; }
.rules-panel.in-viewer { margin: 0; }

body.in-room .card-editor [data-act="show-card"] { display: none; }

/* The secret menu: an invisible spot in the top-left corner. Tap it 7 times in a row (app.js). */
#options-button {
  position: absolute;
  top: env(safe-area-inset-top);
  left: env(safe-area-inset-left);
  z-index: 5;
  width: 64px;
  height: 56px;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  font-size: 1px;
  cursor: default;
  opacity: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  width: max-content;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 18px;
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- buttons and inputs ---------- */

.btn {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-size: 14px;
  line-height: 1.42857;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-lg { padding: 10px 16px; font-size: 18px; line-height: 1.33; border-radius: 6px; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 3px; }

.btn-primary { background: var(--primary); border-color: var(--primary-border); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-primary:not(:disabled):active { transform: translateY(1px); }

.btn-default { background: var(--panel); border-color: var(--border-strong); color: var(--text); }
.btn-default:not(:disabled):hover { background: var(--hover); }

.btn-warning { background: var(--warning); border-color: var(--warning-border); color: #fff; }
.btn-warning:hover { background: var(--warning-hover); }

.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:not(:disabled):hover { background: var(--danger); color: #fff; }

.btn-link, .btn.btn-link {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

input[type="text"], input[type="search"], input[type="password"], select, textarea {
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px keeps iPhones from zooming in */
}
textarea { width: 100%; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }


/* ---------- the secret menu ---------- */

dialog.menu {
  width: min(640px, calc(100% - 20px));
  max-height: calc(100% - 60px);
  padding: 0;
  overflow: hidden; /* only .menu-body scrolls, so the header and Done button always stay put */
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}
dialog.menu[open] { display: flex; flex-direction: column; }
dialog.menu::backdrop { background: rgba(0, 0, 0, 0.5); }

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px 10px;
}
.menu-head h2 { margin: 0; font-size: 18px; font-weight: 500; }

.close {
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 28px;
  font-weight: bold;
  line-height: 1;
  opacity: 0.4;
  cursor: pointer;
}
.close:hover { opacity: 0.8; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 15px;
  border-bottom: 1px solid var(--border);
}
.tabs [role="tab"] {
  margin-bottom: -1px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 4px 4px 0 0;
  background: none;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
}
.tabs [role="tab"]:hover { background: var(--hover); }
.tabs [role="tab"][aria-selected="true"] {
  border-color: var(--border) var(--border) var(--panel);
  background: var(--panel);
  color: var(--text);
  cursor: default;
}

.menu-body {
  position: relative; /* keeps the hidden screen-reader labels inside the scrolling area */
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 15px;
}

.menu-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  border-top: 1px solid var(--rule);
}
.save-status { flex: 1; color: var(--muted); font-size: 13px; }
.version { color: var(--muted); font-size: 12px; opacity: 0.7; }

@media (max-width: 600px) {
  dialog.menu {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .menu-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .card-row { scroll-margin-top: 115px; }
  .menu-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

.control-group { padding-bottom: 15px; margin-bottom: 15px; border-bottom: 1px solid var(--rule); }
.control-group:last-child { border-bottom: 0; margin-bottom: 0; }
.control-label { margin: 0 0 8px; font-size: 15px; font-weight: bold; }

.help-block { display: block; margin: 2px 0 8px; color: var(--muted); font-size: 14px; }

.radio, .checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.radio input, .checkbox input { width: 18px; height: 18px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--primary); }
.radio .help-block { margin: 0; }

.group-list { margin: 12px 0; }
.group-row { padding: 8px 0; border-top: 1px solid var(--rule); }
.group-row:last-child { border-bottom: 1px solid var(--rule); }
.group-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.group-line .checkbox { flex: 1 1 200px; margin: 0; }
.group-name { font-weight: 500; overflow-wrap: anywhere; }
.group-row.is-off .group-name { color: var(--muted); }
.group-actions { display: flex; gap: 6px; font-size: 13px; }
.group-line .rename-form { flex: 1 1 100%; }

.cards-affected {
  margin: 4px 0 0;
  padding-left: 26px;
  list-style: none;
  font-size: 14px;
  line-height: 1.6;
}
.cards-affected a { color: var(--muted); text-decoration: none; }
.cards-affected a:hover { color: var(--primary); text-decoration: underline; }
.group-row.is-off .cards-affected { opacity: 0.6; }

.empty { margin: 4px 0; padding-left: 26px; color: var(--muted); font-size: 14px; }

.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.inline-form input { flex: 1 1 180px; min-width: 0; }

.form-msg { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.form-msg:empty { display: none; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row:not(:has(> :not([hidden]))) { display: none; }

.draft-actions { margin-bottom: 12px; }

.sync-box {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.sync-box .help-block { margin-top: 0; }
.connect-form { margin-top: 10px; }
.connect-form .help-block { margin: 8px 0 0; }
.connect-form input { font-family: ui-monospace, Menlo, Consolas, monospace; }
.steps { margin: 0 0 10px; padding-left: 1.4em; font-size: 14px; line-height: 1.5; }
.steps li { margin-bottom: 4px; }

/* ---------- card editor ---------- */

.editor-toolbar {
  position: sticky;
  top: -15px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -15px 0 0;
  padding: 15px 0 10px;
  background: var(--panel);
}
.editor-toolbar input { flex: 1 1 160px; min-width: 0; }
.editor-toolbar select { flex: 0 1 210px; min-width: 0; }
.editor-toolbar .btn { min-height: 38px; }

.card-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--rule); }
.card-list > .empty { padding: 16px 4px; }
.card-row { border-bottom: 1px solid var(--rule); scroll-margin-top: 70px; }
.card-row.open { background: var(--hover); }

.card-row-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 6px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.card-row-head:hover { background: var(--hover); }
.row-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-snippet {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.row-groups { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.row-groups:empty { display: none; }
.row-chevron::before {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
.card-row.open .row-chevron::before { transform: rotate(45deg); }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 12px;
  white-space: nowrap;
}

.card-editor { padding: 6px 8px 16px; }

.field { min-width: 0; margin: 0 0 14px; padding: 0; border: 0; }
.field-label { display: block; margin-bottom: 4px; padding: 0; font-size: 14px; font-weight: 600; }
.field input[type="text"] { width: 100%; }
.optional { color: var(--muted); font-weight: normal; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* A group in the card editor is a checkbox drawn as a pill. Checked = this card is in the group. */
.chip-check { position: relative; display: inline-flex; cursor: pointer; }
.chip-check input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip-check span {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--panel);
  font-size: 14px;
  line-height: 1.3;
  user-select: none;
}
.chip-check input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
.chip-check input:checked + span::before { content: "✓ "; }
.chip-check input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip-check:hover input:not(:checked) + span { border-color: var(--primary); }

.chip-add {
  padding: 6px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
}
.chip-add:hover { border-color: var(--primary); }
.new-group-form { margin-top: 10px; }
.group-help { margin: 8px 0 0; }

.preview {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.pv-title { margin-bottom: 4px; font-size: 20px; font-weight: bold; overflow-wrap: anywhere; }
.pv-text { overflow-wrap: anywhere; }
.preview p { margin: 0 0 0.5em; }
.preview p:last-child { margin-bottom: 0; }
.preview ol, .preview ul { margin: 0.5em 0; padding-left: 1.5em; }
.preview .red-suit { color: var(--red-suit); font-style: normal; }
.pv-flavor { margin-top: 6px; color: var(--flavor); font-style: italic; overflow-wrap: anywhere; }

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