/**
 * app.css — Paciência.online design system and game screen.
 * Tokens and components follow docs/design-spec.md (design/prototypes/tokens.css + ui.css).
 * Pure vanilla CSS. No dependencies.
 */

/* ─── Design Tokens ──────────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  /* Felt (table) — default: verde. Alternatives via [data-felt]. */
  --felt: #0E7A3E;
  --felt-light: #13914C;
  --felt-deep: #085A2C;

  /* UI surfaces */
  --page: #07170D;
  --nav-bg: rgba(8, 24, 14, 0.92);
  --panel: #0F2216;
  --panel-raised: #15301F;
  --scrim: rgba(3, 12, 7, 0.62);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --control: rgba(255, 255, 255, 0.07);
  --control-hover: rgba(255, 255, 255, 0.13);

  /* Text */
  --text: #F3F6F3;
  --text-muted: #A7B6AA;
  --text-dim: #7D9382;

  /* Accents */
  --gold: #D4A020;
  --gold-hover: #E4B43C;
  --gold-ink: #1B1606;
  --gold-soft: rgba(212, 160, 32, 0.14);
  --red: #E85D45;
  --success: #6FD394;
  --focus: #F2D27A;

  /* Cards (mirrors js/engine/CardRenderer.js) */
  --card-bg: #FFFFFF;
  --card-stroke: #D6DCD7;
  --card-red: #D23A2E;
  --card-black: #16201A;
  --card-dark-bg: #1A221D;
  --card-dark-stroke: #33413A;
  --card-dark-red: #FF6B5C;
  --card-dark-black: #EEF2EF;

  /* Type */
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 17px;
  --fs-lg: 20px;
  --fs-xl: 28px;
  --fs-2xl: 40px;
  --fs-3xl: 56px;

  /* Spacing (4px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* Elevation */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.22);
  --shadow-panel: 0 24px 60px -16px rgba(0, 0, 0, 0.6);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 120ms;
  --dur-base: 220ms;

  /* Layout */
  --nav-h: 56px;
  --sidebar-w: 300px;
}

[data-felt="azul"] {
  --felt: #15577F;
  --felt-light: #1B6A99;
  --felt-deep: #0B3A57;
  --page: #061420;
  --panel: #0E1F2C;
  --panel-raised: #142B3C;
  --nav-bg: rgba(6, 18, 28, 0.92);
}

[data-felt="vinho"] {
  --felt: #7C2233;
  --felt-light: #932A3E;
  --felt-deep: #561623;
  --page: #1A070C;
  --panel: #2A1117;
  --panel-raised: #391820;
  --nav-bg: rgba(26, 7, 12, 0.92);
}

/* ─── Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 { text-wrap: balance; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

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

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ─── Icons ──────────────────────────────────────────────────────────── */
.ic {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ic.lg { width: 20px; height: 20px; }

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn-primary { background: var(--gold); color: var(--gold-ink); }
.btn-primary:hover { background: var(--gold-hover); }

.btn-secondary { background: var(--control); border-color: var(--line-strong); color: var(--text); }
.btn-secondary:hover { background: var(--control-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--control); }

.btn-lg { height: 48px; padding: 0 20px; font-size: 15px; border-radius: var(--r-lg); }
.btn-block { width: 100%; }

.nav-btn { height: 36px; padding: 0 14px; font-size: 14px; border-radius: var(--r-md); }
.nav-btn.icon-only { width: 36px; padding: 0; }

/* ─── Game Screen (felt) ─────────────────────────────────────────────── */
.felt {
  background: radial-gradient(120% 90% at 40% 30%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-deep) 100%);
}

#game-screen {
  height: 100vh;
  height: 100dvh;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── Navbar ─────────────────────────────────────────────────────────── */
.navbar {
  position: relative;
  z-index: 5;
  flex: none;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 0 max(var(--s-6), env(safe-area-inset-right)) 0 max(var(--s-6), env(safe-area-inset-left));
  background: var(--nav-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-sm);
}

.brand-spade { width: 22px; height: 22px; flex: none; fill: var(--gold); }
.brand-word { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: -0.01em; line-height: 1; }
.brand-tld { font-weight: 500; font-size: 14px; color: var(--text-muted); }

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.narrow-only { display: none; }

/* ─── Layout ─────────────────────────────────────────────────────────── */
#app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  gap: var(--s-5);
  padding: var(--s-5) max(var(--s-5), env(safe-area-inset-right)) var(--s-5) max(var(--s-5), env(safe-area-inset-left));
}

#game-workspace {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-height: 0;
  min-width: 0;
}

.table {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--r-lg);
  background: rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 2px 12px rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* no swipe navigation / double-tap zoom on the table */
}

/* ─── Score Bar ──────────────────────────────────────────────────────── */
.scorebar {
  flex: none;
  height: 64px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  background: var(--nav-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-label .ic { width: 12px; height: 12px; }
.label-short { display: none; }

.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

/* ─── Sidebar ────────────────────────────────────────────────────────── */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.wins {
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background: var(--nav-bg);
}

.wins h2 {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.wins-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.wins-big {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 44px;
  font-weight: 600;
  color: var(--gold);
  line-height: 1;
}

.streak {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.streak b {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text);
}

.streak .ic { width: 14px; height: 14px; color: var(--gold); }

/* ─── Ad Slots (reserved sizes, never over the table) ────────────────── */
.ad-slot {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ad-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.ad-frame,
.ad-frame .adsbygoogle {
  display: block;
  width: var(--ad-w);
  height: var(--ad-h);
}

.ad-frame {
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.16);
  border: 1px dashed var(--line-strong);
}

.ad-frame.filled {
  background: transparent;
  border: none;
}

#ad-bottom {
  --ad-w: 728px;
  --ad-h: 90px;
  margin-top: var(--s-1); /* extra gap so card drags don't end on the ad */
}

#ad-sidebar {
  --ad-w: 300px;
  --ad-h: 250px;
}

/* Tall desktop screens: half-page sidebar ad */
@media (min-width: 1024px) and (min-height: 900px) {
  #ad-sidebar { --ad-h: 600px; }
}

/* Wide desktop screens: billboard-width bottom strip */
@media (min-width: 1400px) {
  #ad-bottom { --ad-w: 970px; }
}

/* Short desktop screens: sidebar ad only, keep the table at ~70% height */
@media (min-width: 1024px) and (max-height: 799px) {
  #ad-bottom { display: none; }
}

/* ─── Overlays & Modals ──────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(var(--s-4), env(safe-area-inset-top)) max(var(--s-4), env(safe-area-inset-right)) max(var(--s-4), env(safe-area-inset-bottom)) max(var(--s-4), env(safe-area-inset-left));
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: overlayIn var(--dur-base) var(--ease-out);
}

.modal {
  width: min(100%, var(--modal-w, 440px));
  margin-block: auto; /* centred when it fits; scrolls from the top when taller than the screen */
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-panel);
  padding: var(--s-8);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  animation: modalIn var(--dur-base) var(--ease-out);
}

.modal:focus { outline: none; }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
}

.modal-head .btn-ghost { margin: -6px -10px 0 0; }

.modal-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.modal-sub { color: var(--text-muted); }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.sheet-grip { display: none; }

.eyebrow {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.chip {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--gold-soft);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}

.chip:empty { display: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Menu */
.menu-modal { --modal-w: 400px; }

.menu-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  text-align: center;
}

.spade-lg { width: 44px; height: 44px; fill: var(--gold); }

.menu-title h2 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.menu-title h2 span {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-muted);
}

.menu-title p { color: var(--text-muted); font-size: 14px; }

.btn.continue {
  flex-direction: column;
  height: auto;
  min-height: 56px;
  padding: 10px 20px;
  gap: 2px;
}

.continue small {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.75;
}

.continue small:empty { display: none; }

.menu-modal .btn-lg .chip { margin-left: auto; }
.menu-modal .btn-lg:has(.chip:not(:empty)) { justify-content: flex-start; }

.menu-foot {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

/* Win */
.win-modal { --modal-w: 460px; }

.kings {
  display: flex;
  justify-content: center;
  height: 96px;
  margin-bottom: -8px;
}

.kings .mini-card {
  --w: 64px;
  margin: 0 -14px;
  transform-origin: 50% 120%;
}

.kings .mini-card:nth-child(1) { transform: rotate(-15deg); }
.kings .mini-card:nth-child(2) { transform: rotate(-5deg) translateY(-6px); }
.kings .mini-card:nth-child(3) { transform: rotate(5deg) translateY(-6px); }
.kings .mini-card:nth-child(4) { transform: rotate(15deg); }

.win-modal:not([data-reduced]) .kings .mini-card {
  animation: kingIn 520ms var(--ease-out) both;
}

.win-modal .kings .mini-card:nth-child(2) { animation-delay: 60ms; }
.win-modal .kings .mini-card:nth-child(3) { animation-delay: 120ms; }
.win-modal .kings .mini-card:nth-child(4) { animation-delay: 180ms; }

@keyframes kingIn {
  from { opacity: 0; translate: 0 24px; }
  to { opacity: 1; translate: 0 0; }
}

.win-title {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.win-title h2 {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.win-title p { color: var(--text-muted); }

.win-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-2);
}

.win-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-3) var(--s-2);
  border-radius: var(--r-md);
  background: var(--panel-raised);
  text-align: center;
  min-width: 0;
}

.win-stat span:first-child {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.win-stat span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-lg);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.win-stat.gold span:last-child { color: var(--gold); }
.win-stat.green span:last-child { color: var(--success); }

.win-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
}

#survey-slot:empty { display: none; }

.fake-door {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  align-self: center;
  min-height: 32px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.fake-door:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.fake-door .ic { width: 14px; height: 14px; }

/* Survey card */
.survey {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5) var(--s-5);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.01));
}

.survey-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.survey-q {
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.35;
}

.survey-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-2);
}

.survey-choices.cols-2 { grid-template-columns: repeat(2, 1fr); }
.survey-choices.cols-5 { grid-template-columns: repeat(5, 1fr); }
.survey-choices.cols-11 { grid-template-columns: repeat(6, 1fr); }

.choice {
  min-height: 40px;
  padding: 0 8px;
  border-radius: var(--r-md);
  background: var(--control);
  border: 1px solid var(--line-strong);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}

.choice:hover { background: var(--control-hover); border-color: rgba(255, 255, 255, 0.28); }
.choice[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }

.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: -4px;
}

.survey-other { display: flex; gap: var(--s-2); }
.survey-other .input { flex: 1; min-width: 0; height: 40px; }
.survey-send { align-self: flex-end; }

.survey-skip {
  min-height: 32px;
  padding: 0 4px;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--text-dim);
}

.survey-skip:hover { color: var(--text-muted); text-decoration: underline; }

.survey-done {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  color: var(--text-muted);
  font-size: 14px;
}

.survey-done .ic { width: 20px; height: 20px; color: var(--success); }

/* Fake door */
.door-modal { --modal-w: 420px; }

.door-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--r-lg);
  background: var(--gold-soft);
  color: var(--gold);
}

.price { display: flex; align-items: baseline; gap: 6px; margin-top: calc(var(--s-6) * -0.5); }
.price b { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 32px; font-weight: 600; }
.price span { color: var(--text-muted); font-size: 14px; }

.fine { font-size: 12px; color: var(--text-dim); }

.done-state {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: rgba(111, 211, 148, 0.08);
  border: 1px solid rgba(111, 211, 148, 0.25);
}

.done-state .ic { color: var(--success); margin-top: 3px; }
.done-state p { font-size: 14px; color: var(--text-muted); }
.done-state strong { color: var(--text); }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }

.input {
  height: 44px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 16px; /* 16px avoids iOS zoom on focus */
  user-select: text;
  -webkit-user-select: text;
}

.input::placeholder { color: var(--text-dim); }
.input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.input[aria-invalid="true"] { border-color: var(--red); }

.field-error { font-size: 12px; color: var(--red); }
.field-error:empty { display: none; }

/* Settings */
.settings-modal { --modal-w: 460px; }

.setting { display: flex; flex-direction: column; gap: var(--s-3); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.setting-text { display: flex; flex-direction: column; }
.setting-title { font-size: 14px; font-weight: 600; }
.setting-help { font-size: 12px; color: var(--text-dim); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
}

.segmented button {
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
}

.segmented button[aria-pressed="true"] {
  background: var(--panel-raised);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--line-strong);
}

.style-options { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }

.style-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.style-option .mini {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--felt);
}

.style-option .mini-card { --w: 40px; }
.style-option[aria-pressed="true"] { border-color: var(--gold); color: var(--text); box-shadow: 0 0 0 1px var(--gold); }

.swatches { display: flex; gap: var(--s-3); }

.swatch-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 48px;
  border: 0;
  background: none;
  font-size: 12px;
  color: var(--text-muted);
}

.swatch-opt i {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.swatch-verde { background: radial-gradient(circle at 40% 30%, #13914C, #085A2C); }
.swatch-azul { background: radial-gradient(circle at 40% 30%, #1B6A99, #0B3A57); }
.swatch-vinho { background: radial-gradient(circle at 40% 30%, #932A3E, #561623); }

.swatch-opt[aria-pressed="true"] { color: var(--text); }
.swatch-opt[aria-pressed="true"] i { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--gold); }

.toggle {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border: 0;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.16);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: transform var(--dur-base) var(--ease-out);
}

.toggle[aria-checked="true"] { background: var(--gold); }
.toggle[aria-checked="true"]::after { transform: translateX(18px); }

.divider { height: 1px; border: 0; background: var(--line); }

/* Sheet items ("Mais") */
.more-modal { --modal-w: 400px; gap: var(--s-3); }

.sheet-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 52px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--r-md);
  background: var(--control);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
}

.sheet-item:hover { background: var(--control-hover); }
.sheet-item .ic { color: var(--gold); }
.sheet-item small { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--text-dim); }

/* ─── Mini cards (CSS twins of the canvas cards) ─────────────────────── */
.mini-card {
  --w: 64px;
  position: relative;
  display: block;
  flex: none;
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: max(4px, calc(var(--w) * 0.08));
  background: var(--card-bg);
  box-shadow: inset 0 0 0 1px var(--card-stroke), var(--shadow-card);
  color: var(--card-black);
}

.mini-card.red { color: var(--card-red); }
.mini-card.dark { background: var(--card-dark-bg); box-shadow: inset 0 0 0 1px var(--card-dark-stroke), var(--shadow-card); color: var(--card-dark-black); }
.mini-card.dark.red { color: var(--card-dark-red); }
.mini-card svg { display: block; fill: currentColor; }

.mini-card .idx {
  position: absolute;
  left: max(3px, calc(var(--w) * 0.07));
  top: max(2px, calc(var(--w) * 0.04));
  display: flex;
  align-items: center;
  gap: max(1px, calc(var(--w) * 0.02));
  font: 700 max(13px, calc(var(--w) * 0.24)) / 1.15 var(--font-ui);
  letter-spacing: -0.02em;
}

.mini-card .idx svg { width: max(10px, calc(var(--w) * 0.17)); height: max(10px, calc(var(--w) * 0.17)); }

.mini-card .pip {
  position: absolute;
  width: calc(var(--w) * 0.52);
  height: calc(var(--w) * 0.52);
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%);
}

.mini-card .face {
  position: absolute;
  left: 0;
  right: 0;
  top: 62%;
  transform: translateY(-50%);
  text-align: center;
  font: 600 calc(var(--w) * 0.5) / 1 var(--font-ui);
  letter-spacing: -0.02em;
}

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  z-index: 200;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: var(--r-pill);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ─── Phones & tablets (< 1024px) ────────────────────────────────────── */
@media (max-width: 1023px) {
  :root { --nav-h: 52px; }

  .navbar { padding: 0 max(var(--s-3), env(safe-area-inset-right)) 0 max(var(--s-3), env(safe-area-inset-left)); }
  .brand-word { font-size: 18px; }
  .brand-tld { font-size: 12px; }
  .brand-spade { width: 20px; height: 20px; }

  .nav-actions { gap: 6px; }
  .nav-btn { width: 36px; padding: 0; }
  .btn-label { display: none; }
  .wide-only { display: none; }
  .narrow-only { display: inline-flex; }

  /* Mobile order: Desfazer, Dica, Novo jogo (gold), Mais */
  #btn-undo { order: 1; }
  #btn-hint { order: 2; }
  #btn-new-game { order: 3; }
  #btn-more { order: 4; }

  /* 44px touch targets around the 36px buttons */
  .nav-btn::after {
    content: "";
    position: absolute;
    inset: -4px -3px;
  }

  #app {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: var(--s-3) max(var(--s-3), env(safe-area-inset-right)) max(var(--s-3), env(safe-area-inset-bottom)) max(var(--s-3), env(safe-area-inset-left));
  }

  #game-workspace { flex: 1; gap: 10px; }
  #sidebar { display: none; }

  .scorebar { height: 52px; }
  .stat-label { font-size: var(--fs-2xs); }
  .stat-label .ic { display: none; }
  .label-long { display: none; }
  .label-short { display: inline; }
  .stat-value { font-size: 17px; }

  #ad-bottom { margin-top: 0; }

  /* Menu and "Mais" become bottom sheets */
  .overlay.as-sheet {
    place-items: end stretch;
    padding: 0;
  }

  .overlay.as-sheet .modal {
    width: 100%;
    max-width: none;
    margin-block: auto 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-width: 1px 0 0;
    padding: var(--s-3) max(var(--s-5), env(safe-area-inset-right)) max(var(--s-6), env(safe-area-inset-bottom)) max(var(--s-5), env(safe-area-inset-left));
    gap: var(--s-4);
    box-shadow: 0 -18px 50px -10px rgba(0, 0, 0, 0.6);
    animation-name: sheetIn;
  }

  .overlay.as-sheet .sheet-grip {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--line-strong);
    align-self: center;
  }

  .overlay.as-sheet .menu-title { padding-top: var(--s-2); }
}

@media (max-width: 767px) {
  #ad-bottom { --ad-w: 320px; --ad-h: 50px; }
}

/* Landscape phones: every pixel of height goes to the table */
@media (max-width: 1023px) and (max-height: 500px) {
  :root { --nav-h: 44px; }
  #game-screen { min-height: 0; }
  #app { gap: var(--s-2); padding-top: var(--s-2); padding-bottom: max(var(--s-2), env(safe-area-inset-bottom)); }
  #game-workspace { gap: var(--s-2); }
  .scorebar { height: 40px; }
  .stat { flex-direction: row; align-items: baseline; justify-content: center; gap: var(--s-2); }
  #ad-bottom { --ad-w: 320px; --ad-h: 50px; }
  #ad-bottom .ad-label { display: none; }
}

@media (max-width: 520px) {
  .modal { padding: var(--s-6) var(--s-5); gap: var(--s-5); }
  .win-title h2 { font-size: 44px; }
  .win-stats { grid-template-columns: repeat(2, 1fr); }
  .kings { height: 84px; }
  .kings .mini-card { --w: 56px; }
}

@media (max-width: 359px) {
  .brand-tld { display: none; }
}

@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: none; }
}

/* ─── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
}

[data-reduced-motion] *,
[data-reduced-motion] *::before,
[data-reduced-motion] *::after {
  animation-duration: 1ms !important;
  animation-delay: 0ms !important;
  transition-duration: 1ms !important;
}
