/* Shared, switchable palette layer for the personal portal. */
html[data-theme="rose"] {
  color-scheme: light;
  --palette-1: #3e3239;
  --palette-2: #6b5560;
  --palette-3: #9e8189;
  --palette-4: #c7a9a3;
  --palette-5: #e8d2c4;
  --palette-6: #f7efe7;
  --theme-page: var(--palette-6);
  --theme-surface: color-mix(in srgb, var(--palette-6) 84%, var(--palette-5));
  --theme-surface-raised: #fffaf5;
  --theme-text: var(--palette-1);
  --theme-muted: var(--palette-2);
  --theme-accent: var(--palette-2);
  --theme-accent-soft: var(--palette-5);
  --theme-border: var(--palette-4);
  --theme-shadow: 0 18px 48px rgb(62 50 57 / 9%);
}

html[data-theme="blue"] {
  color-scheme: light;
  --palette-1: #06141b;
  --palette-2: #11212d;
  --palette-3: #253745;
  --palette-4: #4a5c6a;
  --palette-5: #9ba8ab;
  --palette-6: #ccd0cf;
  --theme-page: #ccd0cf;
  --theme-surface: color-mix(in srgb, var(--palette-6) 70%, white);
  --theme-surface-raised: #f7f9f8;
  --theme-text: var(--palette-1);
  --theme-muted: var(--palette-3);
  --theme-accent: var(--palette-3);
  --theme-accent-soft: var(--palette-5);
  --theme-border: var(--palette-5);
  --theme-shadow: 0 18px 48px rgb(6 20 27 / 10%);
}

html[data-theme="green"] {
  color-scheme: light;
  --palette-1: #051f20;
  --palette-2: #0b2b26;
  --palette-3: #163832;
  --palette-4: #235347;
  --palette-5: #8eb69b;
  --palette-6: #daf1de;
  --theme-page: #daf1de;
  --theme-surface: color-mix(in srgb, var(--palette-6) 66%, white);
  --theme-surface-raised: #ffffff;
  --theme-text: var(--palette-1);
  --theme-muted: var(--palette-3);
  --theme-accent: var(--palette-3);
  --theme-accent-soft: var(--palette-5);
  --theme-border: var(--palette-5);
  --theme-shadow: 0 18px 48px rgb(5 31 32 / 10%);
}

html[data-theme] {
  --primary: var(--theme-accent);
  --primary-dark: var(--theme-text);
  --primary-light: var(--theme-accent-soft);
  --secondary: var(--theme-accent-soft);
  --text: var(--theme-text);
  --text-light: var(--theme-muted);
  --text-lighter: color-mix(in srgb, var(--theme-muted) 58%, white);
  --glass: var(--theme-surface);
  --glass-heavy: var(--theme-surface-raised);
  --shadow-xs: 0 2px 8px rgb(0 0 0 / 4%);
  --shadow-sm: var(--theme-shadow);
}

html[data-theme] body {
  color: var(--theme-text);
  background: var(--theme-page);
  background-image: none;
  animation: none;
}

html[data-theme] body::before {
  animation: none;
  opacity: 0;
}

html[data-theme] :is(.portal-card, .game-card, .month-card, .plan-item, .game-wrapper, .result-panel, .stat-item, .photo-card, .character-select, .game-over, .settings-panel) {
  color: var(--theme-text);
  background-color: var(--theme-surface);
  border-color: color-mix(in srgb, var(--theme-border) 55%, transparent);
  box-shadow: var(--theme-shadow);
}

html[data-theme] :is(.portal-card, .game-card, .month-card, .plan-item, .game-wrapper, .result-panel, .stat-item, .photo-card, .character-select, .game-over, .settings-panel) {
  border-radius: 22px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html[data-theme] :is(.portal-card, .game-wrapper, .settings-panel) {
  border: 1px solid color-mix(in srgb, var(--theme-border) 62%, transparent);
}

html[data-theme] :is(.portal-button, .game-card, .back-button, .back-btn, .add-btn, .update-btn, .start-btn, .restart-btn, .btn-confirm) {
  color: var(--theme-text);
  background: var(--theme-accent-soft);
  box-shadow: none;
  transition: transform .18s ease, background-color .18s ease, border-color .18s ease;
}

html[data-theme] :is(.portal-button, .game-card, .back-button, .back-btn, .add-btn, .update-btn, .start-btn, .restart-btn, .btn-confirm):hover {
  background: var(--theme-border);
  transform: translateY(-2px);
}

html[data-theme] :is(input, textarea, select) {
  color: var(--theme-text);
  background-color: var(--theme-surface-raised);
  border-color: var(--theme-border);
}

html[data-theme] :is(input, textarea, select)::placeholder {
  color: var(--theme-muted);
  opacity: .72;
}

html[data-theme] :is(a, button) {
  -webkit-tap-highlight-color: color-mix(in srgb, var(--theme-accent) 18%, transparent);
}

html[data-theme] :is(.portal-button, .game-card, .add-btn, .update-btn, .start-btn, .restart-btn, .btn-confirm) {
  border-color: transparent;
}

.theme-switcher {
  position: fixed;
  z-index: 10000;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 12px;
  color: var(--theme-text, #242124);
  background: var(--theme-surface-raised, #fffaf5);
  border: 1px solid var(--theme-border, #c7a9a3);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 10%);
  font: 600 12px/1.2 system-ui, sans-serif;
}

.theme-switcher label { white-space: nowrap; }
.theme-switcher select {
  min-height: 34px;
  max-width: 126px;
  padding: 5px 24px 5px 9px;
  border: 0;
  border-radius: 999px;
  color: var(--theme-text, #242124);
  background: var(--theme-page, #f7efe7);
  font: inherit;
}

.theme-switcher :focus-visible,
html[data-theme] :is(a, button, input, textarea, select):focus-visible {
  outline: 3px solid var(--theme-accent, #6b5560);
  outline-offset: 3px;
}

.site-nav {
  position: fixed;
  z-index: 9998;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--theme-border, #c7a9a3);
  border-radius: 18px;
  color: var(--theme-text, #3e3239);
  background: var(--theme-surface-raised, #fffaf5);
  box-shadow: 0 8px 26px rgb(0 0 0 / 8%);
  font: 600 13px/1.1 system-ui, sans-serif;
}

.site-nav a {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--theme-surface-raised, #fffaf5);
  background: var(--theme-accent, #6b5560);
}

.site-nav a:hover { background: var(--theme-accent-soft, #e8d2c4); }
.site-nav a[aria-current="page"]:hover { background: var(--theme-accent, #6b5560); }

html[data-theme] body:has(.site-nav) { padding-top: 76px; }
html[data-theme] body:has(.site-nav) { overflow-x: hidden; overflow-y: auto; }

@media (max-width: 480px) {
  .theme-switcher { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); }
  .theme-switcher label { display: none; }
  .theme-switcher select { min-height: 40px; max-width: 120px; }
  html[data-theme] body { background-attachment: scroll; }
  .site-nav {
    top: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    justify-content: space-around;
    gap: 2px;
    padding: 6px;
    border-radius: 18px;
  }
  .site-nav a { flex: 1; min-width: 0; min-height: 44px; padding-inline: 7px; font-size: 12px; }
  html[data-theme] body:has(.site-nav) { padding-top: 18px; padding-bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  html[data-theme] *, html[data-theme] *::before, html[data-theme] *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
