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

:root {
  --bg: #f5f0e8;
  --bg2: #ede7da;
  --surface: #faf7f2;
  --surface2: #f0eade;
  --border: rgba(120,100,70,0.12);
  --border-hover: rgba(120,100,70,0.28);
  --text: #2c2418;
  --text-muted: rgba(44,36,24,0.52);
  --text-dim: rgba(44,36,24,0.3);
  --accent: #7a5c38;
  --accent-light: #a07848;
  --accent-soft: rgba(122,92,56,0.1);
  --accent-hover: rgba(122,92,56,0.18);
  --danger: #b84040;
  --success: #3a7a58;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  overflow-x: hidden;
}

/* ── LEAF CANVAS ── */
#leaf-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ── SCREENS ── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 1;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ── LANDING ── */
#landing { background: transparent; }
.landing-inner { text-align: center; max-width: 480px; padding: 2rem; }
.brand-mark {
  width: 52px; height: 52px;
  border: 1px solid var(--border-hover);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 2.5rem;
  background: var(--surface);
}
.brand-mark svg { width: 22px; height: 22px; }
.landing-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.landing-title em { font-style: italic; color: var(--accent); }
.landing-sub {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.04em;
  margin-bottom: 3rem;
}
.btn-group {
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; max-width: 280px; margin: 0 auto;
}
.btn {
  width: 100%;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.btn:hover {
  border-color: var(--border-hover);
  background: var(--surface2);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #faf7f2;
  font-weight: 500;
}
.btn.primary:hover { background: var(--accent-light); border-color: var(--accent-light); }
.btn.ghost { color: var(--text-muted); background: transparent; }
.btn.ghost:hover { color: var(--text); background: var(--accent-soft); }
.footer-hint { margin-top: 2.5rem; font-size: 12px; color: var(--text-dim); letter-spacing: 0.03em; }

/* ── MODAL OVERLAY ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(44,36,24,0.35);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 100; padding: 1rem;
}
.overlay.active { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  width: 100%; max-width: 380px;
  transform: translateY(12px);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 8px 40px rgba(44,36,24,0.12);
}
.overlay.active .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.75rem;
}
.modal-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 400; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}
.modal-close:hover { border-color: var(--border-hover); color: var(--text); }
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 12px; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 6px;
  text-transform: uppercase;
}
.field input {
  width: 100%; padding: 11px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body); font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-dim); }
.modal-footer { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 8px; }
.modal-switch { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 0.75rem; }
.modal-switch a { color: var(--accent); text-decoration: none; cursor: pointer; }
.modal-switch a:hover { text-decoration: underline; }
.msg { font-size: 12px; padding: 8px 12px; border-radius: 6px; margin-top: 8px; display: none; }
.msg.error {
  background: rgba(184,64,64,0.08);
  border: 1px solid rgba(184,64,64,0.22);
  color: var(--danger);
  display: block;
}
.msg.success {
  background: rgba(58,122,88,0.08);
  border: 1px solid rgba(58,122,88,0.22);
  color: var(--success);
  display: block;
}

/* ── DASHBOARD ── */
#dashboard {
  background: transparent;
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  overflow: hidden;
}
.dash-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(245,240,232,0.88);
  backdrop-filter: blur(10px);
  z-index: 2;
}
.dash-brand { font-family: var(--font-display); font-size: 1rem; font-weight: 400; color: var(--text); }
.dash-user { display: flex; align-items: center; gap: 10px; }
.dash-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--border-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500; color: var(--accent);
}
.dash-username { font-size: 13px; color: var(--text-muted); }
.btn-logout {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); font-family: var(--font-body); font-size: 12px;
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
  transition: all var(--transition);
}
.btn-logout:hover { border-color: var(--border-hover); color: var(--text); }

/* Config notice */
.config-bar {
  background: rgba(122,92,56,0.07);
  border: 1px solid rgba(122,92,56,0.2);
  border-radius: 0;
  padding: 8px 1.5rem;
  font-size: 12px; color: var(--accent);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; z-index: 2;
}
.config-bar a { color: inherit; cursor: pointer; text-decoration: underline; }

/* ── SWITCH STAGE ── */
.sw-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0 0.5rem;
  overflow: visible;
  position: relative;
  width: 100%;
}

.sw-category-bar {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 0.75rem;
}
.sw-category-label {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 400;
  color: var(--text); letter-spacing: 0.01em;
}
.sw-add-btn {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-family: var(--font-body); font-size: 11px;
  padding: 3px 10px; border-radius: 6px;
  cursor: pointer; transition: all var(--transition);
}
.sw-add-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Carousel wrapper */
.sw-carousel-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.sw-arrow {
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: transparent; border: none;
  font-size: 2rem; line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), transform var(--transition);
  z-index: 2;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.sw-arrow:hover { color: var(--text); transform: scale(1.15); }
.sw-arrow:disabled { opacity: 0.2; cursor: default; transform: none; }

.sw-carousel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 52vh;
  overflow: visible;
  position: relative;
}

/* Game cards — centre = 1/3 screen height, width = height / 1.3 (portrait ratio) */
.sw-card {
  flex-shrink: 0;
  border-radius: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(44,36,24,0.06);
}
.sw-card:hover { border-color: var(--border-hover); }

/* Size states */
/* Centre = 50vh tall, width = height / 1.3 (portrait ratio)
   Side cards scale down so the centre always dominates */
.sw-card.center {
  height: 50vh;
  width: calc(50vh / 1.3);
  opacity: 1; transform: scale(1);
  border-color: var(--accent);
  box-shadow: 0 6px 28px rgba(122,92,56,0.2);
}
.sw-card.side-near {
  height: calc(50vh * 0.55);
  width: calc(50vh * 0.55 / 1.3);
  opacity: 0.7; transform: scale(1);
}
.sw-card.side-far {
  height: calc(50vh * 0.38);
  width: calc(50vh * 0.38 / 1.3);
  opacity: 0.4; transform: scale(1);
}
.sw-card.side-far2 {
  height: calc(50vh * 0.28);
  width: calc(50vh * 0.28 / 1.3);
  opacity: 0.25; transform: scale(1);
}

.sw-card-cover {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem;
  background: var(--surface2);
  border-radius: 13px;
  overflow: hidden;
}
.sw-card-cover img {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 13px;
}
.sw-card.center .sw-card-cover { font-size: 4.5rem; }

/* Info strip below carousel */
.sw-info {
  margin-top: 0.9rem;
  text-align: center;
  min-height: 60px;
  padding: 0 2rem;
  width: 100%;
  max-width: 860px;
}
.sw-info-title {
  font-family: var(--font-display);
  font-size: 1.15rem; font-weight: 400;
  color: var(--text); margin-bottom: 2px;
}
.sw-info-desc {
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 8px;
}
.sw-info-actions {
  display: flex; gap: 8px; justify-content: center;
}
.sw-info-actions .btn {
  width: auto; padding: 8px 20px; font-size: 13px;
}

/* ── SWITCH DOCK ── */
.sw-dock {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  background: rgba(245,240,232,0.88);
  backdrop-filter: blur(10px);
  width: 100%;
}

/* Inner dock container — centred, max width matches carousel */
.sw-dock-inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 860px;
}

.sw-dock-arrow {
  flex-shrink: 0;
  width: 32px; height: 32px;
  background: transparent; border: none;
  font-size: 1.4rem; color: var(--text-muted);
  cursor: pointer; transition: color var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.sw-dock-arrow:hover { color: var(--text); }

.sw-dock-scroll {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 8px;
}
.sw-dock-scroll::-webkit-scrollbar { display: none; }

.sw-dock-item {
  flex-shrink: 0;
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  opacity: 0.55;
}
.sw-dock-item:hover { opacity: 0.85; background: var(--accent-soft); }
.sw-dock-item.active {
  opacity: 1;
  border-color: var(--border-hover);
  background: var(--surface);
  box-shadow: 0 1px 6px rgba(44,36,24,0.08);
}
.sw-dock-icon { font-size: 20px; line-height: 1; }
.sw-dock-label { font-size: 10px; color: var(--text-muted); letter-spacing: 0.04em; white-space: nowrap; }

/* Empty state card */
.sw-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 1.5rem 2rem;
  border: 1px dashed var(--border);
  border-radius: 14px; color: var(--text-dim);
  font-size: 13px; text-align: center;
  min-width: 160px;
}
.sw-empty-icon { font-size: 2rem; opacity: 0.4; }

@media (max-width: 480px) {
  .sw-card.center    { height: 38vh; width: calc(38vh / 1.3); }
  .sw-card.side-near { height: calc(38vh * 0.55); width: calc(38vh * 0.55 / 1.3); }
  .sw-card.side-far  { height: calc(38vh * 0.38); width: calc(38vh * 0.38 / 1.3); }
  .dash-topbar { padding: 0.6rem 1rem; }
}

/* Key Gate */
.key-gate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem;
  width: 100%; max-width: 360px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(44,36,24,0.1);
}
.key-gate-icon { font-size: 28px; margin-bottom: 1rem; opacity: 0.6; }
.key-gate-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 400; margin-bottom: 0.4rem; }
.key-gate-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 1.5rem; line-height: 1.5; }
.key-gate .field input { text-align: center; letter-spacing: 0.12em; font-size: 15px; }
.key-gate-actions { display: flex; gap: 8px; margin-top: 1rem; }

@media (max-width: 480px) {
  .dash-topbar { padding: 0.75rem 1rem; }
  .switch-hero, .game-rail-section { padding-left: 1rem; padding-right: 1rem; }
  .config-bar { margin-left: 1rem; margin-right: 1rem; }
}

/* ── APP IFRAME OVERLAY ── */
.app-overlay-hidden {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  flex-direction: column;
}
.app-overlay-hidden.active {
  display: flex;
}
.app-overlay-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(245,240,232,0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-overlay-back {
  background: var(--accent);
  color: #faf7f2;
  border: none;
  border-radius: 8px;
  padding: 7px 18px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.app-overlay-back:hover { background: var(--accent-light); }
.app-overlay-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
}
.app-overlay-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: white;
}