/* ============================================
   Sleep Calculator v3 — Premium Therapeutic
   Starfield + glassmorphism + tactile micro-interactions
   ============================================ */

/* ---- Design Tokens ---- */
:root {
    --bg-deep: #040810;
    --bg: #090e1a;
    --bg-surface: #0e1525;
    --bg-card: rgba(18, 26, 44, 0.7);
    --bg-card-solid: #141e30;
    --bg-card-hover: rgba(22, 31, 50, 0.85);
    --bg-input: rgba(12, 18, 30, 0.7);
    --accent: #d4a574;
    --accent-dim: #b8895a;
    --accent-soft: rgba(212, 165, 116, 0.08);
    --accent-glow: rgba(212, 165, 116, 0.18);
    --text: #e8e5df;
    --text-secondary: #a5a29c;
    --text-muted: #6e6b65;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.10);
    --radius: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.35);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.55);
    --shadow-glow: 0 0 40px var(--accent-glow);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --max-w: 660px;
    --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    line-height: 1.72;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ---- Canvas Starfield Background ---- */
#starfield {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

/* ---- Ambient Gradient Overlay ---- */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 60% 40% at 30% 20%, rgba(212, 165, 116, 0.025) 0%, transparent 70%),
        radial-gradient(ellipse 50% 35% at 70% 75%, rgba(130, 120, 200, 0.02) 0%, transparent 70%);
    animation: aurora-drift 30s ease-in-out infinite;
}

@keyframes aurora-drift {
    0%, 100% { opacity: 0.6; }
    33% { opacity: 1; }
    66% { opacity: 0.5; }
}

/* ---- Typography ---- */
h1 { font-size: 2.25rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
h2 { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.015em; }
h3 { font-size: 1rem; font-weight: 600; }
p  { color: var(--text-secondary); line-height: 1.72; }

a { color: var(--accent); text-decoration: none; transition: color 0.2s var(--ease-out); }
a:hover { color: #e8c49a; }

/* ---- Layout ---- */
.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 1.5rem;
    position: relative;
    z-index: 1;
}

/* ---- Navigation ---- */
.nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    background: rgba(4, 8, 16, 0.78);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.nav-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.75rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.nav-brand-icon { font-size: 1.2rem; }

.nav-links { display: flex; list-style: none; gap: 0.1rem; }

.nav-links a {
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s var(--ease-out);
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    background: var(--bg-card);
}

/* ============================================
   BUTTONS — with ripple
   ============================================ */
.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.72rem 1.5rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.925rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    overflow: hidden;
    transition: all 0.25s var(--ease-out);
    -webkit-user-select: none;
    user-select: none;
}

.btn:active { transform: scale(0.965); }

/* Ripple element */
.btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    transform: scale(0);
    animation: ripple-effect 0.7s var(--ease-out) forwards;
    pointer-events: none;
}

@keyframes ripple-effect {
    to { transform: scale(4); opacity: 0; }
}

.btn-primary {
    background: var(--accent);
    color: #1a1410;
    box-shadow: 0 2px 12px rgba(212, 165, 116, 0.2);
}

.btn-primary:hover {
    background: #deb887;
    box-shadow: 0 4px 24px rgba(212, 165, 116, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: scale(0.965);
    box-shadow: 0 1px 8px rgba(212, 165, 116, 0.15);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
}

.btn-ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-ghost .ripple { background: rgba(212, 165, 116, 0.1); }

.btn-lg {
    padding: 0.95rem 2.25rem;
    font-size: 1.05rem;
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: 0.45rem 1rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* ---- Toggle ---- */
.toggle-group {
    display: inline-flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    white-space: nowrap;
}

.toggle-btn.active {
    background: var(--bg-card-solid);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

/* ============================================
   CUSTOM RANGE SLIDER
   ============================================ */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: var(--border-strong);
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-deep);
    box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-sm);
    cursor: grab;
    transition: all 0.2s var(--ease-out);
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 0 6px var(--accent-soft), var(--shadow-md);
    transform: scale(1.1);
}

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    box-shadow: 0 0 0 10px var(--accent-soft), 0 0 28px var(--accent-glow);
}

/* ============================================
   HERO
   ============================================ */
.hero {
    padding: 7rem 0 3rem;
    text-align: center;
}

.hero h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--text) 20%, var(--accent) 80%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: title-breathe 6s ease-in-out infinite;
}

@keyframes title-breathe {
    0%, 100% { filter: brightness(1) saturate(1); }
    50% { filter: brightness(1.12) saturate(1.1); }
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 400px;
    margin: 0.75rem auto 0;
}

/* ============================================
   MAIN CALCULATOR — glass card
   ============================================ */
.section { padding: 2.5rem 0; }

.calc-card {
    background: linear-gradient(145deg,
        rgba(22, 30, 48, 0.75) 0%,
        rgba(16, 22, 38, 0.65) 50%,
        rgba(22, 30, 48, 0.7) 100%);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.04) inset,
        var(--shadow-md);
    transition: all 0.5s var(--ease-out);
}

.calc-card:hover {
    border-color: var(--border-strong);
    box-shadow:
        0 1px 0 rgba(255,255,255,0.06) inset,
        var(--shadow-lg),
        var(--shadow-glow);
}

.calc-mode {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.calc-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* Time input — custom-styled */
.calc-time-input {
    text-align: center;
}

.calc-time-input label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.calc-time-input input[type="time"] {
    font-size: 3rem;
    font-weight: 700;
    font-family: var(--font);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-lg);
    transition: all 0.3s var(--ease-out);
    letter-spacing: 0.03em;
    width: 200px;
    cursor: pointer;
}

.calc-time-input input[type="time"]:hover {
    border-color: var(--border-strong);
    background: rgba(14, 21, 37, 0.9);
}

.calc-time-input input[type="time"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), 0 0 20px var(--accent-glow);
    background: rgba(14, 21, 37, 0.95);
}

.calc-time-input input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7) sepia(0.3) saturate(2);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.calc-time-input input[type="time"]:hover::-webkit-calendar-picker-indicator {
    opacity: 1;
}

/* Sleep Now */
.sleep-now-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.825rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    background: none;
    border: none;
    font-family: var(--font);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
}

.sleep-now-btn:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

/* Latency */
.latency-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 340px;
}

.latency-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 95px;
    text-align: right;
}

.latency-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 48px;
}

/* Results */
.calc-results {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    width: 100%;
    margin-top: 0.25rem;
}

.result-card {
    background: rgba(12, 18, 30, 0.6);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 0.5rem;
    text-align: center;
    transition: all 0.35s var(--ease-out);
    animation: result-pop 0.55s var(--ease-spring) backwards;
}

.result-card:nth-child(1) { animation-delay: 0.05s; }
.result-card:nth-child(2) { animation-delay: 0.13s; }
.result-card:nth-child(3) { animation-delay: 0.21s; }
.result-card:nth-child(4) { animation-delay: 0.29s; }

.result-card.recommended {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 28px var(--accent-glow);
    transform: scale(1.04);
}

.result-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.result-card.recommended:hover {
    transform: scale(1.04) translateY(-2px);
}

.result-card .time {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.2rem;
    letter-spacing: -0.01em;
}

.result-card .meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.result-card .badge-rec {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-top: 0.4rem;
    padding: 0.18rem 0.55rem;
    border-radius: 20px;
    background: rgba(212, 165, 116, 0.15);
    border: 1px solid rgba(212, 165, 116, 0.2);
}

@keyframes result-pop {
    from { opacity: 0; transform: scale(0.92) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.calc-note {
    margin-top: 1.25rem;
    font-size: 0.825rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.7;
    padding: 0 0.5rem;
}

/* ============================================
   MINI TOOLS
   ============================================ */
.section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 0.5rem;
    opacity: 0.75;
}

.section-title {
    margin-bottom: 0.25rem;
}

.section-desc {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.tools-mini {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.tool-chip {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.35s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.tool-chip::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, var(--accent-soft) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.4s var(--ease-out);
}

.tool-chip:hover::before { opacity: 1; }

.tool-chip:hover {
    border-color: var(--border-strong);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md), 0 0 30px var(--accent-glow);
}

.tool-chip-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    display: block;
    transition: transform 0.35s var(--ease-spring);
}

.tool-chip:hover .tool-chip-icon {
    transform: scale(1.15) rotate(-3deg);
}

.tool-chip h3 {
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

.tool-chip p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

/* ============================================
   TOOL PANEL (Modal)
   ============================================ */
.tool-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(4, 8, 16, 0.78);
    backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.tool-overlay.active {
    display: flex;
    animation: overlay-in 0.3s var(--ease-out);
}

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

.tool-panel {
    background: linear-gradient(160deg,
        rgba(22, 30, 48, 0.9) 0%,
        rgba(14, 20, 34, 0.85) 50%,
        rgba(22, 30, 48, 0.88) 100%);
    backdrop-filter: blur(30px) saturate(1.3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    padding: 2.25rem;
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.04) inset,
        var(--shadow-lg);
    position: relative;
    animation: panel-slide 0.4s var(--ease-spring);
}

@keyframes panel-slide {
    from { opacity: 0; transform: translateY(30px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.tool-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 0.3rem;
}

.tool-panel > p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.tool-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card-solid);
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease-out);
}

.tool-close:hover {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}

/* Form elements */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.45rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    transition: all 0.2s var(--ease-out);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Tool results */
.tool-results {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: none;
    animation: result-pop 0.45s var(--ease-spring);
}

.tool-results:not(:empty) { display: block; }

.result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}

.result-item:last-child { border-bottom: none; }

.result-time {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.result-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: right;
}

.result-note {
    margin-top: 1rem;
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.7;
    padding: 0.85rem;
    background: var(--bg-input);
    border-radius: var(--radius);
}

.result-warning {
    margin-top: 0.75rem;
    font-size: 0.825rem;
    color: #d4a574;
    line-height: 1.6;
    padding: 0.75rem;
    background: rgba(212, 165, 116, 0.06);
    border: 1px solid rgba(212, 165, 116, 0.12);
    border-radius: var(--radius);
}

/* ---- Visualizer Bars ---- */
.viz-header {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.viz-bars {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.viz-cycle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.viz-cycle-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 76px;
    font-variant-numeric: tabular-nums;
}

.viz-bars-row {
    display: flex;
    gap: 2px;
    flex: 1;
    height: 34px;
}

.viz-bar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: transform 0.2s;
    animation: bar-grow 0.8s var(--ease-out) backwards;
}

.viz-bar:hover {
    transform: scaleY(1.15);
    filter: brightness(1.3);
}

@keyframes bar-grow {
    from { transform: scaleX(0); opacity: 0; }
    to { transform: scaleX(1); opacity: 1; }
}

.viz-legend {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.viz-legend span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.viz-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

/* ---- Caffeine Bar ---- */
.caffeine-bar-wrap {
    position: relative;
    height: 36px;
    background: var(--bg-input);
    border-radius: var(--radius);
    margin: 1rem 0;
    overflow: hidden;
    border: 1px solid var(--border);
}

.caffeine-bar-fill {
    height: 100%;
    border-radius: var(--radius);
    transition: width 1s var(--ease-out);
}

.caffeine-bar-label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0.75rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text);
}

/* ---- Countdown ring for nap ---- */
.countdown-ring {
    display: flex;
    justify-content: center;
    margin: 0.5rem 0 1rem;
}

.countdown-ring svg {
    transform: rotate(-90deg);
}

.countdown-bg {
    fill: none;
    stroke: var(--border-strong);
    stroke-width: 4;
}

.countdown-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s var(--ease-out);
}

.countdown-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent);
}

/* ============================================
   SCIENCE
   ============================================ */
.science-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.science-row {
    display: flex;
    gap: 1.25rem;
    padding: 1.5rem 1.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: all 0.3s var(--ease-out);
    align-items: flex-start;
}

.science-row:hover {
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}

.science-dot {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 0.6rem;
    box-shadow: 0 0 8px var(--accent-glow);
}

.science-row h3 {
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

.science-row p {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 560px;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
    border-top: 1px solid var(--border);
    padding: 3rem 0;
    margin-top: 2rem;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
    padding-bottom: 2rem;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.footer-col p { font-size: 0.85rem; color: var(--text-muted); }

.footer-col h4 {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: 0.35rem; }
.footer-col a { font-size: 0.85rem; color: var(--text-muted); transition: color 0.2s; }
.footer-col a:hover { color: var(--accent); }

.footer-bottom {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.footer-bottom p { font-size: 0.8rem; color: var(--text-muted); }

/* ============================================
   CONTENT PAGES (Blog / About / Legal)
   ============================================ */
.page { padding-top: 5.5rem; padding-bottom: 4rem; min-height: 60vh; margin: 0 auto; padding-left: 1.5rem; padding-right: 1.5rem; }

.page .page-header { margin-bottom: 2.5rem; }
.page .page-header h1 { margin-bottom: 0.4rem; }
.page .page-header p { font-size: 1rem; color: var(--text-muted); }

.blog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.blog-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    transition: all 0.35s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.blog-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0;
    transition: opacity 0.35s var(--ease-out);
}

.blog-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md), 0 0 30px var(--accent-glow);
}

.blog-card:hover::before {
    opacity: 0.6;
}

.blog-card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.blog-card h2 a { color: var(--text); transition: color 0.2s; }
.blog-card h2 a:hover { color: var(--accent); }

.blog-card .blog-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.blog-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.65;
}

.blog-card .read-more {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: gap 0.2s;
}

.blog-card .read-more:hover {
    gap: 0.5rem;
}

.article-page { max-width: 680px; }

/* Article header */
.article-page article h1 {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
    margin-bottom: 0.6rem;
}

.article-page .article-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

/* Lead paragraph */
.article-page article > p:first-of-type {
    font-size: 1.075rem;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 2rem;
}

/* Section headings */
.article-page h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-top: 3rem;
    margin-bottom: 0.85rem;
    padding-top: 0;
    color: var(--text);
    letter-spacing: -0.01em;
}

.article-page h2::before {
    content: '';
    display: block;
    width: 32px;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    margin-bottom: 0.75rem;
}

.article-page h3 {
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
}

/* Body text */
.article-page p {
    margin-bottom: 1.1rem;
    line-height: 1.78;
    color: var(--text-secondary);
}

/* Lists */
.article-page ul, .article-page ol {
    margin: 0.75rem 0 1.5rem 1.75rem;
    color: var(--text-secondary);
    line-height: 1.78;
}

.article-page li {
    margin-bottom: 0.45rem;
    padding-left: 0.25rem;
}

.article-page li::marker {
    color: var(--text-muted);
}

/* Emphasis / key points */
.article-page strong {
    color: var(--text);
    font-weight: 600;
}

/* Tables */
.article-page table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

.article-page thead {
    background: var(--bg-card-solid);
}

.article-page th {
    padding: 0.8rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    border-bottom: 1px solid var(--border-strong);
    letter-spacing: 0.02em;
}

.article-page td {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.article-page tbody tr:last-child td {
    border-bottom: none;
}

.article-page tbody tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
.article-page tbody tr:hover td {
    background: var(--bg-card);
}

/* Conclusion */
.article-page article > p:last-of-type {
    margin-top: 2rem;
}

.content-page { max-width: 660px; }
.content-page .page-header { margin-bottom: 3rem; }
.content-page .page-header h1 { margin-bottom: 0.4rem; }
.content-page .page-header p { font-size: 1rem; color: var(--text-muted); }
.content-page section { margin-bottom: 2.5rem; padding-bottom: 2.5rem; border-bottom: 1px solid var(--border); }
.content-page section:last-of-type { border-bottom: none; padding-bottom: 0; }
.content-page h2 { font-size: 1.2rem; margin-bottom: 0.75rem; color: var(--text); }
.content-page h3 { margin: 1.25rem 0 0.5rem; color: var(--text-secondary); font-size: 0.95rem; }
.content-page p { margin-bottom: 0.85rem; line-height: 1.75; }
.content-page ul,.content-page ol { margin: 0.5rem 0 1.25rem 1.5rem; color: var(--text-secondary); line-height: 1.75; }
.content-page li { margin-bottom: 0.4rem; }
.content-page .last-updated { font-size: 0.825rem; color: var(--text-muted); margin-bottom: 2rem; }
.content-page .values-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.content-page .value-item { padding: 1.25rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.content-page .value-item h3 { margin: 0 0 0.35rem; font-size: 0.95rem; color: var(--accent); }
.content-page .value-item p { font-size: 0.85rem; margin: 0; color: var(--text-muted); }
.content-page .contact-methods { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.5rem 0; }
.content-page .contact-card { padding: 1.5rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); text-align: center; }
.content-page .contact-card-icon { font-size: 1.5rem; margin-bottom: 0.5rem; }
.content-page .contact-card h3 { margin: 0 0 0.25rem; font-size: 0.9rem; }
.content-page .contact-card p { font-size: 0.85rem; margin: 0; color: var(--text-muted); }
@media (max-width: 480px) { .content-page .values-grid, .content-page .contact-methods { grid-template-columns: 1fr; } }



/* ---- Blog CTA Box ---- */
.cta-box {
    background: var(--accent-soft);
    border: 1px solid rgba(212, 165, 116, 0.15);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
    margin: 2rem 0;
    text-align: center;
}

.cta-box h3 {
    font-size: 1rem;
    margin-bottom: 0.35rem;
    color: var(--text);
}

.cta-box p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.cta-button {
    display: inline-flex;
    align-items: center;
    padding: 0.65rem 1.4rem;
    background: var(--accent);
    color: #1a1410;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.2s var(--ease-out);
}

.cta-button:hover {
    background: #deb887;
    color: #1a1410;
    box-shadow: 0 4px 18px var(--accent-glow);
}

/* Related articles at bottom of blog posts */
.related-articles {
    margin-top: 3rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.related-articles h3 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.related-articles ul {
    list-style: none;
    margin: 0;
}

.related-articles li {
    margin-bottom: 0.35rem;
}

.related-articles a {
    font-size: 0.875rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.9rem; }
    .calc-results { grid-template-columns: 1fr 1fr; }
    .tools-mini { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr 1fr; }
    .science-grid { grid-template-columns: 1fr 1fr; }
    .calc-card { padding: 1.75rem 1.25rem; }
    .calc-time-input input[type="time"] { font-size: 2.25rem; width: 170px; }
}

@media (max-width: 480px) {
    .hero h1 { font-size: 1.6rem; }
    .calc-results { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .tools-mini { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr; }
    .science-grid { grid-template-columns: 1fr; }
    .calc-card { padding: 1.5rem 1rem; }
    .calc-time-input input[type="time"] { font-size: 1.8rem; width: 150px; }
    .result-card { padding: 1rem 0.4rem; }
    .result-card .time { font-size: 1rem; }
    .nav-links a { padding: 0.3rem 0.5rem; font-size: 0.78rem; }
}

/* ============================================
   V4 ADDITIONS — Deep tool enhancements
   ============================================ */

/* ---- Age Selector ---- */
.age-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 0.25rem;
}

.age-selector label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.age-selector select {
    padding: 0.4rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.age-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---- Sleep Score ---- */
.sleep-score {
    margin-top: 1rem;
    text-align: center;
}

.sleep-score-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.sleep-score-bar-wrap {
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    overflow: hidden;
    max-width: 200px;
    margin: 0 auto;
}

.sleep-score-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s var(--ease-out);
}

.sleep-score-text {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ---- Nap Stage Visualization ---- */
.nap-stages {
    display: flex;
    gap: 2px;
    height: 28px;
    margin: 1rem 0;
    border-radius: 6px;
    overflow: hidden;
}

.nap-stage-bar {
    height: 100%;
    transition: all 0.5s var(--ease-out);
    animation: bar-grow 0.6s var(--ease-out) backwards;
    position: relative;
}

/* nap-stage-bar::after removed — using .nap-stage-labels instead */


.nap-stage-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 1.5rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ---- Caffeine Drink Picker ---- */
.drink-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.drink-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.65rem 0.4rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    font-family: var(--font);
}

.drink-chip:hover {
    border-color: var(--border-strong);
    background: var(--bg-card);
}

.drink-chip.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.drink-chip-icon {
    font-size: 1.25rem;
}

.drink-chip-name {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 500;
}

.drink-chip-amount {
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: 600;
}

/* ---- Caffeine Multi-Checkpoint ---- */
.caff-checkpoints {
    display: flex;
    justify-content: space-between;
    margin-top: 0.75rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.caff-checkpoint {
    text-align: center;
    flex: 1;
}

.caff-checkpoint-time {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.caff-checkpoint-mg {
    font-size: 0.68rem;
}

/* ---- Quality Meter ---- */
.quality-meter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 600;
}

.quality-meter.good {
    background: rgba(90, 150, 112, 0.12);
    border: 1px solid rgba(90, 150, 112, 0.2);
    color: #7ab890;
}

.quality-meter.caution {
    background: rgba(212, 165, 116, 0.1);
    border: 1px solid rgba(212, 165, 116, 0.18);
    color: var(--accent);
}

.quality-meter.bad {
    background: rgba(196, 106, 90, 0.12);
    border: 1px solid rgba(196, 106, 90, 0.2);
    color: #c46a5a;
}

/* ---- Visualizer Wake Window ---- */
.viz-wake-marker {
    margin-left: 86px;
    padding: 0.15rem 0 0.35rem;
    display: flex;
    align-items: center;
}

.wake-window {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    background: rgba(212, 165, 116, 0.08);
    border: 1px dashed rgba(212, 165, 116, 0.2);
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* ---- Custom Time Picker (spinner) ---- */
.time-spinner {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: center;
}

.time-spinner-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.time-spinner-btn {
    width: 32px;
    height: 28px;
    border: none;
    background: var(--bg-input);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
}

.time-spinner-btn:hover {
    background: var(--bg-card);
    color: var(--accent);
}

.time-spinner-value {
    font-size: 2.5rem;
    font-weight: 700;
    font-family: var(--font);
    color: var(--text);
    width: 60px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.time-spinner-colon {
    font-size: 2rem;
    font-weight: 300;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.time-spinner-ampm {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    transition: all 0.15s;
    margin-left: 0.5rem;
}

.time-spinner-ampm:hover {
    color: var(--accent);
    background: var(--bg-input);
}

@media (max-width: 480px) {
    .drink-grid { grid-template-columns: repeat(2, 1fr); }
    .time-spinner-value { font-size: 1.8rem; width: 48px; }
    .time-spinner-btn { width: 40px; height: 36px; font-size: 1.2rem; }
    .viz-cycle-label { min-width: 52px; font-size: 0.68rem; }
}

/* Share button states */
.btn-ghost.btn-sm:hover { border-color: var(--accent); color: var(--accent); }


/* ---- Blog Share Buttons ---- */
.article-share {
    margin-top: 3rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
}

.article-share h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.share-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s var(--ease-out);
}

.share-btn:hover {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--bg-card-hover);
}

.share-btn.copied {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}
