/* ============================================================
   Tokens
   ============================================================ */
:root {
  --curtain: #7A1F2B;
  --curtain-deep: #5C1621;
  --gold: #C9A227;
  --gold-bright: #E0BC4C;
  --ink: #1B1512;
  --cream: #F2E9DC;
  --cream-dim: #E7DBC7;
  --win: #5C7A5E;
  --win-bright: #6F9471;
  --loss: #B85C5C;
  --loss-bright: #C77373;

  --font-display: "Playfair Display", "Georgia", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@font-face {
  font-family: "Playfair Display";
  src: local("Playfair Display");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Header
   ============================================================ */
.site-header {
  text-align: center;
  padding: 2.5rem 1.5rem 1.25rem;
}

.site-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  letter-spacing: 0.01em;
  margin: 0 0 0.4rem;
  color: var(--gold-bright);
}

.subhead {
  margin: 0;
  color: var(--cream-dim);
  font-size: 1rem;
  max-width: 34ch;
  margin: 0 auto;
}

/* ============================================================
   Stage
   ============================================================ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 0 1.25rem 3rem;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.stage {
  width: 100%;
  background: linear-gradient(180deg, var(--curtain) 0%, var(--curtain-deep) 100%);
  border-radius: 6px;
  padding: 2.5rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}

.doors {
  display: flex;
  gap: clamp(0.6rem, 3vw, 1.4rem);
  justify-content: center;
  width: 100%;
}

.door {
  --door-w: clamp(76px, 22vw, 130px);
  --door-h: clamp(140px, 40vw, 220px);
  width: var(--door-w);
  height: var(--door-h);
  perspective: 900px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.door:disabled {
  cursor: default;
}

.door-panel {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(160deg, #8B5E1F 0%, #5E3E12 100%);
  border: 3px solid var(--gold);
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform 0.55s cubic-bezier(0.45, 0, 0.2, 1), box-shadow 0.3s ease;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15), 0 3px 8px rgba(0,0,0,0.3);
}

.door:not(:disabled):hover .door-panel {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15), 0 3px 8px rgba(0,0,0,0.3), 0 0 0 3px rgba(201,162,39,0.4);
}

.door-number {
  margin-top: 0.6rem;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  color: var(--gold-bright);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.door-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  background: var(--cream);
  border-radius: 2px;
  opacity: 0;
  transform: translateZ(-1px);
}

/* Opened state: swing the door panel back to reveal .door-content behind it */
.door.is-open .door-panel {
  transform: rotateY(-108deg);
}
.door.is-open .door-content {
  opacity: 1;
}

.door.is-selected .door-panel {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15), 0 3px 8px rgba(0,0,0,0.3), 0 0 0 3px var(--gold-bright);
}

.door.is-win .door-content { background: var(--win-bright); }
.door.is-loss .door-content { background: var(--loss-bright); }

.stage-message {
  margin: 0;
  font-size: 1.05rem;
  text-align: center;
  color: var(--cream);
  min-height: 1.5em;
}

/* ============================================================
   Controls
   ============================================================ */
.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.mode-tabs {
  display: flex;
  background: var(--cream-dim);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.mode-tab {
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1.3rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.mode-tab.is-active {
  background: var(--curtain);
  color: var(--cream);
}

.mode-panel {
  display: none;
  width: 100%;
  max-width: 420px;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.mode-panel.is-active {
  display: flex;
}

.panel-hint {
  margin: 0;
  color: var(--cream-dim);
  font-size: 0.92rem;
  text-align: center;
}

.choice-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.4rem;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--gold);
  color: var(--ink);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.45; cursor: default; filter: none; }

.btn-secondary {
  background: transparent;
  border-color: var(--cream-dim);
  color: var(--cream);
}
.btn-secondary:hover { border-color: var(--cream); }
.btn-secondary:disabled { opacity: 0.45; cursor: default; }

.btn-text {
  background: none;
  border: none;
  color: var(--cream-dim);
  text-decoration: underline;
  font-size: 0.85rem;
  padding: 0.25rem;
}
.btn-text:hover { color: var(--cream); }

.auto-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.auto-row label {
  font-size: 0.88rem;
  color: var(--cream-dim);
  min-width: 11rem;
  text-align: right;
}

.auto-row input[type="number"] {
  width: 6rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--cream-dim);
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.auto-row input[type="range"] {
  width: 10rem;
  accent-color: var(--gold);
}

.speed-label {
  font-size: 0.85rem;
  color: var(--cream-dim);
  min-width: 3.5rem;
}

/* ============================================================
   Stats ledger
   ============================================================ */
.stats {
  width: 100%;
  max-width: 480px;
  background: var(--cream);
  color: var(--ink);
  border-radius: 6px;
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stats h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
}

.stat-ledger {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stat-row {
  display: grid;
  grid-template-columns: 5rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.stat-label {
  font-size: 0.88rem;
  font-weight: 600;
}

.stat-bar-track {
  height: 10px;
  background: var(--cream-dim);
  border-radius: 999px;
  overflow: hidden;
}

.stat-bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.switch-bar { background: var(--win); }
.stay-bar { background: var(--loss); }

.stat-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  white-space: nowrap;
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--cream-dim);
  font-size: 0.8rem;
}

.site-footer p {
  max-width: 46ch;
  margin: 0 auto;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 420px) {
  .auto-row label {
    text-align: left;
    min-width: 0;
    width: 100%;
  }
  .stat-row {
    grid-template-columns: 4rem 1fr auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .door-panel { transition: none; }
  .stat-bar { transition: none; }
}
