:root {
    /* --- Material You Inspired Theme --- */
    --m3-primary-hue: 210;

    /* Core Colors (derived from hue) */
    --m3-primary: hsl(var(--m3-primary-hue), 85%, 60%);
    --m3-on-primary: hsl(var(--m3-primary-hue), 70%, 10%);

    --m3-primary-container: hsl(var(--m3-primary-hue), 70%, 25%);
    --m3-on-primary-container: hsl(var(--m3-primary-hue), 75%, 88%);

    --m3-secondary: hsl(var(--m3-primary-hue), 20%, 65%);
    --m3-on-secondary: hsl(var(--m3-primary-hue), 30%, 10%);

    --m3-secondary-container: hsl(var(--m3-primary-hue), 25%, 25%);
    --m3-on-secondary-container: hsl(var(--m3-primary-hue), 20%, 88%);

    --m3-tertiary: hsl(calc(var(--m3-primary-hue) + 60), 50%, 60%);
    --m3-on-tertiary: hsl(calc(var(--m3-primary-hue) + 60), 50%, 10%);

    --m3-tertiary-container: hsl(calc(var(--m3-primary-hue) + 60), 40%, 25%);
    --m3-on-tertiary-container: hsl(calc(var(--m3-primary-hue) + 60), 40%, 88%);

    /* Error Colors (for reset button) */
    --m3-error-hue: 0;
    /* Red */
    --m3-error: hsl(var(--m3-error-hue), 80%, 55%);
    --m3-on-error: hsl(var(--m3-error-hue), 70%, 95%);
    --m3-error-container: hsl(var(--m3-error-hue), 70%, 20%);
    --m3-on-error-container: hsl(var(--m3-error-hue), 70%, 88%);


    /* Surface Colors (backgrounds for dark theme) */
    --m3-surface-dim: hsl(var(--m3-primary-hue), 10%, 6%);
    --m3-surface: hsl(var(--m3-primary-hue), 10%, 10%);
    --m3-surface-bright: hsl(var(--m3-primary-hue), 8%, 15%);

    --m3-surface-container-lowest: hsl(var(--m3-primary-hue), 12%, 4%);
    --m3-surface-container-low: hsl(var(--m3-primary-hue), 12%, 8%);
    --m3-surface-container: hsl(var(--m3-primary-hue), 12%, 12%);
    --m3-surface-container-high: hsl(var(--m3-primary-hue), 10%, 17%);
    --m3-surface-container-highest: hsl(var(--m3-primary-hue), 10%, 22%);

    /* Text/Icon Colors on Surfaces */
    --m3-on-surface: hsl(var(--m3-primary-hue), 10%, 90%);
    --m3-on-surface-variant: hsl(var(--m3-primary-hue), 10%, 70%);

    /* Outlines and Separators */
    --m3-outline: hsl(var(--m3-primary-hue), 15%, 50%);
    --m3-outline-variant: hsl(var(--m3-primary-hue), 10%, 35%);

    /* State Layers (for hover, focus, pressed) */
    --m3-state-hover-opacity: 0.08;
    --m3-state-focus-opacity: 0.12;
    --m3-state-pressed-opacity: 0.12;
    --m3-state-dragged-opacity: 0.16;

    /* --- Font Settings --- */
    --clock-font-family: 'Roboto Mono', monospace;
    --ui-font-family: 'Noto Sans', sans-serif;
    --clock-font-size: 15vw;

    /* --- Corner Radius --- */
    --m3-corner-none: 0px;
    --m3-corner-xs: 4px;
    --m3-corner-s: 8px;
    --m3-corner-m: 12px;
    --m3-corner-l: 16px;
    --m3-corner-xl: 28px;
    --m3-corner-full: 999px;

    /* --- Shadows (Subtle) --- */
    --m3-shadow-1: 0 1px 2px 0 hsla(0, 0%, 0%, .3), 0 1px 3px 1px hsla(0, 0%, 0%, .15);
    --m3-shadow-2: 0 1px 2px 0 hsla(0, 0%, 0%, .3), 0 2px 6px 2px hsla(0, 0%, 0%, .15);
    --m3-shadow-3: 0 4px 8px 3px hsla(0, 0%, 0%, .3), 0 1px 3px hsla(0, 0%, 0%, .15);

    /* New variable for progress bar */
    --m3-progress-bar-color: hsl(var(--m3-primary-hue), 15%, 15%);
    /* Slightly more saturated than surface */

    --bg-color: var(--m3-surface);
    /* Keep for potential JS fallback if needed, though M3 vars are primary */
    --text-color: var(--m3-on-surface);
    /* Keep for potential JS fallback */
}

body {
    margin: 0;
    font-family: var(--ui-font-family);
    background-color: var(--m3-surface);
    color: var(--m3-on-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
    position: relative;
    /* For progress bar positioning */

    -webkit-user-select: none;
    /* Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* Internet Explorer/Edge */
    user-select: none;
    /* Standard */
    -webkit-tap-highlight-color: transparent;
}

/* Timer Progress Bar */
#timer-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    /* Starts at 0 width */
    background-color: var(--m3-progress-bar-color);
    z-index: -1;
    /* Behind everything else */
    transition: width 0.5s linear;
    /* Smooth width transition for updates */
    opacity: 0;
    /* Hidden by default */
}

body.timer-active #timer-progress-bar {
    /* Show only when timer is active */
    opacity: 1;
}


.app-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    /* Ensure app content is above progress bar */
    z-index: 1;
}

#main-display {
    font-family: var(--clock-font-family);
    font-size: var(--clock-font-size);
    font-weight: 400;
    /* Base weight */
    line-height: 1;
    white-space: nowrap;
    transition: font-size 0.3s, font-family 0.3s;
    min-height: calc(var(--clock-font-size) * 1.15);
    display: flex;
    align-items: center;
    /* Vertically center content */
    justify-content: center;
    width: auto;
    min-width: 70vw;
    max-width: 95vw;
    position: relative;
    color: var(--m3-on-surface);
}

.clock-digits {
    display: inline-flex;
    align-items: baseline;
    visibility: visible;
    transition: visibility 0s;
}

#clock-hours, #clock-minutes, #clock-seconds {
    letter-spacing: -0.03em;
    font-weight: 400;
}


.clock-separator.main-sep {
    opacity: 0.7;
    margin: 0 0.01em;
    padding: 0 0.01em;
    transform: scaleY(0.9) translateY(-0.02em);
    font-weight: 400;
    letter-spacing: -0.03em;
}


#clock-ampm {
    font-size: 0.25em;
    margin-left: 0.2em;
    vertical-align: baseline;
    font-weight: 500;
    color: var(--m3-on-surface-variant);
    letter-spacing: normal;
}

#timer-input {
    font-family: inherit;
    font-size: inherit;
    font-weight: 400;
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--m3-on-surface);
    background-color: transparent;
    border: none;
    text-align: center;
    width: auto;
    /* Let content define width; it will mimic the clock-digits span */
    min-width: 1ch;
    outline: none;
    padding: 0;
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    caret-color: var(--m3-primary);
}


#timer-input::placeholder {
    color: var(--m3-on-surface-variant);
    font-size: 0.3em;
    opacity: 0.8;
    font-weight: 300;
    letter-spacing: normal;
}

#date-display-container {
    font-family: var(--ui-font-family);
    font-size: calc(var(--clock-font-size) * 0.10);
    margin-top: 20px;
    font-weight: 400;
    color: var(--m3-on-surface-variant);
}

#timer-controls-container {
    margin-top: 30px;
    display: flex;
    gap: 16px;
}

.control-btn, .m3-button-base {
    font-family: var(--ui-font-family);
    font-weight: 500;
    padding: 10px 24px;
    border-radius: var(--m3-corner-full);
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s, opacity 0.2s;
    text-transform: none;
    font-size: 0.9em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    outline: none;
    position: relative;
    overflow: hidden;
}

.control-btn::before, .m3-button-base::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: currentColor;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.control-btn:hover::before, .m3-button-base:hover::before {
    opacity: var(--m3-state-hover-opacity);
}

.control-btn:focus-visible::before, .m3-button-base:focus-visible::before {
    opacity: var(--m3-state-focus-opacity);
}

.control-btn:active, .m3-button-base:active {
    transform: scale(0.98);
}

.control-btn:active::before, .m3-button-base:active::before {
    opacity: var(--m3-state-pressed-opacity);
}

.m3-filled-button {
    background-color: var(--m3-primary);
    color: var(--m3-on-primary);
}

.m3-filled-button:hover {
    background-color: hsl(var(--m3-primary-hue), 85%, 65%);
}

.m3-tonal-button {
    background-color: var(--m3-secondary-container);
    color: var(--m3-on-secondary-container);
}

.m3-tonal-button:hover {
    background-color: hsl(var(--m3-primary-hue), 25%, 30%);
}

.m3-error-button {
    background-color: var(--m3-error-container);
    color: var(--m3-on-error-container);
    border-radius: var(--m3-corner-l);
}

.m3-error-button:hover {
    background-color: hsl(var(--m3-error-hue), 70%, 25%);
}

.m3-error-button:focus-visible::before {
    background-color: var(--m3-error);
}

.control-btn#timer-start-pause-btn.running {
    background-color: var(--m3-tertiary);
    color: var(--m3-on-tertiary);
}

.control-btn#timer-start-pause-btn.running:hover {
    background-color: hsl(calc(var(--m3-primary-hue) + 60), 50%, 65%);
}

.action-buttons-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
}

.action-buttons {
    display: flex;
    gap: 8px;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

.action-buttons.hidden {
    opacity: 0;
    pointer-events: none;
}

.m3-icon-button {
    background-color: var(--m3-surface-container-high);
    color: var(--m3-on-surface-variant);
    border: none;
    padding: 8px;
    border-radius: var(--m3-corner-full);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s, transform 0.1s;
    box-shadow: var(--m3-shadow-1);
    position: relative;
    overflow: hidden;
}

.m3-icon-button::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--m3-primary);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    border-radius: inherit;
}

.m3-icon-button:hover {
    color: var(--m3-primary);
}

.m3-icon-button:hover::before {
    opacity: var(--m3-state-hover-opacity);
}

.m3-icon-button:focus-visible::before {
    opacity: var(--m3-state-focus-opacity);
}

.m3-icon-button:active {
    transform: scale(0.95);
}

.m3-icon-button:active::before {
    opacity: var(--m3-state-pressed-opacity);
}

.action-buttons .material-icons-outlined {
    font-size: 24px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: hsla(var(--m3-primary-hue), 10%, 5%, 0.6);
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.show {
    display: flex;
}

.modal-content {
    font-family: var(--ui-font-family);
    background-color: var(--m3-surface-container);
    color: var(--m3-on-surface);
    margin: auto;
    padding: 24px;
    border-radius: var(--m3-corner-xl);
    width: 90%;
    max-width: 480px;
    box-shadow: var(--m3-shadow-3);
    position: relative;
}

.modal-content h2 {
    margin-top: 0;
    font-weight: 500;
    font-size: 1.4em;
    color: var(--m3-on-surface);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.modal-content .close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 4px;
}

.setting-group {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.setting-group label:first-child {
    flex-shrink: 0;
    font-size: 0.9em;
    color: var(--m3-on-surface-variant);
    margin-right: auto;
}

.m3-text-field, .m3-select {
    font-family: var(--ui-font-family);
    padding: 10px 14px;
    border-radius: var(--m3-corner-xs);
    border: 1px solid var(--m3-outline-variant);
    background-color: var(--m3-surface-container-highest);
    color: var(--m3-on-surface);
    min-width: 80px;
    font-size: 0.95em;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    line-height: 1.2;
    height: auto;
}

.m3-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' viewBox='0 -960 960 960' width='24' fill='%23${(props) => props.arrowColor || 'e0e0e0'}'%3E%3Cpath d='M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    width: 180px;
}

.m3-text-field:focus, .m3-select:focus {
    border-color: var(--m3-primary);
    box-shadow: 0 0 0 1px var(--m3-primary);
}

.m3-text-field[type="number"] {
    width: 80px;
}

.m3-color-picker {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 40px;
    height: 28px;
    background-color: transparent;
    border: 1px solid var(--m3-outline-variant);
    border-radius: var(--m3-corner-s);
    cursor: pointer;
    padding: 0;
}

.m3-color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
    border-radius: var(--m3-corner-s);
}

.m3-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: calc(var(--m3-corner-s) - 2px);
}

.m3-color-picker::-moz-color-swatch {
    border: none;
    border-radius: var(--m3-corner-s);
    padding: 2px;
}

.m3-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--m3-primary);
    flex-shrink: 0;
    border: 2px solid var(--m3-outline);
    border-radius: var(--m3-corner-xs);
    appearance: none;
    display: inline-grid;
    place-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

.m3-checkbox::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--m3-on-primary);
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.m3-checkbox:checked {
    background-color: var(--m3-primary);
    border-color: var(--m3-primary);
}

.m3-checkbox:checked::before {
    transform: scale(1.2);
}

.m3-checkbox:focus-visible {
    outline: 2px solid var(--m3-primary);
    outline-offset: 2px;
}

#reset-settings-btn {
    width: 100%;
    margin-top: 24px;
}

.m3-switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.m3-switch-label {
    font-size: 0.9em;
    color: var(--m3-on-surface-variant);
    cursor: default;
}

.m3-switch {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.m3-switch-track {
    cursor: pointer;
    width: 52px;
    height: 32px;
    background-color: var(--m3-surface-container-highest);
    border: 2px solid var(--m3-outline);
    display: inline-block;
    border-radius: var(--m3-corner-full);
    position: relative;
    transition: background-color 0.2s, border-color 0.2s;
}

.m3-switch-track::before {
    content: "";
    position: absolute;
    height: 24px;
    width: 24px;
    left: 2px;
    bottom: 2px;
    background-color: var(--m3-outline);
    border-radius: 50%;
    transition: transform 0.2s, background-color 0.2s, width 0.2s;
}

.m3-switch:checked+.m3-switch-track {
    background-color: var(--m3-primary);
    border-color: var(--m3-primary);
}

.m3-switch:checked+.m3-switch-track::before {
    background-color: var(--m3-on-primary);
    transform: translateX(20px);
}

.m3-switch:checked+.m3-switch-track::after {
    content: "\e5ca";
    font-family: 'Material Icons Outlined';
    font-size: 16px;
    color: var(--m3-primary);
    position: absolute;
    left: 7px;
    top: 50%;
    transform: translateY(-50%) translateX(20px);
    transition: transform 0.2s, color 0.2s;
    opacity: 1;
}

.m3-switch+.m3-switch-track::after {
    content: "";
    opacity: 0;
    transition: opacity 0.2s;
}

.m3-switch:focus-visible+.m3-switch-track {
    box-shadow: 0 0 0 2px var(--m3-surface), 0 0 0 4px var(--m3-primary);
}

.timer-finished-blink .clock-digits,
.timer-finished-blink #clock-ampm {
    animation: blink 0.8s step-start infinite;
}

@keyframes blink {
    50% {
        opacity: 0.2;
    }
}