/* --- CSS VARIABLES & RESET --- */
:root {
    /* DEFAULT (DARK) VARIABLES */
    --bg-dark: #050505; 
    --bg-light: #121212;
    --text-main: #ffffff;
    --text-muted: #a1a1a6; 
    
    /* MODE COLORS (CONSTANTS) */
    --color-focus: #FF4D30;
    --color-short: #4D96FF; 
    --color-long: #34C759; 

    /* ACTION COLOR (Purple) - Settings, Toggles, Presets */
    --color-action: #7F5AF0;
    --action-glow: rgba(127, 90, 240, 0.4);

    /* NOTIFICATION COLOR (Yellow) - Alerts */
    --color-notification: #FFD60A;
    --notification-glow: rgba(255, 214, 10, 0.45);

    /* DYNAMIC ACCENT (Defaults to Focus) */
    --accent-color: var(--color-focus); 
    --accent-glow: rgba(255, 77, 48, 0.4);
    
    /* BACKGROUND GRADIENT COLOR (Low Opacity) */
    --accent-bg-glow: rgba(255, 77, 48, 0.15); 
    
    /* UI Element Colors (Glassmorphism) */
    --glass-bg: rgba(28, 28, 30, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: 20px;
    
    --input-bg: rgba(255, 255, 255, 0.05); 
    --modal-bg: #1c1c1e;
    
    /* Ring Colors */
    --ring-track-col: rgba(255, 255, 255, 0.1);
    
    /* Dropdown Arrow */
    --arrow-color: #a1a1a6;

    /* Font Stack */
    --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- LIGHT MODE OVERRIDES --- */
body.light-mode {
    --bg-dark: #f0f0f5; 
    --bg-light: #ffffff;
    --text-main: #1d1d1f;
    --text-muted: #86868b; 
    
    --arrow-color: #1d1d1f;

    /* Glass styles for light mode */
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(0, 0, 0, 0.05);
    
    --input-bg: rgba(0, 0, 0, 0.05);
    --modal-bg: #ffffff;
    
    --ring-track-col: rgba(0, 0, 0, 0.05);
}

/* --- DYNAMIC MODE THEMES --- */
body[data-mode="focus"] {
    --accent-color: var(--color-focus);
    --accent-glow: rgba(255, 77, 48, 0.4);
    --accent-bg-glow: rgba(255, 77, 48, 0.15); 
}

body[data-mode="short_break"] {
    --accent-color: var(--color-short);
    --accent-glow: rgba(77, 150, 255, 0.4);
    --accent-bg-glow: rgba(77, 150, 255, 0.15); 
}

body[data-mode="long_break"] {
    --accent-color: var(--color-long);
    --accent-glow: rgba(52, 199, 89, 0.4);
    --accent-bg-glow: rgba(52, 199, 89, 0.15); 
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    height: 100dvh; 
    width: 100vw;
    overflow: hidden;
    
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 50% 0%, var(--accent-bg-glow) 0%, transparent 65%),
        radial-gradient(circle at 85% 90%, var(--accent-bg-glow) 0%, transparent 50%);
    background-attachment: fixed;
    background-repeat: no-repeat;
    
    color: var(--text-main);
    font-family: var(--font-family);
    transition: background-color 0.5s ease;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5vh;
}

/* --- HEADER --- */
.app-header {
    flex-shrink: 0;
    margin-top: 5vh; 
    margin-bottom: 0;
    text-align: center;
    width: 100%;
    padding: 0 20px;
    z-index: 10;
}

.app-title {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 800;
    margin-bottom: 0.25rem;
    color: var(--text-main);
    text-shadow: 0 2px 10px rgba(0,0,0,0.1); 
}

.app-subtitle {
    color: var(--text-muted);
    font-size: clamp(0.8rem, 3vw, 1rem);
}

/* --- MAIN LAYOUT --- */
main {
    flex: initial;
    display: flex;
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
    min-height: 0; 
    padding: 0;
    gap: 5vh;
}

/* --- GLASSMORPHISM MODE SELECTOR --- */
.mode-selector {
    display: flex;
    gap: 5px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    padding: 6px;
    border-radius: 50px; 
    z-index: 10;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 40px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mode-btn:not(.active):hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
}

body.light-mode .mode-btn:not(.active):hover {
    background: rgba(0,0,0,0.05);
}

.mode-btn.active {
    background: var(--accent-color);
    color: white;
    font-weight: 600;
    box-shadow: 0 4px 15px var(--accent-glow);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* --- THE RING --- */
.ring-container {
    position: relative;
    width: min(85vw, 55vh, 500px);
    height: min(85vw, 55vh, 500px);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; 
    background: radial-gradient(circle, var(--accent-bg-glow) 0%, transparent 70%);
    border-radius: 50%;
}

.ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(120deg); 
    overflow: visible;
}

.ring-track-svg {
    fill: none;
    stroke: var(--ring-track-col);
    stroke-width: 6; 
    stroke-linecap: round; 
    cx: 50; cy: 50; r: 42;
    stroke-dasharray: 219.9 264; 
}

.ring-progress-svg {
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 6;
    stroke-linecap: round;
    cx: 50; cy: 50; r: 42;
    stroke-dasharray: 0 264; 
    filter: drop-shadow(0 0 15px var(--accent-glow));
    transition: stroke-dasharray 0.1s linear, stroke 0.5s ease, filter 0.5s ease;
}

/* --- CONTENT INSIDE RING --- */
.ring-content {
    position: absolute;
    width: 80%;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center; 
    align-items: center;
    z-index: 20; 
}

/* --- COLLAPSIBLE WRAPPER --- */
.collapsible-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transition: all 0.5s ease;
    overflow: hidden;
    width: 100%;
    justify-items: center;
    margin-bottom: 0; 
}

.collapsible-wrapper.visible {
    grid-template-rows: 1fr; 
    opacity: 1;
    margin-bottom: 1.5rem; 
}

.collapsible-inner { min-height: 0; width: 100%; display: flex; justify-content: center; }

.status-text {
    color: var(--text-muted);
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 500;
    text-align: center;
    line-height: 1.6;
    white-space: pre-line;
}

/* --- DOTS --- */
.dots-container {
    display: flex;
    gap: 12px;
    align-items: center;
    height: 16px; 
    padding: 0 10px;
}

.dot {
    width: 8px; height: 8px;
    border: 1px solid var(--text-muted);
    border-radius: 2px;
    transition: all 0.3s;
}

.dot.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    animation: liquid-pulse 1s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

.dot.completed {
    background: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-glow);
}

@keyframes liquid-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-glow); }
    20% { transform: scale(1.5); box-shadow: 0 0 15px 4px var(--accent-glow); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0,0,0,0); }
}

/* --- TIME DISPLAY --- */
.time-display {
    font-size: clamp(3rem, 15vw, 6rem);
    font-weight: 700;
    letter-spacing: -2px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    margin-bottom: 1.5rem; 
    text-shadow: 0 4px 20px rgba(0,0,0,0.1); 
}
.time-colon {
    margin: 0 4px; 
    position: relative;
    top: -2px; 
    font-variant-numeric: normal;
}

/* --- BUTTONS --- */
.btn {
    padding: 12px 28px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    z-index: 30; 
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:hover { transform: scale(1.05); box-shadow: 0 6px 30px var(--accent-glow); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}
.btn-secondary:hover { 
    background: rgba(255,255,255,0.15); 
}
body.light-mode .btn-secondary:hover { background: rgba(0,0,0,0.1); }

.btn.hidden { display: none; }

/* SPECIFIC OVERRIDE FOR SAVE SETTINGS BUTTON (Purple) */
#saveSettingsBtn {
    background: var(--color-action) !important;
    box-shadow: 0 4px 20px var(--action-glow);
}
#saveSettingsBtn:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 30px var(--action-glow);
}

/* --- FOOTER --- */
.app-footer {
    flex-shrink: 0;
    margin-bottom: 1rem; 
    padding: 0 20px;
    width: 100%;
    text-align: center;
}
.footer-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.footer-link:hover { opacity: 1; }

/* --- SETTINGS TRIGGER (Glass) --- */
.settings-trigger {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    padding: 10px 14px;
    border-radius: 30px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.settings-trigger:hover { 
    transform: translateY(-2px); 
    color: var(--text-main);
    border-color: var(--accent-color);
}
.settings-trigger svg { width: 14px; height: 14px; fill: currentColor; }

/* --- PRESET TRIGGER (Glass) --- */
.preset-trigger-btn {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 0.85rem;
    
    /* Default state is now faded (muted) */
    color: var(--text-muted);
    
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

/* Hover state now matches Settings (colors up) */
.preset-trigger-btn:hover {
    color: var(--text-main); /* Brighten text */
    border-color: var(--accent-color); /* Glow with mode color */
    box-shadow: 0 4px 15px var(--accent-bg-glow);
    
    transform: translateY(-2px); /* Physics match */
    background: var(--glass-bg) !important; /* Force glass bg */
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); 
    backdrop-filter: blur(8px); 
    z-index: 1000;
    display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-card {
    background: var(--modal-bg);
    width: 90%; max-width: 420px; 
    border-radius: 24px;
    padding: 24px; 
    border: 1px solid var(--glass-border);
    
    max-height: 90vh; 
    overflow-y: auto; 
    
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    color: var(--text-main);
    transition: background 0.3s;
    
    scroll-behavior: smooth;
    scrollbar-width: thin; 
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent; 
}
body.light-mode .modal-card {
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent; 
}

.wide-modal { max-width: 500px; }

.modal-header { display: flex; justify-content: space-between; margin-bottom: 12px; align-items: center;}
.modal-title { font-weight: 700; font-size: 1.3rem; }
.close-btn { background:transparent; border:none; color: var(--text-main); font-size:1.6rem; cursor:pointer; line-height: 1;}

.modal-subtitle {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 24px; 
    margin-bottom: 16px; 
    text-align: left;
    font-weight: 600;
    opacity: 0.9;
}

.setting-label { 
    display: block; 
    color: var(--text-muted); 
    margin-bottom: 8px; 
    font-size: 0.85rem; 
    font-weight: 500;
}

/* --- SCROLLBAR STYLING --- */
.modal-card::-webkit-scrollbar { width: 4px; }
.modal-card::-webkit-scrollbar-track { background: transparent; }
.modal-card::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, 0.2); border-radius: 10px; }
body.light-mode .modal-card::-webkit-scrollbar-thumb { background-color: rgba(0, 0, 0, 0.2); }

/* --- PRESET GRID --- */
.preset-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

.preset-card {
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: 0.2s;
}
.preset-card:hover { 
    /* Uses Action Color (Purple) */
    border-color: var(--color-action); 
    background: rgba(255,255,255,0.03); 
}
body.light-mode .preset-card:hover { background: rgba(0,0,0,0.03); }

.preset-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.preset-name { font-weight: 700; font-size: 1rem; }
.preset-times { 
    font-size: 0.8rem; 
    /* Uses Action Color (Purple) */
    color: var(--color-action); 
    font-weight: 600; 
    background: var(--input-bg); 
    padding: 2px 8px; border-radius: 4px; 
}
.preset-desc { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

/* --- INPUTS --- */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type=number] { -moz-appearance: textfield; }

.input-row { display: flex; gap: 14px; margin-bottom: 20px; }

.input-wrapper { 
    flex: 1 1 0px; 
    min-width: 0; 
    display:flex; 
    flex-direction:column; 
}

.qty-selector {
    display: flex; align-items: center;
    background: var(--input-bg);
    border-radius: 14px;
    border: 1px solid var(--glass-border);
    padding: 4px; 
    height: 44px; 
    width: 100%;
}

.qty-btn {
    width: 36px;
    height: 100%;
    border-radius: 10px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 1.2rem;
    display: flex; align-items: center; justify-content: center;
    user-select: none;
    flex-shrink: 0;
}
.qty-btn:hover { color: var(--text-main); background: rgba(128,128,128,0.1); }

.setting-input {
    flex: 1; 
    min-width: 0;
    background: transparent; border: none;
    color: var(--text-main); text-align: center; font-size: 1.05rem; font-weight: 600; outline: none;
}

/* --- SELECTS --- */
.select-wrapper {
    position: relative; width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 14px; 
    height: 44px; 
    display: flex; align-items: center; padding: 0 12px;
}
.custom-select {
    background: transparent; width: 100%; height: 100%; border: none;
    color: var(--text-main); font-size: 1rem; font-weight: 500; outline: none; appearance: none;
    font-family: var(--font-family);
    cursor: pointer;
}
.select-wrapper::after {
    content: ''; position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    width: 10px; height: 6px; background-color: var(--arrow-color);
    clip-path: polygon(100% 0%, 0 0%, 50% 100%); pointer-events: none;
}
.custom-select option { background: var(--modal-bg); color: var(--text-main); }

/* --- TOGGLES --- */
.toggle-row { 
    display: flex; justify-content: space-between; 
    margin-bottom: 12px;
    padding: 4px 0;
    align-items: center; 
}
.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--input-bg); border-radius: 34px; transition: .4s; border: 1px solid var(--glass-border); }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .4s; }

/* UPDATED: Active toggles now use Action Purple */
input:checked + .slider { background-color: var(--color-action); border-color: var(--color-action); }
input:checked + .slider:before { transform: translateX(18px); }

/* --- TOAST --- */
.toast {
    position: fixed; top: 30px; left: 50%;
    transform: translateX(-50%) translateY(-20px);
    
    /* Uses Yellow for distinct notification with Dark Text */
    background: var(--color-notification); 
    box-shadow: 0 8px 30px var(--notification-glow);
    color: #1d1d1f; 
    
    font-weight: 600;
    padding: 10px 24px; border-radius: 30px; font-size: 0.9rem;
    opacity: 0; pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- CONFIRMATION MODAL SPECIFICS --- */
#resetConfirmModal {
    z-index: 2000; /* Ensure it sits ON TOP of the Settings Modal */
}

.confirm-modal-card {
    max-width: 340px;
    text-align: center;
    padding-top: 32px;
    padding-bottom: 24px;
}

.confirm-msg {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 24px;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Style the Confirm Reset button to match the Action Purple theme */
#confirmResetBtn {
    background: var(--color-action);
    box-shadow: 0 4px 20px var(--action-glow);
}
#confirmResetBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px var(--action-glow);
}

/* --- MOBILE TWEAKS --- */
@media (max-height: 600px) {
    .app-footer { display: none; }
    .app-header { margin-top: 10px; }
    main { padding-top: 2vh; gap: 2vh; }
    .ring-container { width: min(80vw, 300px); height: min(80vw, 300px); }
    .time-display { font-size: 3.5rem; }
}
@media (max-width: 400px) {
    .btn { padding: 10px 20px; font-size: 0.9rem; }
    .time-display { font-size: 16vw; } 
    .mode-btn { padding: 6px 12px; font-size: 0.8rem; }
    .preset-header { flex-direction: column; align-items: flex-start; gap: 4px; }
}