@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;700&display=swap');

/* ---------- Theme tokens ---------- */
:root {
    --bg: #121212;
    --bg-elevated: #1c1c1e;
    --text: #f4f4f5;
    --text-dim: #9a9a9a;
    --accent: #03DAC6;
    --accent-2: #CF6679;
    --border: #2a2a2c;
    --track: #2a2a2c;
    --danger: #CF6679;

    /* The "Fancy Digital Clock" chip keeps its own fixed look in both themes,
       like a physical device display rather than themed page chrome. */
    --odo-bg: #1e1e1e;
    --odo-gradient: linear-gradient(to bottom right, #0263e1, #eb1836);
    --odo-digit: #ffffff;
}

html[data-theme="light"] {
    --bg: #f5f6f8;
    --bg-elevated: #ffffff;
    --text: #16181d;
    --text-dim: #6b7280;
    --accent: #0f9d8f;
    --accent-2: #c2185b;
    --border: #e2e4e9;
    --track: #e2e4e9;
    --danger: #c2185b;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Rubik', Arial, sans-serif;
    transition: background-color 200ms ease, color 200ms ease;
}

button, input {
    font-family: inherit;
}

/* ---------- Layout ---------- */
#app {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

#setup {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.app-title {
    font-size: 2em;
    margin: 0 0 6px;
    text-align: center;
    color: var(--accent);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    font-size: 0.85em;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#setup input[type="text"],
#setup input[type="number"] {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 12px 14px;
    font-size: 1em;
    outline: none;
}

#setup input[type="text"]:focus,
#setup input[type="number"]:focus {
    border-color: var(--accent);
}

/* ---------- Segmented control ---------- */
.segmented {
    display: flex;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    flex-wrap: wrap;
}

.segmented-option {
    flex: 1 1 auto;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-dim);
    padding: 10px 12px;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
    white-space: nowrap;
}

.segmented-option:hover {
    color: var(--text);
}

.segmented-option.active {
    background: var(--accent);
    color: #0b0b0c;
    font-weight: 500;
}

/* ---------- Checkboxes ---------- */
.checkbox-field {
    flex-direction: row;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.95em;
}

.checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ---------- Buttons ---------- */
.primary-btn {
    background: var(--accent);
    color: #0b0b0c;
    border: none;
    border-radius: 10px;
    padding: 14px 20px;
    font-size: 1.05em;
    font-weight: 500;
    cursor: pointer;
    margin-top: 6px;
    transition: transform 100ms ease, opacity 150ms ease;
}

.primary-btn:hover { opacity: 0.9; }
.primary-btn:active { transform: scale(0.98); }

.ghost-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85em;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease;
}

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

.icon-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.corner-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20;
}

/* ---------- Display screen ---------- */
#display {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
}

#displayTitle {
    font-size: clamp(1.6em, 5vw, 3em);
    text-align: center;
    color: var(--accent);
    margin: 0;
    max-width: 90vw;
}

#visualStage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

#controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.overtime #displayTitle,
.overtime .stage-label,
.overtime .timer-plain {
    color: var(--accent-2) !important;
}

/* ---------- Plain digits visual ---------- */
.timer-plain {
    font-size: clamp(2.5em, 10vw, 6em);
    font-weight: 500;
    color: var(--accent-2);
    letter-spacing: 0.02em;
}

/* ---------- Pie visual ---------- */
.pie-wrap {
    width: clamp(180px, 40vw, 360px);
    aspect-ratio: 1;
}

.pie {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: conic-gradient(var(--accent) calc(var(--pct, 100) * 1%), var(--track) 0);
    transform: rotate(-90deg);
    transition: background 200ms linear;
}

/* ---------- Shared visual label (pie / ring) ---------- */
.stage-label {
    font-size: clamp(1.3em, 4vw, 2.4em);
    font-weight: 500;
    color: var(--text);
}

/* ---------- Ring visual ---------- */
.ring-wrap {
    position: relative;
    width: clamp(180px, 40vw, 360px);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-track {
    fill: none;
    stroke: var(--track);
    stroke-width: 10;
}

.ring-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dashoffset 200ms linear, stroke 200ms ease;
}

.ring-label-wrap {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ring-sublabel {
    font-size: 0.85em;
    color: var(--text-dim);
}

/* ---------- Odometer visual ("Fancy Digital Clock") ---------- */
.odo-chip {
    background: var(--odo-gradient);
    border-radius: 22px;
    display: inline-flex;
    padding: 4px;
}

.odo-inner {
    align-items: center;
    background-color: var(--odo-bg);
    border-radius: 18px;
    display: flex;
    overflow: hidden;
    margin: 0;
    padding: 0 20px;
}

.odo-char {
    height: var(--odo-char-h, 150px);
    width: var(--odo-char-w, 80px);
    position: relative;
    text-align: center;
}

.odo-char.colon {
    color: var(--odo-digit);
    font-size: var(--odo-font-active, 8em);
    line-height: var(--odo-char-h, 150px);
    width: auto;
    padding: 0 4px;
}

.odo-slider {
    display: flex;
    flex-direction: column;
    left: 0;
    position: absolute;
    top: 0;
    transition: top 200ms;
    width: var(--odo-char-w, 80px);
}

.odo-option {
    color: var(--odo-digit);
    font-size: var(--odo-font-inactive, 4em);
    height: var(--odo-char-h, 150px);
    line-height: var(--odo-char-h, 150px);
    opacity: 0.05;
    transition: opacity 300ms, font-size 300ms;
}

.odo-option.active {
    font-size: var(--odo-font-active, 8em);
    opacity: 1;
}

:root {
    --odo-char-h: clamp(40px, 11vw, 150px);
    --odo-char-w: clamp(20px, 5.6vw, 80px);
    --odo-font-active: clamp(20px, 6.4vw, 128px);
    --odo-font-inactive: clamp(10px, 3.2vw, 64px);
}

/* ---------- Full display mode ---------- */
body.is-full-display #app {
    padding: 20px;
}

body.is-full-display #themeToggle,
body.is-full-display #controls {
    display: none;
}

body.is-full-display #displayTitle {
    font-size: clamp(2em, 6vw, 4em);
}

body.is-full-display .timer-plain {
    font-size: clamp(3.5em, 14vw, 9em);
}

body.is-full-display .pie-wrap,
body.is-full-display .ring-wrap {
    width: clamp(240px, 55vw, 560px);
}

body.is-full-display {
    --odo-char-h: clamp(56px, 16vw, 220px);
    --odo-char-w: clamp(28px, 8vw, 116px);
    --odo-font-active: clamp(28px, 9vw, 190px);
    --odo-font-inactive: clamp(14px, 4.5vw, 95px);
}

.exit-full-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 30;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85em;
    cursor: pointer;
    opacity: 0.35;
    transition: opacity 150ms ease;
}

.exit-full-btn:hover {
    opacity: 1;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
    #app { padding: 24px 14px; }
    #controls { flex-direction: column; width: 100%; }
    #controls .ghost-btn { width: 100%; }
}
