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

:root {
    --amber: #ffaa00;
    --amber-dim: #7a4e00;
    --bg: #0d0d0d;
    --red: #ff3b30;
    --green: #34c759;
    --border: #1e1e1e;
    --clock-color: #e8e8e8;
}

html, body {
    width: 100%; 
    height: 100%; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height prevents URL bar overlap */
    background: var(--bg);
    color: var(--amber);
    font-family: ui-sans-serif, system-ui, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body {
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* Scanlines */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.07) 2px, rgba(0,0,0,0.07) 4px
    );
    pointer-events: none;
    z-index: 100;
}

/* ── Wall clock ── */
#wall-clock-wrap {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: clamp(8px, 1.5vh, 20px);
    padding-bottom: clamp(8px, 1.5vh, 20px);
    transition: opacity 0.4s ease;
}

/* Desktop/Tablet: pad sides to sit between floating buttons */
@media (min-width: 600px) {
    #wall-clock-wrap {
    padding-left: clamp(110px, 15vw, 180px);
    padding-right: clamp(110px, 15vw, 180px);
    }
}

/* Phones in portrait: push down to clear floating buttons, use full width */
@media (max-width: 599px) {
    #wall-clock-wrap {
    padding-top: calc(env(safe-area-inset-top) + 60px);
    padding-left: 10px;
    padding-right: 10px;
    }
    .float-btn {
    font-size: 11px;
    padding: 0.6em 0.9em;
    }
}

#wall-clock {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-weight: 700;
    font-size: clamp(40px, min(10vw, 10vh), 160px);
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--clock-color);
    white-space: nowrap;
}

#wall-clock-label {
    font-size: clamp(10px, 1.4vw, 14px);
    font-weight: 300;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: rgba(232, 232, 232, 0.35);
    margin-top: 0.4em;
}

/* ── Content area ── */
#content {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ── Panels ── */
.panel {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.panel.active { display: flex; }

/* ── Shared timer display ── */
.big-display {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-weight: 700;
    /* BOUNDED SCALING: Stops Galaxy Tab from overflowing vertically */
    font-size: clamp(60px, min(22vw, 28vh), 250px);
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--amber);
    transition: color 0.15s;
    padding: 0.08em 0;
}

.big-display.paused { color: var(--amber-dim); }
.big-display.urgent { color: var(--red); }

/* ── Status label ── */
.status-label {
    font-size: clamp(13px, 2vw, 18px);
    font-weight: 300;
    letter-spacing: 0.35em;
    color: var(--amber-dim);
    height: 2.2em;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.status-label.running { color: var(--green); }
.status-label.paused  { color: var(--amber); }
.status-label.done    { color: var(--red); }

/* ── Last split ── */
#sw-split {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: clamp(16px, 2.5vw, 28px);
    color: #2a2a2a;
    letter-spacing: 0.05em;
    height: 1.6em;
    display: flex;
    align-items: center;
    transition: color 0.3s;
}

#sw-split.has-split { color: var(--amber-dim); }

/* ── Controls ── */
.controls {
    display: flex;
    gap: clamp(12px, 3vw, 48px);
    margin-top: clamp(16px, 2.5vh, 36px);
}

.btn {
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-weight: 600;
    font-size: clamp(18px, min(3vw, 3vh), 32px);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    border: 2px solid currentColor;
    background: transparent;
    color: var(--amber-dim);
    padding: 0.75em 2.5em;
    cursor: pointer;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    border-radius: 3px;
    min-width: clamp(140px, 20vw, 300px);
    touch-action: manipulation;
}

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

/* Dimmed Solid Outlines (Removed Box Shadows) */
.btn-primary { 
    color: var(--amber); 
    border-color: rgba(255, 170, 0, 0.3); 
}
.btn-primary:active { 
    background: var(--amber); 
    color: var(--bg); 
    box-shadow: 0 0 30px rgba(255,170,0,0.6); /* Keep glow on active tap */
}

/* Dimmed Reset/Bin Button */
.btn-danger { 
    color: #444; 
    border-color: rgba(68, 68, 68, 0.4); 
    opacity: 0.5; /* Dims the icon and border by 50% */
    transition: opacity 0.2s, color 0.1s;
}
.btn-danger.active { 
    color: var(--red); 
    border-color: rgba(255, 59, 48, 0.4); 
    opacity: 1; /* Restores to full brightness if it enters an active/warning state */
}
.btn-danger:active { 
    background: var(--red); 
    color: var(--bg); 
    opacity: 1;
}

/* ── Timer (stopwatch) control layout ── */
#sw-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    padding: 0 clamp(10px, 6vw, 110px);
    gap: clamp(10px, 2vw, 24px);
}

#sw-controls #sw-reset-all { justify-self: start; }
#sw-controls #sw-startstop { justify-self: center; }
#sw-controls #sw-skip      { justify-self: end; }

.btn svg { width: 100%; height: 100%; fill: currentColor; display: block; }

.btn-pill {
    /* Height remains exactly the same as before */
    height: clamp(68px, min(18vw, 15vh), 160px);
    /* Width is dynamically calculated to be exactly 1.5x (50% wider) than the height */
    width: calc(clamp(68px, min(18vw, 15vh), 160px) * 1.5); 
    min-width: 0;
    padding: 0;
    border-radius: 999px; /* Forces the perfect pill shape */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Adjusts the icon proportions to fit the wider pill shape properly */
.btn-pill svg { width: 30%; height: 45%; }

.btn-skip { 
    color: var(--amber); 
    border-color: rgba(255, 170, 0, 0.3); 
}
.btn-skip:active { 
    background: var(--amber); 
    color: var(--bg); 
    box-shadow: 0 0 30px rgba(255,170,0,0.6); 
}

.is-hidden { visibility: hidden; pointer-events: none; }

/* ── Countdown setter ── */
#cd-setter {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    justify-items: center;
    gap: 0.15em clamp(8px, 2vw, 24px);
}

.cd-val {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-weight: 700;
    font-size: clamp(56px, min(18vw, 22vh), 150px);
    line-height: 1;
    color: var(--amber);
    width: 2.2ch;
    text-align: center;
}

.cd-adj {
    background: transparent;
    border: 1px solid var(--amber-dim);
    color: var(--amber);
    font-size: clamp(16px, 2.5vw, 28px);
    width: clamp(64px, min(10vw, 8vh), 120px);
    height: clamp(36px, min(6vh, 8vw), 56px);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.cd-adj:active { background: var(--amber); color: var(--bg); border-color: var(--amber); }

.cd-label {
    font-size: clamp(10px, 1.5vw, 14px);
    letter-spacing: 0.25em;
    color: #444;
    text-transform: uppercase;
    margin-top: 0.2em;
}

.cd-colon {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-weight: 700;
    font-size: clamp(56px, min(18vw, 22vh), 150px);
    color: var(--amber-dim);
    line-height: 1;
}

/* ── Floating top buttons ── */
.float-btn {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 0.5em;
    background: rgba(13,13,13,0.7);
    border: 1px solid var(--amber-dim);
    color: var(--amber-dim);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: clamp(12px, 1.6vw, 15px);
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 0.8em 1.1em;
    border-radius: 999px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    touch-action: manipulation;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.float-btn:active { color: var(--amber); border-color: var(--amber); }

.mode-icon { width: 1.3em; height: 1.3em; flex-shrink: 0; }
.icon-countdown { display: none; }
#mode-toggle.mode-countdown .icon-stopwatch { display: none; }
#mode-toggle.mode-countdown .icon-countdown { display: block; }

#mode-toggle { left: max(12px, env(safe-area-inset-left)); }

#update-toast {
    position: fixed;
    top: clamp(62px, 11vh, 88px);
    font-family: ui-sans-serif, system-ui, sans-serif;
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.3s;
}

#update-toast {
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    max-width: min(340px, 85vw);
    background: rgba(26,26,26,0.96);
    border: 1px solid var(--green);
    color: var(--green);
    font-size: clamp(12px, 1.6vw, 14px);
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0.03em;
    padding: 0.85em 1.25em;
    border-radius: 99px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 15px rgba(46,204,113,0.15);
    cursor: pointer;
    z-index: 300;
}
#update-toast.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

#wake-toast {
    position: fixed;
    bottom: clamp(40px, 8vh, 60px);
    left: max(16px, env(safe-area-inset-left));
    background: rgba(13,13,13,0.94);
    border: 1px solid var(--amber-dim);
    color: var(--amber);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: clamp(11px, 1.5vw, 13px);
    letter-spacing: 0.05em;
    padding: 0.75em 0.95em;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.3s;
    z-index: 250;
    transform: translateY(10px);
}
#wake-toast.show { 
    opacity: 1; 
    transform: translateY(0); 
}

/* ── Bottom-left corner readouts ── */
#corner-stack {
    position: fixed;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
    z-index: 200;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    pointer-events: none;
}
.corner {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #2e2e2e;
    font-family: ui-monospace, monospace;
}
#wake-indicator.locked { color: #1a3a1a; }

/* ── Tablet & Desktop Landscape Scale Up ── */
@media (min-width: 768px) and (orientation: landscape) {
    #wall-clock {
    /* Increased base size and pushed vh limit higher */
    font-size: clamp(100px, min(18vw, 18vh), 240px);
    }
    
    .btn-pill {
    height: clamp(100px, min(18vw, 20vh), 180px);
    width: calc(clamp(100px, min(18vw, 20vh), 180px) * 1.5);
    }

    #sw-controls {
    gap: clamp(24px, 4vw, 50px);
    }
}

/* ── Extreme Landscape (e.g., iPhone horizontally) ── */
/* Placed strictly at the end to guarantee override priority */
@media (max-height: 430px) {
    #wall-clock-wrap { padding-top: 4px; padding-bottom: 4px; padding-left: 0; padding-right: 0; margin-top: 0; }
    #wall-clock { font-size: clamp(24px, 7vh, 56px); }
    #wall-clock-label { display: none; }
    
    .big-display { font-size: clamp(40px, 28vh, 120px); }
    .status-label { height: 1.6em; font-size: clamp(11px, 2.5vh, 15px); }
    #sw-split { height: 1.2em; font-size: clamp(12px, 3vh, 20px); }
    
    #sw-controls { padding: 0 clamp(16px, 6vw, 60px); }
    .btn-pill { 
    height: clamp(56px, 16vh, 84px); 
    width: calc(clamp(56px, 16vh, 84px) * 1.5); 
    }
    
    .float-btn { font-size: 11px; padding: 0.55em 0.85em; top: 6px; }
    #voice-toggle { padding: 0.55em; }
    #corner-stack { bottom: 6px; }
    
    .cd-val, .cd-colon { font-size: clamp(32px, 22vh, 80px); }
    .cd-adj { height: clamp(28px, 4vh, 40px); font-size: clamp(14px, 2vh, 20px); }
}