/* ===============================
   CalmClock — Distraction-Free UI
   =============================== */

:root {
    --bg: #0f1115;
    --panel: #151824;
    --panel-2: #1b2030;
    --text: #e9edf1;
    --muted: #a7b0bf;
    --primary: #6aa6ff;
    --primary-600: #4f90ff;
    --accent: #7ce2ce;
    --danger: #ff6b6b;
    --ring: #2a3550;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --radius: 16px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f8fb;
        --panel: #ffffff;
        --panel-2: #f1f4f9;
        --text: #12141a;
        --muted: #4b5565;
        --primary: #2f6bff;
        --primary-600: #2558d6;
        --accent: #00b8a9;
        --danger: #e23d3d;
        --ring: #d9e2ff;
        --shadow: 0 6px 24px rgba(16, 24, 40, .12);
    }
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
    color: var(--text);
    background: radial-gradient(1200px 600px at 20% -10%, rgba(122, 164, 255, .06), transparent 60%),
        radial-gradient(1000px 700px at 120% 10%, rgba(124, 226, 206, .07), transparent 60%),
        var(--bg);
}

/* Accessibility helpers */
.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

.muted {
    color: var(--muted);
}

/* --- Layout --- */
.app-header,
.app-footer {
    max-width: 980px;
    margin: 0 auto;
    padding: 16px 20px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    margin: 0;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.container {
    max-width: 980px;
    margin: 10px auto 40px;
    padding: 0 20px;
    display: grid;
    gap: 20px;
}

.timer-card,
.stats,
.log {
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

/* --- Header buttons --- */
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    transition: transform .1s ease, border-color .2s ease, background .2s ease;
}

.icon-btn:hover {
    transform: translateY(-1px);
    border-color: var(--ring);
}

.icon-btn:focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: 2px;
}

/* --- Timer section --- */
.session-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.select-label {
    font-size: 14px;
    color: var(--muted);
}

select {
    appearance: none;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, .08);
    padding: 8px 12px;
    border-radius: 12px;
    outline: none;
}

select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 144, 255, .15);
}

.timer-display {
    font-variant-numeric: tabular-nums;
    font-size: clamp(48px, 10vw, 96px);
    font-weight: 800;
    text-align: center;
    padding: 22px 10px;
    margin: 8px 0 16px;
    letter-spacing: 1px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .08), transparent);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .06);
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
}

/* Buttons */
button {
    font: inherit;
    color: var(--text);
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--panel-2);
    cursor: pointer;
    transition: transform .06s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease, opacity .2s;
    user-select: none;
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.primary {
    background: linear-gradient(180deg, var(--primary), var(--primary-600));
    border: none;
    color: white;
    box-shadow: 0 8px 18px rgba(79, 144, 255, .35);
}

.primary:hover {
    filter: brightness(1.03);
}

.primary:focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: 3px;
}

.secondary {
    background: var(--panel-2);
    border: 1px solid rgba(255, 255, 255, .08);
}

.secondary:hover {
    border-color: var(--ring);
}

.ghost {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .12);
}

.ghost:hover {
    border-color: var(--ring);
}

.danger {
    color: white;
    background: linear-gradient(180deg, var(--danger), #c63c3c);
    border: none;
    box-shadow: 0 8px 18px rgba(230, 80, 80, .35);
}

.quick-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 6px;
}

.chip {
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(124, 226, 206, .15);
    border: 1px solid rgba(124, 226, 206, .35);
    color: var(--text);
    font-weight: 600;
}

.chip:hover {
    background: rgba(124, 226, 206, .22);
}

/* --- Stats --- */
.stats h2 {
    margin: 4px 0 14px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.stat-item {
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 14px;
    padding: 14px;
    min-height: 86px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    margin-top: 4px;
}

/* --- Log --- */
.log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.log-actions {
    display: flex;
    gap: 8px;
}

.log-list {
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    overflow: clip;
}

.log-head {
    display: grid;
    grid-template-columns: 1.1fr .8fr .6fr 1.5fr;
    gap: 8px;
    padding: 10px 12px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.log-body {
    display: block;
    max-height: 320px;
    overflow: auto;
}

.log-row {
    display: grid;
    grid-template-columns: 1.1fr .8fr .6fr 1.5fr;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.log-row:last-child {
    border-bottom: none;
}

.log-row span,
.log-row div {
    align-self: center;
}

/* Note form */
.note-form {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.note-form input {
    flex: 1;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: var(--panel);
    color: var(--text);
    outline: none;
}

.note-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 144, 255, .15);
}

/* --- Dialog (Settings) --- */
dialog {
    width: min(560px, 92vw);
    border: none;
    padding: 0;
    border-radius: 18px;
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    color: var(--text);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(2px);
}

.settings-form {
    padding: 14px;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 6px 6px 10px;
}

.dialog-header h2 {
    margin: 6px 0;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 8px 6px 6px;
}

.settings-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 12px;
    padding: 10px;
}

.settings-grid input[type="number"] {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: var(--panel-2);
    color: var(--text);
    outline: none;
}

.settings-grid input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 144, 255, .15);
}

.settings-grid .row {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    padding: 0;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 6px 12px;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    color: var(--muted);
}

/* --- Focus styles --- */
:focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: 2px;
    border-radius: 12px;
}

/* --- Scrollbars (WebKit/Chromium) --- */
.log-body::-webkit-scrollbar {
    height: 12px;
    width: 12px;
}

.log-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .15);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.log-body::-webkit-scrollbar-track {
    background: transparent;
}

/* --- Responsive --- */
@media (max-width: 760px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .log-head,
    .log-row {
        grid-template-columns: 1fr .7fr .6fr 1fr;
    }

    .session-meta {
        flex-wrap: wrap;
    }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}