/* Shared app theme — daneschilling.com sunset palette + games-style shell */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root,
[data-theme="light"] {
  color-scheme: light;

  --color-primary: #C44D2E;
  --color-primary-hover: #9A3424;
  --color-primary-shadow: rgba(196, 77, 46, 0.25);
  --color-primary-light: #F5E6C8;
  --color-primary-selected: #E8752A;
  --color-secondary: #E8752A;
  --color-accent: #F2A93B;
  --color-teal: #6BAEA6;
  --color-teal-dark: #4A8F88;
  --color-cream: #F5E6C8;
  --color-bg: #DDD0B8;
  --color-surface: #F5E6C8;
  --color-surface-raised: #FFFFFF;
  --color-surface-hover: #EDE0C4;
  --color-border: rgba(107, 174, 166, 0.35);
  --color-text: #5F5952;
  --color-text-muted: #7A736B;
  --color-danger: #9A3424;
  --color-danger-hover: #7A2A1C;
  --color-danger-light: #F8E8E4;
  --color-focus: #6BAEA6;
  --color-overlay: rgba(95, 89, 82, 0.55);
  --color-shadow: rgba(95, 89, 82, 0.12);
  --radius: 12px;
  --radius-lg: 20px;
  --radius-sm: 8px;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --min-touch: 44px;
  --shell-padding-x: 1.25rem;
  --shell-padding-y: 1.25rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --gutter-inline-start: max(var(--shell-padding-x), var(--safe-left));
  --gutter-inline-end: max(var(--shell-padding-x), var(--safe-right));

  /* Legacy aliases (emotions, trakd, emdr) */
  --primary: var(--color-primary);
  --primary-hover: var(--color-primary-hover);
  --primary-light: var(--color-primary-light);
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --surface-raised: var(--color-surface-raised);
  --text: var(--color-text);
  --text-muted: var(--color-text-muted);
  --border: var(--color-border);
  --danger: var(--color-danger);
  --danger-hover: var(--color-danger-hover);
  --danger-light: var(--color-danger-light);
  --accent: var(--color-teal);
  --accent-dim: rgba(107, 174, 166, 0.18);
  --accent-text: #FFFFFF;
  --bg-elevated: var(--color-surface);
  --bg-hover: var(--color-surface-hover);
  --bg-deep: var(--color-bg);
  --bg-surface: var(--color-surface);
  --page-bg: var(--color-bg);
  --text-primary: var(--color-text);
  --text-secondary: var(--color-text-muted);
  --shadow: 0 8px 32px var(--color-shadow);
  --shadow-sm: 0 2px 8px var(--color-shadow);
  --focus-ring: 0 0 0 3px rgba(107, 174, 166, 0.35);
}

[data-theme="dark"] {
  color-scheme: dark;

  --color-primary: #E8752A;
  --color-primary-hover: #F2A93B;
  --color-primary-shadow: rgba(232, 117, 42, 0.3);
  --color-primary-light: #4A3D30;
  --color-primary-selected: #C44D2E;
  --color-secondary: #F2A93B;
  --color-accent: #F2A93B;
  --color-teal: #6BAEA6;
  --color-teal-dark: #4A8F88;
  --color-cream: #3D3832;
  --color-bg: #2A2622;
  --color-surface: #3D3832;
  --color-surface-raised: #4A4540;
  --color-surface-hover: #565048;
  --color-border: rgba(107, 174, 166, 0.22);
  --color-text: #F5E6C8;
  --color-text-muted: #B8B0A4;
  --color-danger: #E8752A;
  --color-danger-hover: #F2A93B;
  --color-danger-light: #4A3530;
  --color-focus: #6BAEA6;
  --color-overlay: rgba(0, 0, 0, 0.65);
  --color-shadow: rgba(0, 0, 0, 0.35);

  --accent-dim: rgba(107, 174, 166, 0.2);
  --accent-text: #2A2622;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* Games-style centered card shell */
.app-page {
  min-height: 100dvh;
  padding:
    max(var(--shell-padding-y), var(--safe-top))
    var(--gutter-inline-end)
    max(var(--shell-padding-y), var(--safe-bottom))
    var(--gutter-inline-start);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Full-bleed mobile apps fill the viewport; gutters live on the shell */
.app-page:has(.app-shell--full) {
  padding: 0;
}

@media (min-width: 600px) {
  .app-page:has(.app-shell--full) {
    padding:
      max(var(--shell-padding-y), var(--safe-top))
      var(--gutter-inline-end)
      max(var(--shell-padding-y), var(--safe-bottom))
      var(--gutter-inline-start);
  }
}

.app-shell {
  width: 100%;
  max-width: 800px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding:
    var(--shell-padding-y)
    var(--gutter-inline-end)
    var(--shell-padding-y)
    var(--gutter-inline-start);
  position: relative;
}

.app-shell--narrow {
  max-width: 560px;
}

.app-shell--full {
  max-width: 480px;
  min-height: 100dvh;
  border-radius: 0;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  box-shadow: none;
  padding:
    max(0px, var(--safe-top))
    var(--gutter-inline-end)
    max(0px, var(--safe-bottom))
    var(--gutter-inline-start);
}

@media (min-width: 600px) {
  .app-shell--full {
    margin: 0 auto;
    border-radius: var(--radius-lg);
    min-height: calc(100dvh - (var(--shell-padding-y) * 2));
    margin-top: var(--shell-padding-y);
    margin-bottom: var(--shell-padding-y);
    box-shadow: var(--shadow);
    padding:
      var(--shell-padding-y)
      var(--gutter-inline-end)
      var(--shell-padding-y)
      var(--gutter-inline-start);
  }
}

.app-header {
  text-align: center;
  margin-bottom: 1.5rem;
  position: relative;
  padding-top: 2.75rem;
}

/* Section gutters for full-bleed layouts — main/footer only; headers keep their own padding */
.app-shell--full > .main,
.app-shell--full > main,
.app-shell--full > footer,
.app-shell--full > .app-footer {
  padding-left: 0;
  padding-right: 0;
}

.app-header h1,
.app-header .app-title {
  margin: 0;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

.app-header .subtitle,
.app-header .tagline {
  margin: 0.35rem 0 0;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  font-weight: 500;
}

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--min-touch);
  height: var(--min-touch);
  padding: 0;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
}

[data-theme="dark"] .theme-icon-moon,
[data-theme="light"] .theme-icon-sun {
  display: none;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 1000;
  padding: 0.75rem 1.25rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
  outline: none;
  box-shadow: var(--focus-ring);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Shared buttons (games pattern) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  min-height: var(--min-touch);
  box-shadow: var(--shadow-sm);
}

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

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

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-hover);
}

.btn-danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.panel {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
