:root {
    --bg: #f5f0eb;
    --surface: #f5f0eb;
    --surface-peak: #ffd6d6;
    --peak-shadow-dark: #c49a9a;
    --peak-shadow-light: #fff5f5;
    --shadow-dark: rgba(0, 0, 0, 0.18);
    --shadow-light: rgba(255, 255, 255, 0.85);
    --text: #4a4038;
    --text-secondary: #6b5e55;
    --text-muted: #8c7e74;
    --clock-tick: #d8d0c8;
    --clock-tick-major: #c4bbb0;
    --needle: #b56b6b;
    --needle-dot: #b56b6b;
    --clock-digital: #6b5e55;
    --top-semicircle: rgba(0,0,0,0.06);
    --peak-fill: rgba(180, 140, 130, 0.3);
    --peak-stroke: rgba(160, 120, 110, 0.35);
    --star-off: #d4cdc4;
    --star-on: #e0a844;
    --header-bg: rgba(245, 240, 235, 0.85);
    --search-bg: var(--surface);
    --provider-icon-bg: #e8e0d8;
    --provider-icon-text: #4a4038;
    --grain-opacity: 0.8;
    --text-shadow-deboss: 0 1px 0 rgba(255, 255, 255, 0.9);
    --selection-bg: rgba(180, 140, 130, 0.4);
}

[data-theme="dark"] {
    --bg: transparent;
    --surface: rgba(25, 5, 55, 0.92);
    --surface-peak: rgba(45, 8, 40, 0.94);
    --shadow-dark: rgba(0, 0, 0, 0.95);
    --shadow-light: rgba(107, 1, 107, 0.6);
    --peak-shadow-dark: #000000;
    --text: #e0e0e0;
    --text-secondary: #b0a8b4;
    --text-muted: #8b7cb8;
    --clock-tick: #4a2a6e;
    --clock-tick-major: #7a5d9e;
    --needle: #d08484;
    --needle-dot: #d08484;
    --clock-digital: #b0a8b4;
    --top-semicircle: rgba(255,255,255,0.06);
    --peak-fill: rgba(220, 140, 180, 0.35);
    --peak-stroke: rgba(220, 140, 180, 0.5);
    --star-off: #4a2e64;
    --star-on: #f0c040;
    --header-bg: rgba(10, 0, 30, 0.75);
    --search-bg: rgba(25, 5, 55, 0.85);
    --provider-icon-bg: #4a2a6e;
    --provider-icon-text: #d4cfd8;
    --grain-opacity: 0.35;
    --text-shadow-deboss: 0 1px 0 rgba(255, 255, 255, 0.15);
    --selection-bg: rgba(140, 100, 200, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    background: var(--bg); color: var(--text);
    min-height: 100vh;
    transition: background 0.35s, color 0.35s;
    -webkit-font-smoothing: antialiased;
    position: relative;
    z-index: 0;
}

[data-theme="dark"] body {
    background: linear-gradient(137deg, #22004e 0%, #000000 50%, #2a0039 100%);
    background-size: 400% 400%;
    background-attachment: fixed;
    animation: gradient 30s ease infinite;
}

@keyframes gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

body::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 1;
    opacity: var(--grain-opacity);
    mix-blend-mode: overlay;
}

[data-theme="light"] body::before { filter: url(#noiseFilterLight); }
[data-theme="dark"] body::before { filter: url(#noiseFilterDark); }

/* Fixed buttons */
.fixed-btn {
    position:fixed; top:20px; z-index:1000;
    width:36px; height:36px; border-radius:50%;
    background: var(--surface);
    border: none;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    user-select:none; -webkit-tap-highlight-color:transparent;
}
.fixed-btn:hover { transform:scale(1.05); }
.fixed-btn:active {
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
    transform: scale(0.95);
}
.fixed-btn svg { width: 18px; height: 18px; pointer-events: none; }

.theme-toggle { left:20px; }
.github-btn { 
    right:66px; 
    text-decoration: none;
    color: var(--text-secondary);
    background: var(--surface);
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
}
.github-btn:hover {
    transform: scale(1.05);
    color: var(--text-secondary);
}
.github-btn:active {
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
    transform: scale(0.95);
}
.settings-btn { right:20px; }

/* Settings Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.settings-panel {
    background: var(--surface);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: 5px 5px 10px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    text-align: center;
    max-width: 320px;
    width: 90%;
    border: none;
}
[data-theme="dark"] .settings-panel {
    border: 1px solid rgba(140, 100, 200, 0.2);
}
.settings-title {
    font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; color: var(--text);
}
.settings-version {
    font-size: 0.8rem; color: var(--text-muted); margin-bottom: 16px;
}
.settings-licences {
    font-size: 0.7rem; color: var(--text-muted); margin-bottom: 12px;
    text-align: center;
}
.settings-licences a {
    color: var(--text-muted);
    text-decoration: none;
    transition: text-decoration 0.2s;
}
.settings-licences a:hover {
    text-decoration: underline;
}
.settings-logo-link {
    display: inline-block;
    margin-bottom: 12px;
}
.settings-logo {
    width: 88px; height: 88px;
    border-radius: 10px;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    transition: transform 0.2s;
}
.settings-logo-link:hover .settings-logo {
    transform: scale(1.05);
}
.settings-attribution {
    font-size: 0.7rem; color: var(--text-muted);
    display: flex; flex-direction: column; gap: 4px;
    border-top: 1px solid var(--shadow-light); padding-top: 12px;
}
.settings-attribution a {
    color: var(--text-muted);
    text-decoration: none;
    transition: text-decoration 0.2s;
}
.settings-attribution a:hover {
    text-decoration: underline;
}

/* Header */
.header {
    text-align:center; padding:20px 20px 10px;
    position:sticky; top:0; z-index:50;
    background: var(--header-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 6px 12px var(--shadow-dark), 0 -1px 0 var(--shadow-light);
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

/* Search */
.search-wrapper {
    position: relative; width:100%; max-width:450px; margin: 0 auto 14px;
}
.search-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    width: 18px; height: 18px; pointer-events: none; color: var(--text);
    opacity: 0; transition: opacity 0.2s;
}
.search-input {
    width:100%; padding:10px 36px 10px 20px;
    border-radius:15px; border: none;
    background: var(--search-bg); color: var(--text);
    font-size:1.0rem; display:block;
    box-shadow: inset 2px 2px 5px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
    outline:none; transition: all 0.2s ease;
    text-align: center;
}
.search-input:focus {
    box-shadow: inset 2px 2px 5px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
}
.search-input::placeholder {
    color: var(--text-muted); opacity: 0.7; text-align: center;
}
.search-input:focus::placeholder { opacity: 0; }
.search-wrapper:focus-within .search-icon { opacity: 0.7; }

.search-clear {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted);
    font-size: 1.2rem; cursor: pointer; display: none;
    align-items: center; justify-content: center; padding: 2px; line-height: 1;
    transition: color 0.2s;
}
.search-clear.visible { display: flex; }
.search-clear:hover { color: var(--text); }

/* Time blocks */
.time-display {
    display:flex; justify-content:center; gap:16px; flex-wrap:wrap;
    margin-bottom:8px; font-family:'SF Mono', monospace;
}
.time-block {
    display:flex; align-items:center; gap:6px;
    background: var(--surface); padding:8px 16px;
    border-radius:20px; border: none;
    font-size:0.9rem;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
}
.time-label { font-weight:600; font-size:0.7rem; text-transform:uppercase; color:var(--text-muted); }
.time-value { text-shadow: var(--text-shadow-deboss); }

/* Cards grid */
.grid-container {
    padding:24px 20px 60px;
    display:grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap:20px; justify-items:center; position: relative; z-index: 2;
}
@media (max-width:400px) { .grid-container { grid-template-columns:1fr; padding:16px 12px 50px; gap:14px; } }

/* Card */
.card {
    background: var(--surface);
    border: none;
    border-radius: 20px;
    padding:24px 22px 22px;
    box-shadow: 5px 5px 10px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    transition: all 0.2s ease;
    display:flex; flex-direction:column; align-items:center; gap:14px;
    position:relative; width:100%; max-width:360px;
}
[data-theme="dark"] .card { border: 1px solid rgba(140, 100, 200, 0.2); }

.card.peak-penalty {
    background: var(--surface-peak);
    box-shadow: inset 4px 4px 6px var(--peak-shadow-dark);
    border: none;
    border-bottom: 2px solid rgba(220, 120, 160, 0.25);
    border-right: 2px solid rgba(220, 120, 160, 0.25);
}

.card-header {
    display: flex; align-items: center; gap: 10px;
    width: 100%; justify-content: center;
}

.provider-icon-link { text-decoration: none; display: inline-flex; }

.provider-icon-img {
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--provider-icon-bg); color: var(--provider-icon-text);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem; font-family: 'Inter', sans-serif;
    letter-spacing: 0.05em; flex-shrink: 0;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    transition: transform 0.2s;
    object-fit: contain; padding: 6px;
}
.provider-icon-link:hover .provider-icon-img { transform: scale(1.1); }

.card-name {
    font-size:1.15rem; font-weight:600; letter-spacing:-0.02em;
    color:var(--text); text-shadow: var(--text-shadow-deboss);
}

.card-clock-wrap { width:180px; height:180px; position:relative; }
.card-clock-wrap svg { width:100%; height:100%; display:block; }

/* SVG clock elements */
.clock-face {
    fill: var(--surface); stroke: none;
    filter: drop-shadow(2px 2px 4px var(--shadow-dark)) drop-shadow(-1px -1px 0 var(--shadow-light));
}
.peak-arc {
    filter: drop-shadow(1px 1px 2px var(--shadow-dark)) drop-shadow(-1px -1px 0 var(--shadow-light));
}
.clock-hand {
    stroke: var(--needle); stroke-width: 2.2; stroke-linecap: round;
    filter: drop-shadow(1px 1px 2px var(--shadow-dark));
}
.center-dot { fill: var(--needle-dot); filter: drop-shadow(1px 1px 2px var(--shadow-dark)); }
.digital-time { text-shadow: var(--text-shadow-deboss); }
.clock-number {
    text-shadow: var(--text-shadow-deboss);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    font-size: 11px; fill: var(--text-muted);
}

.card-divider { width:100%; border:none; border-top:1px solid var(--shadow-light); margin:4px 0; opacity:0.5; }

.card-countdown {
    font-size:1rem; font-weight:600; padding:6px 16px;
    border-radius:20px; font-family:'SF Mono', monospace;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
}
.to-peak { color:#c74560; background:var(--surface); }
.to-nonpeak { color:#2a9d5c; background:var(--surface); }
[data-theme="dark"] .to-peak { color:#ff8da1; }
[data-theme="dark"] .to-nonpeak { color:#4cdb8a; }

.card-countdown.no-peak {
    box-shadow: none; border: 1px solid var(--shadow-light);
    opacity: 0.5; background: transparent; color: var(--text-muted);
}

.card-schedule {
    font-size:0.82rem; color:var(--text-secondary);
    font-family:'SF Mono', monospace; text-decoration:none;
    display:flex; align-items:center; gap:4px; transition:opacity 0.2s;
}
.card-schedule:hover { opacity:0.7; text-decoration:underline; }
.card-schedule svg { width:14px; height:14px; color:inherit; flex-shrink:0; }

.star-btn {
    position:absolute; top:10px; right:12px;
    background: var(--surface); border: none; cursor:pointer;
    padding:4px; border-radius:50%;
    box-shadow: 2px 2px 4px var(--shadow-dark), -1px -1px 0 var(--shadow-light);
    color:var(--star-off); transition: all 0.2s ease;
    display:flex; align-items:center; justify-content:center; z-index:2;
}
.star-btn:hover { transform: scale(1.05); }
.star-btn:active {
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
    transform: scale(0.92);
}
.star-btn.starred {
    color: var(--star-on);
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -1px -1px 0 var(--shadow-light);
    transform: scale(0.97);
}
.star-btn.starred:hover { transform: scale(0.98); }
.star-btn.starred:active { transform: scale(0.92); }
.star-btn svg { width:16px; height:16px; pointer-events:none; }

.card.hidden { display:none; }

/* Custom selection color */
::selection {
    background: var(--selection-bg);
}
::-moz-selection {
    background: var(--selection-bg);
}