@font-face {
    font-family: 'Plus Jakarta Sans';
    src: url('../fonts/plus-jakarta-sans-latin.woff2') format('woff2');
    font-weight: 200 800;
    font-display: swap;
}

/* Tokens: the Aymrine template (aymrine_design_language.md §3) with Athan's teal-green accent */
:root {
    --color-canvas: #F8F7F2;
    --color-surface: #FFFFFF;
    --color-surface-low: #EEEDE5;
    --color-surface-high: #E6E5DC;
    --color-text: #1B1F1C;
    --color-text-secondary: #555C57;
    --color-text-tertiary: #9BA19C;

    --color-accent: #17625A;
    --color-accent-hover: #0F4A43;
    --color-on-accent: #FFFFFF;
    --color-accent-container: #D3EAE5;
    --color-on-accent-container: #0B3B35;
    --color-accent-tint: #E4F1EE;
    --color-hover: rgba(23, 98, 90, 0.08);
    --color-focus: rgba(23, 98, 90, 0.15);
    --color-scrim: rgba(17, 21, 19, 0.32);
    --color-dock: rgba(255, 255, 255, 0.95);

    --color-danger: #B3261E;

    --shadow-1: 0 1px 2px rgba(27, 31, 28, 0.05), 0 4px 16px rgba(27, 31, 28, 0.05);
    --shadow-2: 0 8px 24px -4px rgba(23, 98, 90, 0.10), 0 2px 6px rgba(27, 31, 28, 0.05);
    --shadow-sheet: 0 -8px 36px rgba(27, 31, 28, 0.16);

    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-sheet: cubic-bezier(0.2, 0.8, 0.2, 1);
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
    --color-canvas: #111513;
    --color-surface: #1A1F1C;
    --color-surface-low: #232926;
    --color-surface-high: #2C332F;
    --color-text: #E6E9E4;
    --color-text-secondary: #A5ADA7;
    --color-text-tertiary: #6B776E;

    --color-accent: #84D2C5;
    --color-accent-hover: #A9E2D8;
    --color-on-accent: #08302A;
    --color-accent-container: #1B4540;
    --color-on-accent-container: #C9ECE4;
    --color-accent-tint: #183A35;
    --color-hover: rgba(132, 210, 197, 0.12);
    --color-focus: rgba(132, 210, 197, 0.25);
    --color-scrim: rgba(0, 0, 0, 0.5);
    --color-dock: rgba(26, 31, 28, 0.94);

    --color-danger: #F2B8B5;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 8px 24px -4px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.75);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    overflow-x: clip;
    background: var(--color-canvas);
    color: var(--color-text);
    font: 400 15px/24px var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--color-accent); }
a:hover { color: var(--color-accent-hover); }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.hidden, [hidden] { display: none !important; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}
svg.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.icon.sm { width: 18px; height: 18px; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */

.view {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 112px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: fadeIn 0.4s ease-out;
}

#settings-view { padding-bottom: calc(env(safe-area-inset-bottom) + 40px); gap: 24px; }

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 44px;
}
.app-header .actions { display: flex; gap: 8px; }
.app-header.start { justify-content: flex-start; gap: 12px; }
button.row:disabled { opacity: 0.5; cursor: default; }
button.row:disabled:hover { background: transparent; }
.stepper button:disabled { opacity: 0.4; cursor: default; }

.screen-title { margin: 0; font-size: 23px; line-height: 1.2; font-weight: 800; letter-spacing: -0.4px; }

/* ---------- Buttons ---------- */

.icon-btn {
    width: 44px; height: 44px; flex: none;
    border: 0; border-radius: 50%;
    background: var(--color-surface-low);
    color: var(--color-text);
    display: inline-flex; align-items: center; justify-content: center;
    text-decoration: none;
    transition: background 0.15s, transform 0.2s var(--ease);
}
.icon-btn:hover { background: var(--color-surface-high); color: var(--color-text); }
.icon-btn.ghost { background: transparent; color: var(--color-text-secondary); }
.icon-btn.ghost:hover { background: var(--color-hover); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.btn {
    height: 48px;
    padding: 0 22px;
    border: 0; border-radius: 9999px;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-size: 15px; font-weight: 700; letter-spacing: 0.01em;
    text-decoration: none;
    background: var(--color-surface-low);
    color: var(--color-text);
    transition: background 0.15s, transform 0.2s var(--ease);
}
.btn:hover { background: var(--color-surface-high); color: var(--color-text); }
.btn.primary { background: var(--color-accent); color: var(--color-on-accent); }
.btn.primary:hover { background: var(--color-accent-hover); color: var(--color-on-accent); }
.btn.small { height: 44px; padding: 0 18px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:active, .icon-btn:active, .chip:active, .day-cell:active { transform: scale(0.97); }

.place-btn { padding: 0 16px 0 12px; max-width: 70%; }
.place-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-btn .pin { color: var(--color-accent); }
.place-btn .chev { color: var(--color-text-secondary); }

/* Segmented control (role="radiogroup") */
.seg {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 4px;
    padding: 4px;
    border-radius: 9999px;
    background: var(--color-surface-low);
}
.seg button {
    height: 40px;
    border: 0; border-radius: 9999px;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 14px; font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s var(--ease), color 0.2s;
}
.seg button:hover { color: var(--color-text); }
.seg button[aria-checked="true"], .seg button[aria-selected="true"] {
    background: var(--color-accent); color: var(--color-on-accent); font-weight: 700;
}

.chip {
    height: 44px;
    padding: 0 16px;
    border: 0; border-radius: 9999px;
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--color-surface-low);
    color: var(--color-text-secondary);
    font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--color-accent-container); color: var(--color-on-accent-container); font-weight: 700; }
.chip .icon { width: 16px; height: 16px; stroke-width: 2.5; }
.chip[aria-pressed="false"] .icon { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards and lists ---------- */

.card {
    background: var(--color-surface);
    border-radius: 22px;
    box-shadow: var(--shadow-1);
    overflow: hidden;
}
.card.padded { padding: 16px; }

.section { display: flex; flex-direction: column; gap: 8px; }
.section-title { margin: 0 4px; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--color-text-secondary); }

.row {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 62px;
    padding: 8px 16px;
    border: 0;
    background: transparent;
    color: var(--color-text);
    text-align: left;
    text-decoration: none;
    transition: background 0.15s;
}
button.row:hover, a.row:hover { background: var(--color-hover); color: var(--color-text); }
.row .title { display: block; font-size: 15px; font-weight: 600; }
.row .subtitle { display: block; font-size: 13px; line-height: 20px; color: var(--color-text-secondary); }
.row .trail { color: var(--color-text-secondary); }
.row.no-lead { grid-template-columns: 1fr auto; }
.row.stacked { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 16px; }
.row.stacked .hint { font-size: 13px; line-height: 20px; color: var(--color-text-secondary); }

.badge-icon {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-surface-low);
    color: var(--color-text-secondary);
}
.badge-icon .icon { width: 18px; height: 18px; }
.badge-icon.accent { background: var(--color-accent-tint); color: var(--color-accent); }

/* ---------- Today ---------- */

.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-nav .date { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.day-nav .date strong { font-size: 18px; line-height: 26px; font-weight: 700; letter-spacing: -0.005em; }
.day-nav .date span { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--color-text-secondary); }

.hero {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    background: var(--color-accent-container);
    color: var(--color-on-accent-container);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hero > * { position: relative; }
.hero .ornament { position: absolute; right: -36px; bottom: -64px; width: 176px; height: 176px; opacity: 0.14; fill: var(--color-accent); }
.hero .label { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.03em; }
.hero .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.hero .name { font-size: 32px; line-height: 40px; font-weight: 800; letter-spacing: -0.02em; }
.hero .time { font-size: 18px; line-height: 26px; font-weight: 700; }
.hero .countdown { font-size: 36px; line-height: 42px; font-weight: 700; letter-spacing: -0.02em; color: var(--color-accent); }
.hero .note { margin-top: 4px; font-size: 13px; line-height: 20px; font-weight: 500; }
.hero.quiet .name { font-size: 22px; line-height: 30px; }

.times { display: flex; flex-direction: column; list-style: none; margin: 0; padding: 0; }
.time-row {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 58px;
    padding: 0 16px;
    font-size: 15px;
    font-weight: 600;
}
.time-row .when { font-variant-numeric: tabular-nums; }
.time-row.minor { color: var(--color-text-secondary); font-weight: 500; }
.time-row.minor .badge-icon { background: transparent; }
.time-row.current { background: var(--color-accent-tint); font-weight: 700; }
.time-row.current .badge-icon { background: var(--color-accent); color: var(--color-on-accent); }
.time-row .name { display: flex; align-items: center; gap: 8px; }
.pill-now {
    font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.02em;
    color: var(--color-on-accent-container); background: var(--color-accent-container);
    border-radius: 9999px; padding: 2px 8px;
}
.tag-next { font-size: 12px; font-weight: 600; color: var(--color-accent); }

.meta-line { text-align: center; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--color-text-secondary); }
.back-today { align-self: center; }

.empty {
    display: flex; flex-direction: column; gap: 16px; align-items: stretch;
    padding: 24px; text-align: center;
}
.empty p { margin: 0; color: var(--color-text-secondary); }
.empty .wordmark { font-size: 28px; line-height: 34px; }

/* ---------- Calendar ---------- */

.month-card { padding: 12px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.month-head { display: flex; align-items: center; justify-content: space-between; }
.month-head .title { text-align: center; }
.month-head .title strong { display: block; font-size: 16px; line-height: 22px; font-weight: 700; }
.month-head .title span { display: block; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--color-text-secondary); }

.weekdays, .month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.weekdays { text-align: center; font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: 0.03em; color: var(--color-text-secondary); }
.day-cell {
    height: 48px;
    border: 0; border-radius: 14px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    padding: 0;
    background: transparent;
    color: var(--color-text);
    font-weight: 500;
    transition: background 0.15s;
}
.day-cell:hover { background: var(--color-hover); }
.day-cell .n { font-size: 15px; line-height: 18px; font-variant-numeric: tabular-nums; }
.day-cell .h { font-size: 10px; line-height: 12px; color: var(--color-text-secondary); }
.day-cell.today { color: var(--color-accent); font-weight: 700; box-shadow: inset 0 0 0 2px var(--color-accent); }
.day-cell[aria-pressed="true"] { background: var(--color-accent); color: var(--color-on-accent); font-weight: 700; box-shadow: none; }
.day-cell[aria-pressed="true"] .h { color: var(--color-on-accent); opacity: 0.85; }

.day-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.day-card .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.day-card .head strong { font-size: 16px; line-height: 22px; }
.day-card .head span { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--color-text-secondary); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 14px; background: var(--color-canvas); }
.tile .k { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--color-text-secondary); }
.tile .v { font-size: 15px; line-height: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile.minor { background: transparent; color: var(--color-text-secondary); }

.table-head { padding: 4px 4px 0; }
.table-wrap { overflow: auto; max-height: 60vh; padding: 0 8px 8px; }
.timetable { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 18px; font-variant-numeric: tabular-nums; }
.timetable th, .timetable td { padding: 6px 4px; text-align: right; white-space: nowrap; }
.timetable th:first-child { text-align: left; padding-left: 6px; }
.timetable thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--color-surface);
    font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: 0.02em; color: var(--color-text-secondary);
}
.timetable tbody th { font-weight: 600; }
.timetable td.minor { color: var(--color-text-secondary); }
.timetable tr.friday { background: var(--color-canvas); }
.timetable tr.today { background: var(--color-accent-tint); color: var(--color-on-accent-container); font-weight: 700; }
.timetable tbody tr { cursor: pointer; }

/* ---------- Dock ---------- */

.dock {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 9999px;
    background: var(--color-dock);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    backdrop-filter: blur(24px) saturate(180%);
    box-shadow: var(--shadow-2);
    transition: transform 0.3s var(--ease), opacity 0.3s;
}
.dock a {
    display: flex; align-items: center; gap: 8px;
    height: 48px; padding: 0 22px;
    border-radius: 9999px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 15px; font-weight: 600;
}
.dock a:hover { color: var(--color-text); }
.dock a[aria-current="page"] { background: var(--color-accent); color: var(--color-on-accent); font-weight: 700; }
body.in-settings .dock { transform: translateX(-50%) translateY(32px) scale(0.92); opacity: 0; pointer-events: none; }

/* ---------- Sheets ---------- */

.scrim {
    position: fixed; inset: 0; z-index: 20;
    background: var(--color-scrim);
    animation: fadeIn 0.28s ease-out;
}
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
    max-height: calc(100dvh - 40px);
    max-width: 560px;
    margin: 0 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--color-surface);
    border-radius: 28px 28px 0 0;
    box-shadow: var(--shadow-sheet);
    padding: 8px 16px calc(env(safe-area-inset-bottom) + 32px);
    display: flex; flex-direction: column; gap: 16px;
    animation: sheetIn 0.28s var(--ease-sheet);
}
.sheet .grabber { align-self: center; width: 40px; height: 4px; border-radius: 9999px; background: var(--color-surface-high); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 22px; line-height: 30px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-head p { margin: 2px 0 0; font-size: 13px; line-height: 20px; color: var(--color-text-secondary); }
.sheet .note { margin: 0 4px; font-size: 13px; line-height: 20px; color: var(--color-text-secondary); }
.sheet .note.center { text-align: center; }
.sheet .list .empty-item { margin: 0; padding: 16px; }
.sheet fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.sheet legend { padding: 0; margin-bottom: 8px; }
.sheet .group { display: flex; flex-direction: column; gap: 8px; }
.sheet .group-label { font-size: 13px; line-height: 20px; font-weight: 600; color: var(--color-text-secondary); }
.sheet .list { list-style: none; margin: 0; padding: 0; border-radius: 22px; background: var(--color-canvas); overflow: hidden; }
.sheet .list .row[aria-checked="true"], .sheet .list .row[aria-current="true"] { background: var(--color-accent-tint); }
.sheet .list .row .check { color: var(--color-accent); visibility: hidden; }
.sheet .list .row[aria-checked="true"] .check, .sheet .list .row[aria-current="true"] .check { visibility: visible; }
.divider { display: flex; align-items: center; gap: 12px; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--color-text-secondary); }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--color-surface-high); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field .group-label { font-size: 13px; line-height: 20px; font-weight: 600; color: var(--color-text-secondary); }
.input {
    display: flex; align-items: center; gap: 8px;
    height: 48px; padding: 0 16px;
    border-radius: 14px;
    background: var(--color-surface-low);
    color: var(--color-text-secondary);
    transition: box-shadow 0.15s, background 0.15s;
}
.input:focus-within { background: var(--color-surface); box-shadow: inset 0 0 0 1.5px var(--color-accent), 0 0 0 3px var(--color-focus); }
.input input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--color-text); font-size: 15px; }
.input input::placeholder { color: var(--color-text-tertiary); }

.stepper { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 9999px; background: var(--color-surface-low); }
.stepper button {
    width: 36px; height: 36px; border: 0; border-radius: 50%;
    background: var(--color-surface); color: var(--color-text);
    font-size: 18px; font-weight: 700; line-height: 1;
}
.stepper output { min-width: 40px; text-align: center; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Settings ---------- */

.about { display: flex; flex-direction: column; gap: 8px; font-size: 13px; line-height: 20px; color: var(--color-text-secondary); }
.about p { margin: 0; }
.about .lead { font-size: 15px; line-height: 24px; color: var(--color-text); font-weight: 600; }
.footer { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 8px; }
.wordmark { font-size: 20px; line-height: 26px; font-weight: 700; letter-spacing: -0.02em; }
.wordmark span { color: var(--color-accent); }
.footer small { font-size: 12px; line-height: 16px; color: var(--color-text-secondary); }

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom) + 96px);
    z-index: 30;
    transform: translateX(-50%) translateY(8px);
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    border-radius: 9999px;
    background: var(--color-text);
    color: var(--color-canvas);
    font-size: 14px; font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Wide screens ---------- */

.today-body, .calendar-body { display: flex; flex-direction: column; gap: 16px; }

/* Side by side rather than a stretched phone layout */
@media (min-width: 768px) {
    .view { max-width: 768px; padding-left: 32px; padding-right: 32px; }
    #calendar-view > .seg { width: 320px; }
    .empty { width: 100%; max-width: 480px; align-self: center; }
    #settings-view { max-width: 560px; }
    .today-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
    .calendar-body { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; }
    .calendar-body.table-mode { display: block; }
    .table-wrap { max-height: none; }
}
@media (min-width: 1100px) {
    .view { max-width: 1040px; }
}

/* ---------- Motion ---------- */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    .btn:active, .icon-btn:active, .chip:active, .day-cell:active { transform: none; }
}
