@layer tokens, reset, layout, components, pages, animations;

/* ── DESIGN TOKENS ─────────────────────────────────────── */

@layer tokens {
  :root {
    /* ── Shared / unchanging ── */

    /* Woody brown */
    --wood-dark: #5C3A1E;
    --wood: #7c5e3a;
    --wood-light: #a0764a;
    --wood-glint: #c49a6c;
    --wood-glass: rgba(92, 58, 30, 0.45);
    --wood-glass-hover: rgba(124, 94, 58, 0.55);
    --accent-leaf: #a3e635;
    --accent-purple: #a78bfa;

    /* Type scale */
    --text-xs: 0.6875rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-md: 1.0625rem;
    --text-lg: 1.25rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;
    --text-3xl: 2.75rem;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 28px;
    --space-3xl: 40px;

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Layout */
    --header-height: 54px;
    --bottom-nav-height: 70px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Fonts */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;

    /* Easing */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring: cubic-bezier(0.25, 0.46, 0.45, 1.4);

    --input-font-size: 16px;
    --glass-blur: 22px;
    --glass-saturate: 1.3;

    /* ── Light theme default ── */

    /* Background depths */
    --bg-deepest: #eaf3ec;
    --bg-body: #f1f7f3;
    --bg-elevated: #e0ece3;

    /* Frosted glass surfaces */
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-bg-hover: rgba(255, 255, 255, 0.82);
    --glass-bg-active: rgba(238, 255, 242, 0.88);
    --glass-bg-solid: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(21, 128, 61, 0.14);
    --glass-border-hover: rgba(21, 128, 61, 0.24);
    --glass-border-focus: rgba(21, 128, 61, 0.42);

    /* Brand green */
    --brand: #15803d;
    --brand-hover: #1e9648;
    --brand-active: #106b32;
    --brand-glow: rgba(21, 128, 61, 0.18);
    --brand-glow-strong: rgba(21, 128, 61, 0.30);
    --brand-soft: #04704C;
    --brand-muted: #166534;

    /* Semantic */
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    --danger-bg: rgba(185, 28, 28, 0.10);
    --info: #0369a1;
    --energy: #92400e;
    --cyan: #0e7490;
    --warning-bg: rgba(180, 83, 9, 0.08);
    --warning-border: rgba(180, 83, 9, 0.2);
    --success-bg-subtle: rgba(21, 128, 61, 0.12);
    --success-border-subtle: rgba(21, 128, 61, 0.3);
    --brand-bg-subtle: rgba(21, 128, 61, 0.08);
    --grid-color: rgba(0, 0, 0, 0.06);

    /* Text */
    --text-primary: #0d1711;
    --text-secondary: #56635b;
    --text-tertiary: #5f6b62;
    --text-on-brand: #f0fdf4;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.10);
    --shadow-glow: 0 0 30px var(--brand-glow);
    --shadow-glass: 0 2px 12px rgba(0, 0, 0, 0.05), 0 0 0 1px var(--glass-border);
  }

  [data-theme="dark"] {
    /* Background depths */
    --bg-deepest: #060c08;
    --bg-body: #0d1510;
    --bg-elevated: #111c14;

    /* Frosted glass surfaces */
    --glass-bg: rgba(16, 34, 22, 0.55);
    --glass-bg-hover: rgba(22, 44, 30, 0.65);
    --glass-bg-active: rgba(28, 56, 38, 0.72);
    --glass-bg-solid: rgba(16, 34, 22, 0.85);
    --glass-border: rgba(74, 222, 128, 0.10);
    --glass-border-hover: rgba(74, 222, 128, 0.18);
    --glass-border-focus: rgba(74, 222, 128, 0.35);

    /* Brand green */
    --brand: #4ade80;
    --brand-hover: #68e89a;
    --brand-active: #36c46b;
    --brand-glow: rgba(74, 222, 128, 0.28);
    --brand-glow-strong: rgba(74, 222, 128, 0.45);
    --brand-soft: #6ee7b7;
    --brand-muted: #bbf7d0;

    /* Semantic */
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #ef4444;
    --info: #38bdf8;
    --energy: #facc15;
    --cyan: #22d3ee;
    --warning-bg: rgba(251, 191, 36, 0.12);
    --warning-border: rgba(251, 191, 36, 0.25);
    --success-bg-subtle: rgba(52, 211, 153, 0.12);
    --success-border-subtle: rgba(52, 211, 153, 0.3);
    --brand-bg-subtle: rgba(74, 222, 128, 0.10);
    --grid-color: rgba(255, 255, 255, 0.06);

    /* Text */
    --text-primary: #f0fdf4;
    --text-secondary: #9ca3a0;
    --text-tertiary: #88928c;
    --text-on-brand: #052e16;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-glass: 0 2px 12px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--glass-border);
  }
}

/* ── RESET & BASE ──────────────────────────────────────── */

@layer reset {

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

  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }

  html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
  }

  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-body);
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  input,
  button,
  textarea {
    font: inherit;
    color: inherit;
    border: none;
    background: none;
  }

  button {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }

  button:active {
    transform: scale(0.97);
    transition: transform 0.1s var(--ease-out-expo);
  }

  a {
    color: var(--brand);
    text-decoration: none;
  }

  .setting-help a {
    display: inline-block;
    min-height: 44px;
  }

  img,
  svg {
    display: block;
  }

  [hidden] {
    display: none !important;
  }

  input {
    caret-color: var(--brand);
  }

  input:focus:not(:focus-visible) {
    outline: none;
  }

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

  :focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
  }

  button:focus-visible,
  a:focus-visible,
  input:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--brand-glow);
  }

  .glass:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -1px;
    border-color: var(--glass-border-focus);
    box-shadow: 0 0 0 3px var(--brand-glow);
  }
}

/* ── BACKGROUND LAYER ──────────────────────────────────── */

@layer layout {
  .bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
  }

  .bg-orbs {
    position: absolute;
    inset: 0;
  }

  .bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.12;
    animation: orb-drift 20s ease-in-out infinite alternate;
  }

  .orb-1 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--brand-glow) 0%, transparent 70%);
    top: -80px;
    left: -60px;
    animation-delay: 0s;
  }

  .orb-2 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(52, 211, 153, 0.25) 0%, transparent 70%);
    top: 40%;
    right: -80px;
    animation-delay: -7s;
  }

  .orb-3 {
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(110, 231, 183, 0.22) 0%, transparent 70%);
    bottom: 10%;
    left: 30%;
    animation-delay: -14s;
  }

  @keyframes orb-drift {
    0% {
      transform: translate(0, 0) scale(1);
    }

    100% {
      transform: translate(30px, -20px) scale(1.15);
    }
  }

  .bg-noise {
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.4;
  }

  /* App shell */
  .app-shell {
    position: relative;
    z-index: 1;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .skip-link {
    position: fixed;
    top: var(--space-sm);
    left: var(--space-sm);
    z-index: 9999;
    padding: var(--space-md) var(--space-xl);
    background: var(--brand);
    color: var(--text-on-brand);
    font-weight: 600;
    font-size: var(--text-sm);
    border-radius: var(--radius-full);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    transform: translateY(-120%);
    transition: transform 0.2s var(--ease-out-expo);
  }

  .skip-link:focus {
    transform: translateY(0);
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
  }
}

/* ── HEADER ────────────────────────────────────────────── */

@layer layout {
  .app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    background: rgba(241, 247, 243, 0.72);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid var(--glass-border);
  }

  .app-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 550;
    color: var(--text-primary);
    letter-spacing: -0.02em;
  }

  .header-actions {
    display: flex;
    gap: var(--space-md);
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background 0.2s ease, color 0.2s ease;
  }

  .icon-btn:active {
    background: var(--glass-bg-active);
    color: var(--text-primary);
  }
}

/* ── BOTTOM NAVIGATION ─────────────────────────────────── */

@layer layout {
  .bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: 50;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: var(--space-sm) var(--space-xs);
    padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    background: rgba(241, 247, 243, 0.78);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-top: 1px solid var(--glass-border);
  }

  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: var(--space-xs);
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    transition: color 0.2s ease, transform 0.2s var(--ease-out-expo);
    position: relative;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .nav-item.active {
    color: var(--brand);
  }

  .nav-item.active::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--brand);
    border-radius: var(--radius-full);
  }

  .nav-icon {
    width: 22px;
    height: 22px;
  }

  .nav-label {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.01em;
  }
}

/* ── MAIN CONTENT ──────────────────────────────────────── */

@layer layout {
  #app-root {
    flex: 1;
    padding: var(--space-lg);
    padding-bottom: var(--space-2xl);
    animation: page-enter 0.35s var(--ease-out-expo);
  }

  #app-root:focus {
    outline: none;
  }

  @keyframes page-enter {
    from {
      opacity: 0;
      transform: translateY(12px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .page {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }
}

/* ── GLASS COMPONENT ───────────────────────────────────── */

@layer components {
  .glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
  }

  .glass-card {
    padding: var(--space-xl);
    box-shadow: var(--shadow-glass);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s var(--ease-out-expo);
  }

  .glass-card:active {
    transform: scale(0.985);
    border-color: var(--glass-border-hover);
  }

  .glass-input {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    color: var(--text-primary);
    font-size: var(--input-font-size);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
  }

  .glass-input:focus {
    border-color: var(--glass-border-focus);
    box-shadow: 0 0 0 3px var(--brand-glow);
  }

  .glass-input::placeholder {
    color: var(--text-tertiary);
  }
}

/* ── BUTTONS ───────────────────────────────────────────── */

@layer components {
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: var(--text-sm);
    letter-spacing: 0.01em;
    transition: all 0.2s var(--ease-out-expo);
    white-space: nowrap;
    min-height: 44px;
  }

  .btn-primary {
    background: var(--brand);
    color: var(--text-on-brand);
    box-shadow: 0 2px 12px var(--brand-glow);
  }

  .btn-primary:active {
    background: var(--brand-active);
    box-shadow: 0 1px 6px var(--brand-glow);
    transform: scale(0.96);
  }

  .btn-secondary {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
  }

  .btn-secondary:active {
    background: var(--glass-bg-active);
    color: var(--text-primary);
  }

  .btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger);
  }

  .btn-danger:active {
    opacity: 0.8;
  }

  .btn-small {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--text-xs);
    font-weight: 600;
  }

  .btn-full {
    width: 100%;
    justify-content: center;
    margin-top: var(--space-sm);
  }

  .btn-icon {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
  }

  .chart-container {
    position: relative;
    width: 100%;
  }

  .chart-doughnut {
    max-width: 260px;
    margin: 0 auto var(--space-lg);
  }

  .chart-bar {
    margin-bottom: var(--space-lg);
  }

  .chart-line {
    margin-bottom: var(--space-sm);
  }
}

/* ── DIALOG ────────────────────────────────────────────── */

@layer components {
  .dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    animation: overlay-in 0.2s ease;
  }

  @keyframes overlay-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  .dialog {
    background: var(--glass-bg-solid);
    backdrop-filter: blur(28px) saturate(1.5);
    -webkit-backdrop-filter: blur(28px) saturate(1.5);
    border: 1px solid var(--glass-border-hover);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow-lg);
    animation: dialog-in 0.25s var(--ease-out-expo);
  }

  @keyframes dialog-in {
    from {
      opacity: 0;
      transform: scale(0.95) translateY(8px);
    }

    to {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }

  .dialog-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
  }

  .dialog-message {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: var(--space-lg);
  }

  .dialog-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    color: var(--text-primary);
    font-size: var(--input-font-size);
    margin-bottom: var(--space-lg);
  }

  .dialog-input:focus {
    border-color: var(--glass-border-focus);
    box-shadow: 0 0 0 3px var(--brand-glow);
  }

  .dialog-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
  }

  .btn-cancel {
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
  }

  .btn-cancel:active {
    background: var(--glass-bg-active);
    color: var(--text-primary);
  }

  [data-theme="dark"] .dialog-overlay {
    background: rgba(0, 0, 0, 0.5);
  }

  [data-theme="dark"] .dialog-input {
    background: rgba(255, 255, 255, 0.04);
  }
}

/* ── TOAST ─────────────────────────────────────────────── */

@layer components {
  #toast-container {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-lg));
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
    max-width: 360px;
    width: calc(100% - var(--space-2xl) * 2);
  }

  .toast {
    background: var(--glass-bg-solid);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid var(--glass-border-hover);
    border-radius: var(--radius-full);
    padding: var(--space-md) var(--space-xl);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in 0.4s var(--ease-out-expo);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }

  .toast svg {
    display: inline;
    flex-shrink: 0;
  }

  .toast.out {
    animation: toast-out 0.3s ease forwards;
  }

  @keyframes toast-in {
    from {
      opacity: 0;
      transform: translateY(16px) scale(0.95);
    }

    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  @keyframes toast-out {
    from {
      opacity: 1;
      transform: translateY(0) scale(1);
    }

    to {
      opacity: 0;
      transform: translateY(8px) scale(0.95);
    }
  }

  .toast.success svg {
    color: var(--success);
  }

  .toast.success {
    border-color: rgba(21, 128, 61, 0.25);
    background: rgba(238, 255, 242, 0.94);
  }
}

/* ── CONFETTI ──────────────────────────────────────────── */

@layer components {
  .confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 300;
    overflow: hidden;
  }

  .confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    top: -10px;
    animation: confetti-fall 1.5s ease-in forwards;
  }

  @keyframes confetti-fall {
    0% {
      transform: translateY(0) rotate(0deg) scale(1);
      opacity: 1;
    }

    100% {
      transform: translateY(100vh) rotate(720deg) scale(0);
      opacity: 0;
    }
  }
}

/* ── REDUCED MOTION ────────────────────────────────────── */

@layer animations {
  @media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ── DARK THEME OVERRIDES ─────────────────────────────── */

@layer theme {
  [data-theme="dark"] .app-header {
    background: rgba(10, 22, 14, 0.7);
  }

  [data-theme="dark"] .bottom-nav {
    background: rgba(10, 22, 14, 0.75);
  }

  [data-theme="dark"] .bg-noise {
    opacity: 0.7;
  }

  [data-theme="dark"] .bg-orb {
    opacity: 0.18;
  }

  [data-theme="dark"] .heatmap-cell {
    background: rgba(255, 255, 255, 0.04);
  }

  [data-theme="dark"] .heatmap-cell.d1 {
    background: rgba(74, 222, 128, 0.15);
  }

  [data-theme="dark"] .heatmap-cell.d2 {
    background: rgba(74, 222, 128, 0.35);
  }

  [data-theme="dark"] .heatmap-cell.d3 {
    background: rgba(74, 222, 128, 0.7);
    color: var(--text-on-brand);
  }

  [data-theme="dark"] .heatmap-cell.d4 {
    background: var(--brand);
    color: var(--text-on-brand);
  }

  [data-theme="dark"] .heatmap-dot {
    background: rgba(255, 255, 255, 0.04);
  }

  [data-theme="dark"] .breakdown-bar-track {
    background: rgba(255, 255, 255, 0.04);
  }

  [data-theme="dark"] .equivalent-item {
    background: rgba(255, 255, 255, 0.04);
  }

  [data-theme="dark"] .setting-input {
    background: rgba(255, 255, 255, 0.04);
  }

  [data-theme="dark"] .setting-input:focus {
    background: rgba(255, 255, 255, 0.02);
  }

  [data-theme="dark"] .toast {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  }

  [data-theme="dark"] .toast.success {
    border-color: rgba(74, 222, 128, 0.3);
    background: rgba(22, 44, 30, 0.9);
  }

  .icon-moon {
    display: block;
  }

  .icon-sun {
    display: none;
  }

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

  [data-theme="dark"] .icon-sun {
    display: block;
  }
}

/* ── RESPONSIVE — DESKTOP ──────────────────────────────── */

@media (min-width: 768px) {
  .app-shell {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
      "header header"
      "nav    main";
    max-width: none;
    min-height: 100dvh;
  }

  .app-header {
    grid-area: header;
    padding-left: 24px;
    padding-right: 24px;
  }

  .bottom-nav {
    grid-area: nav;
    position: static;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 2px;
    padding: var(--space-lg) 0;
    height: auto;
    border-top: none;
    border-right: 1px solid var(--glass-border);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 20px;
    border-radius: 0;
    font-size: var(--text-sm);
    min-height: 44px;
    position: relative;
    width: 100%;
  }

  .nav-item.active::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--brand);
    border-radius: 0 3px 3px 0;
  }

  .nav-item.active::before {
    display: none;
  }

  .nav-item .nav-label {
    font-size: var(--text-sm);
  }

  #app-root {
    grid-area: main;
    padding: 24px 32px;
    overflow-y: auto;
    max-height: calc(100dvh - 56px);
  }

  .page {
    max-width: 1200px;
  }

  .btn-full {
    max-width: 360px;
  }

  .dialog-overlay .dialog {
    max-width: 440px;
  }

  #toast-container {
    bottom: var(--space-lg);
    left: calc(220px + ((100vw - 220px) / 2));
  }
}

/* ── iOS 27 home-screen web app top blur workaround ────── */

html[data-ios27="true"] {
  --ios27-blur-gap: 0px;
}

@media (orientation: portrait) and (max-width: 767px) {
  html[data-ios27="true"] {
    --ios27-blur-gap: 20px;
  }

  html[data-ios27="true"] .app-header {
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px) + var(--ios27-blur-gap));
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px) + var(--ios27-blur-gap));
    background: var(--bg-body);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}