/* ============================================================
   Fair Divider — Editorial Financial Warm (Option A)
   Mobile-first, warm cream palette, asymmetric radii,
   Playfair Display + Outfit + Inter.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,800;1,400;1,600;1,700&display=swap');

/* ---------- Design tokens ---------- */
:root {
  /* Palette */
  --bg: oklch(98% 0.015 85);
  --bg-2: oklch(96% 0.022 80);
  --surface: oklch(100% 0 0);
  --surface-sunken: oklch(96% 0.018 85);
  --surface-elevated: oklch(99% 0.01 85);

  --ink: oklch(18% 0.03 260);
  --ink-muted: oklch(42% 0.02 260);
  --ink-subtle: oklch(64% 0.015 260);

  --accent: oklch(68% 0.17 55);
  --accent-soft: oklch(94% 0.05 55);
  --accent-ink: oklch(48% 0.17 55);

  --positive: oklch(62% 0.18 150);
  --positive-soft: oklch(92% 0.06 150);
  --positive-ink: oklch(42% 0.14 150);

  --negative: oklch(58% 0.2 25);
  --negative-soft: oklch(94% 0.05 30);

  --separator: oklch(88% 0.015 85);
  --hairline: oklch(90% 0.012 85);

  /* Typography */
  --serif: 'Playfair Display', 'New York', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --display: 'Outfit', 'SF Pro Rounded', -apple-system, sans-serif;

  /* Spacing scale */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 2.5rem;
  --s-8: 3rem;
  --s-9: 4rem;

  /* Radii — asymmetric editorial */
  --r-card: 22px 28px 22px 28px;
  --r-card-lg: 28px 36px 28px 36px;
  --r-btn: 18px 22px 18px 22px;
  --r-pill: 999px;
  --r-input: 14px 18px 14px 18px;

  /* Shadows — warm, soft, layered */
  --shadow-1:
    0 1px 2px oklch(18% 0.03 260 / 0.04),
    0 8px 20px oklch(18% 0.03 260 / 0.06);
  --shadow-2:
    0 1px 3px oklch(18% 0.03 260 / 0.05),
    0 20px 48px -24px oklch(18% 0.03 260 / 0.12);
  --shadow-3:
    0 2px 4px oklch(18% 0.03 260 / 0.05),
    0 20px 40px oklch(18% 0.03 260 / 0.10),
    0 40px 80px -20px oklch(18% 0.03 260 / 0.10);

  /* Motion */
  --dur-fast: 150ms;
  --dur: 260ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  /* Layout */
  --maxw: 1240px;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  /* Safe areas */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* ---------- Dark mode (warm charcoal) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(17% 0.015 60);
    --bg-2: oklch(20% 0.018 60);
    --surface: oklch(22% 0.018 60);
    --surface-sunken: oklch(19% 0.015 60);
    --surface-elevated: oklch(25% 0.02 60);

    --ink: oklch(96% 0.01 80);
    --ink-muted: oklch(78% 0.015 80);
    --ink-subtle: oklch(60% 0.015 80);

    --accent: oklch(74% 0.16 60);
    --accent-soft: oklch(30% 0.08 55);
    --accent-ink: oklch(82% 0.14 60);

    --positive: oklch(72% 0.17 150);
    --positive-soft: oklch(28% 0.08 150);
    --positive-ink: oklch(82% 0.14 150);

    --negative: oklch(68% 0.2 25);
    --negative-soft: oklch(30% 0.1 30);

    --separator: oklch(32% 0.02 60);
    --hairline: oklch(28% 0.015 60);

    --shadow-1:
      0 1px 2px oklch(0% 0 0 / 0.4),
      0 8px 20px oklch(0% 0 0 / 0.35);
    --shadow-2:
      0 1px 3px oklch(0% 0 0 / 0.4),
      0 20px 48px -24px oklch(0% 0 0 / 0.55);
    --shadow-3:
      0 2px 4px oklch(0% 0 0 / 0.5),
      0 30px 60px -20px oklch(0% 0 0 / 0.6);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  line-height: 1.55;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background:
    radial-gradient(ellipse at 18% 8%, oklch(95% 0.04 70 / 0.85) 0%, transparent 45%),
    radial-gradient(ellipse at 85% 92%, oklch(95% 0.035 150 / 0.7) 0%, transparent 50%),
    var(--bg);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(ellipse at 18% 8%, oklch(28% 0.05 60 / 0.6) 0%, transparent 50%),
      radial-gradient(ellipse at 85% 92%, oklch(26% 0.045 150 / 0.5) 0%, transparent 55%),
      var(--bg);
  }
}

/* Paper noise atmosphere */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.08  0 0 0 0 0.05  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  body::before { opacity: 0.2; mix-blend-mode: screen; }
}

img, svg { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + var(--s-6)) var(--gutter) var(--s-7);
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}

@media (min-width: 1024px) {
  .app {
    max-width: 900px;
  }
}

/* ---------- Header ---------- */
header {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-top: var(--s-6);
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--separator);
  position: relative;
}

@media (min-width: 640px) {
  header {
    padding-top: 0;
  }
}

header h1 {
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
header h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

header p {
  font-family: var(--sans);
  color: var(--ink-muted);
  font-size: clamp(0.95rem, 2vw, 1.05rem);
  max-width: 52ch;
  margin: 0;
}

.lang-selector {
  position: absolute;
  top: 0;
  inset-inline-end: 0;
}
.lang-selector select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--r-pill);
  padding: 0.5rem 2rem 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  min-height: 40px;
  box-shadow: var(--shadow-1);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%),
                    linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.lang-selector select:hover { border-color: var(--accent); }
.lang-selector select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Stepper ---------- */
#steps, .steps {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) 0;
}
.step {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  opacity: 0.45;
  transition: opacity var(--dur) var(--ease);
}
.step.active { opacity: 1; }
.step.current .step-label {
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
}
.step-dot {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 1.15rem;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--separator);
  border-radius: 50% 45% 55% 50%;
  box-shadow: var(--shadow-1);
  flex-shrink: 0;
}
.step.current .step-dot {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.step-label {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--ink-muted);
  white-space: nowrap;
}
.step-line {
  flex: 1;
  height: 1px;
  background: var(--separator);
  min-width: 12px;
}

@media (max-width: 480px) {
  .step-label { display: none; }
  .step-line { min-width: 16px; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-6);
  flex: 1 0 auto;
}
@media (min-width: 1024px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--s-7);
    align-items: start;
  }
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: clamp(1.25rem, 4vw, 2.25rem);
  box-shadow: var(--shadow-2);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, oklch(100% 0 0 / 0.8), transparent);
  pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  .card::before { background: linear-gradient(90deg, transparent, oklch(100% 0 0 / 0.08), transparent); }
}

.card h2, .card h3 {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.1;
  color: var(--ink);
  margin: 0 0 var(--s-4);
}
.card h2 { font-size: clamp(1.6rem, 4vw, 2.25rem); }
.card h3 { font-size: clamp(1.25rem, 3vw, 1.6rem); }
.card p { color: var(--ink-muted); }

.card-header-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.card-header-row h2 { margin: 0; }

.btn-back {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border: 1px solid var(--separator);
  border-radius: 14px 18px 14px 18px;
  color: var(--ink);
  font-size: 1.15rem;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  flex-shrink: 0;
}
.btn-back:hover { transform: translateX(-2px); background: var(--accent-soft); }
[dir="rtl"] .btn-back { transform: scaleX(-1); }
[dir="rtl"] .btn-back:hover { transform: scaleX(-1) translateX(-2px); }

/* ---------- Mode select ---------- */
#mode-select { text-align: center; }
.mode-buttons {
  display: grid;
  gap: var(--s-4);
  margin-top: var(--s-5);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .mode-buttons { grid-template-columns: 1fr 1fr; }
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-2);
  text-align: start;
  padding: var(--s-5);
  min-height: 120px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--r-card);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-2);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.mode-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); }
.mode-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.mode-card--outline {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--separator);
}
.mode-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.5rem;
  font-style: italic;
  line-height: 1.1;
}
.mode-card:not(.mode-card--outline) .mode-title { color: var(--accent); }
.mode-desc {
  font-size: 0.9rem;
  color: inherit;
  opacity: 0.75;
  font-weight: 400;
}

/* ---------- Forms ---------- */
.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}
@media (min-width: 640px) {
  .input-grid { grid-template-columns: 1fr 1fr; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
}
.form-group label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-subtle);
}

.form-control {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  background: var(--surface-sunken);
  border: 1px solid var(--separator);
  border-radius: var(--r-input);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 500;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.form-control:hover { border-color: var(--accent); }
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%),
                    linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.5rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 48px;
  padding: 0.85rem 1.5rem;
  border-radius: var(--r-btn);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.98rem;
  letter-spacing: 0.005em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
  position: relative;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  box-shadow: var(--shadow-2);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--accent);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
}
.btn-secondary:hover { background: var(--accent-soft); }

.btn-warning {
  background: var(--positive);
  color: oklch(100% 0 0);
  border-color: var(--positive);
  box-shadow: var(--shadow-2);
}
.btn-warning:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); filter: brightness(1.05); }

.btn-full { width: 100%; }

/* ---------- Game: precision bar ---------- */
#precision-bar-container {
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-5);
}
.precision-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.precision-header > span:first-child {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
  color: var(--ink-subtle);
}
#precision-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.precision-track {
  height: 8px;
  background: var(--hairline);
  border-radius: var(--r-pill);
  overflow: hidden;
  position: relative;
}
.precision-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--positive));
  border-radius: var(--r-pill);
  transition: width 600ms var(--ease);
}

/* Turn info */
#turn-info { margin-bottom: var(--s-5); }
#turn-info h3 {
  font-family: var(--serif);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: var(--s-2);
}
#turn-info h3 #current-player-name {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}
#turn-info p {
  color: var(--ink-muted);
  font-size: 0.95rem;
}

/* ---------- Choice cards ---------- */
#choice-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
}
@media (min-width: 640px) { #choice-cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { #choice-cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); } }

.choice-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  cursor: pointer;
  min-height: 180px;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  position: relative;
  text-align: start;
}
.choice-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow-3);
}
.choice-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.choice-room {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-subtle);
}
.choice-price {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.choice-tag {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  padding: 4px 12px;
  background: var(--positive-soft);
  color: var(--positive-ink);
  border-radius: var(--r-pill);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.choice-price-bar {
  margin-top: auto;
  height: 6px;
  background: var(--hairline);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.choice-price-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  border-radius: var(--r-pill);
  transition: width 500ms var(--ease);
}

/* ---------- Proposal / results shared list ---------- */
#proposal-list, #results-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-top: var(--s-4);
}

.result-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.result-item:hover { border-color: var(--accent); transform: translateY(-1px); }

.result-player {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  color: var(--ink);
  line-height: 1.15;
  min-width: 0;
  overflow-wrap: anywhere;
}

.result-assignment {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: end;
}
[dir="rtl"] .result-assignment { align-items: flex-start; text-align: start; }

.result-room {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-subtle);
}
.result-rent {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
}

#proposal-level {
  font-family: var(--display);
  font-weight: 600;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
#results-precision {
  font-family: var(--display);
  font-weight: 600;
  color: var(--positive-ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Action button row ---------- */
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-5);
}
.action-buttons .btn { flex: 1 1 auto; min-width: 140px; }
@media (max-width: 480px) {
  .action-buttons .btn { flex: 1 1 100%; }
}

/* ---------- Sidebar / history ---------- */
.sidebar {
  display: none;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: var(--s-5);
  box-shadow: var(--shadow-1);
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}
body:has(#game-area:not(.hidden)) .sidebar,
body:has(#proposal:not(.hidden)) .sidebar,
body:has(#results:not(.hidden)) .sidebar {
  display: flex;
}
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: calc(var(--safe-t) + var(--s-5));
    max-height: calc(100vh - var(--safe-t) - var(--s-8));
    overflow: auto;
  }
}

.sidebar h3 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  margin: 0 0 var(--s-2);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--separator);
}
.sidebar h3::after {
  content: "";
  display: block;
  width: 32px;
  height: 2px;
  background: var(--accent);
  margin-top: var(--s-2);
}

#history-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.history-item {
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--separator);
  border-radius: 10px 14px 10px 14px;
  padding: var(--s-3) var(--s-4);
  font-size: 0.85rem;
}
.history-item.manual { border-left-color: var(--accent); }
.history-item.auto { border-left-color: var(--positive); }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: 4px;
}
.history-header .player {
  font-family: var(--serif);
  font-weight: 700;
  font-style: italic;
  color: var(--ink);
  font-size: 0.95rem;
}
.badge {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.badge.manual { background: var(--accent-soft); color: var(--accent-ink); }
.badge.auto { background: var(--positive-soft); color: var(--positive-ink); }
.history-details {
  color: var(--ink-muted);
  font-size: 0.8rem;
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
}

/* ---------- Footer ---------- */
.app-footer {
  flex-shrink: 0;
  padding: var(--s-5) var(--gutter) calc(var(--safe-b) + var(--s-5));
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-subtle);
  border-top: 1px solid var(--separator);
  position: relative;
  z-index: 1;
}
.app-footer a {
  color: var(--ink-muted);
  font-family: var(--serif);
  font-style: italic;
}
.app-footer a:hover { color: var(--accent); }
.footer-sep { margin: 0 var(--s-3); color: var(--ink-subtle); }

/* ---------- RTL tweaks ---------- */
[dir="rtl"] body { direction: rtl; }
[dir="rtl"] .lang-selector select {
  background-position: 18px 50%, 13px 50%;
  padding: 0.5rem 1rem 0.5rem 2rem;
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .btn:hover, .mode-card:hover, .choice-card:hover, .result-item:hover { transform: none; }
}

/* ---------- Responsive hero / small screens ---------- */
@media (max-width: 380px) {
  .app { padding-inline: var(--s-4); }
  .card { padding: var(--s-5) var(--s-4); }
  header h1 { font-size: 2.25rem; }
}

/* ---------- Touch targets ---------- */
button, .btn, .mode-card, .choice-card, select, input, .btn-back {
  min-height: 44px;
}

/* ---------- Print safety ---------- */
@media print {
  body::before { display: none; }
  .sidebar, .app-footer, .lang-selector { display: none !important; }
  .card { box-shadow: none; border-color: #ddd; }
}
