/*
 * Собственная палитра, а не цвета темы Telegram: у приложения свой характер,
 * а от Telegram берётся только светлая/тёмная схема. Акцент и шкала «тепла»
 * календаря — проверенный синий (валидатор палитры, контраст ≥ 3:1 к подложке).
 */
:root {
    color-scheme: dark;

    --bg-0: #0a0b0f;
    --bg-1: #14161d;
    --bg-2: #1c1f29;
    --ink-0: #f2f4f8;
    --ink-1: #a8b0c0;
    --ink-2: #6f7789;
    --line: rgba(255, 255, 255, .09);
    --line-strong: rgba(255, 255, 255, .16);

    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-dim: rgba(57, 135, 229, .18);
    --danger: #e66767;

    --aurora-1: #3987e5;
    --aurora-2: #7c5cff;
    --aurora-3: #12b3a0;

    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 18px 40px -24px rgba(0, 0, 0, .9);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --ease: cubic-bezier(.22, 1, .36, 1);
    --spring: cubic-bezier(.34, 1.56, .64, 1);
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg-0: #eef1f7;
    --bg-1: #ffffff;
    --bg-2: #f5f7fb;
    --ink-0: #10131a;
    --ink-1: #4b5361;
    --ink-2: #838b9a;
    --line: rgba(16, 19, 26, .09);
    --line-strong: rgba(16, 19, 26, .16);

    --accent: #2a78d6;
    --accent-dim: rgba(42, 120, 214, .12);
    --danger: #d03b3b;

    --shadow: 0 18px 40px -28px rgba(16, 19, 26, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-0);
    color: var(--ink-0);
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(78px + var(--safe-bottom));
    overflow-x: hidden;
}

h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--ink-2); font-size: 13px; }
.hint { color: var(--ink-2); font-size: 11.5px; margin: 10px 0 0; text-align: center; }
.req { color: var(--danger); }
[hidden] { display: none !important; }
button { font-family: inherit; }

/* ─────────── Фон ─────────── */
.aurora {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    overflow: hidden;
}
.aurora-blob {
    position: absolute; display: block;
    width: 70vw; height: 70vw; max-width: 460px; max-height: 460px;
    border-radius: 50%;
    filter: blur(70px);
    opacity: .5;
}
:root[data-theme="light"] .aurora-blob { opacity: .28; }

.aurora-blob.a { background: var(--aurora-1); top: -16vw; left: -18vw; animation: drift-a 24s ease-in-out infinite; }
.aurora-blob.b { background: var(--aurora-2); top: 22vh; right: -26vw; animation: drift-b 30s ease-in-out infinite; }
.aurora-blob.c { background: var(--aurora-3); bottom: -20vh; left: 10vw; opacity: .3; animation: drift-c 34s ease-in-out infinite; }

@keyframes drift-a { 50% { transform: translate3d(8vw, 6vh, 0) scale(1.12); } }
@keyframes drift-b { 50% { transform: translate3d(-10vw, -8vh, 0) scale(.9); } }
@keyframes drift-c { 50% { transform: translate3d(6vw, -10vh, 0) scale(1.15); } }

/* ─────────── Заставка ─────────── */
.gate {
    position: fixed; inset: 0; z-index: 50;
    display: grid; place-items: center;
    background: var(--bg-0); padding: 32px; text-align: center;
}
.gate-card { max-width: 320px; color: var(--ink-1); font-size: 14px; line-height: 1.5; }
.gate-mark { width: 56px; height: 56px; margin: 0 auto 20px; color: var(--accent); }
.gate-mark svg { width: 100%; height: 100%; }
.bolt {
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
    animation: trace 1.6s var(--ease) infinite;
}
@keyframes trace {
    0% { stroke-dashoffset: 120; opacity: .3; }
    55% { stroke-dashoffset: 0; opacity: 1; }
    100% { stroke-dashoffset: -120; opacity: .3; }
}
.gate.error .gate-mark { color: var(--danger); }
.gate.error .bolt { animation: none; stroke-dashoffset: 0; }

/* ─────────── Каркас ─────────── */
.screen { position: relative; z-index: 1; padding: calc(16px + var(--safe-top)) 16px 8px; }
.screen-head { margin-bottom: 16px; }
.block { margin-top: 26px; }

.section-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
}

.card {
    background: color-mix(in srgb, var(--bg-1) 82%, transparent);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

/* ─────────── Герой ─────────── */
.hero { padding: 8px 4px 22px; }
.hero.compact { padding-bottom: 16px; }
.greeting { margin: 0 0 14px; color: var(--ink-2); font-size: 13px; }
/* Только первая буква, а не каждое слово: «Среда, 29 июля», не «29 Июля» */
.greeting::first-letter, .hero-title h1::first-letter, .day-panel h2::first-letter { text-transform: uppercase; }

.hero-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.hero-title {
    flex: 1; border: none; background: none; color: inherit;
    display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}

.hero-year { font-size: 12px; color: var(--ink-2); }

.hero-figure { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hero-value {
    font-size: 54px; font-weight: 680; line-height: 1;
    letter-spacing: -.04em;
    background: linear-gradient(135deg, var(--ink-0) 30%, var(--accent));
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.hero-figure.small .hero-value { font-size: 34px; }
.hero-unit { font-size: 13px; color: var(--ink-2); }

/* ─────────── Метр ─────────── */
.meter { margin-top: 18px; }
.meter-track {
    height: 8px; border-radius: 999px; overflow: hidden;
    background: var(--accent-dim);
}
.meter-fill {
    height: 100%; width: 0; border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--aurora-2)));
    transition: width .9s var(--ease);
}
.meter-legend {
    display: flex; justify-content: space-between; gap: 12px;
    margin-top: 8px; font-size: 12px; color: var(--ink-1);
}

.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero-top .greeting { margin-bottom: 0; padding-top: 10px; }

/* ─────────── Настройки ─────────── */
.settings-lead { line-height: 1.5; margin: 0 0 14px; }
.settings-state {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.settings-state .pill.custom { background: color-mix(in srgb, var(--aurora-2) 20%, transparent); color: var(--aurora-2); }

/* Промпт — код, а не проза: моноширинный и с переносами как есть */
#prompt-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px; line-height: 1.55; white-space: pre-wrap;
}

.settings-test {
    margin-top: 18px; padding-top: 18px;
    border-top: 1px solid var(--line);
}
.chip-btn.wide { width: 100%; padding: 11px; }
#prompt-result { margin-top: 12px; }

.result-note {
    font-size: 12.5px; line-height: 1.5; padding: 12px 14px;
    border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-2) 70%, transparent); color: var(--ink-1);
}
.result-note.bad { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.result-note.warn { border-color: color-mix(in srgb, var(--aurora-2) 45%, transparent); }

/* ─────────── Быстрая запись ─────────── */
.quick textarea { margin-top: 0; }
.quick-actions { display: flex; gap: 8px; margin-top: 10px; }
.quick-actions .primary-btn { flex: 1; }

/* ─────────── Плитки ─────────── */
.tiles {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    margin-top: 26px;
}
.tile {
    background: color-mix(in srgb, var(--bg-1) 70%, transparent);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px 10px; text-align: center;
}
.tile-value { display: block; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
.tile-label { display: block; margin-top: 3px; font-size: 11px; color: var(--ink-2); }

/* ─────────── Календарь ─────────── */
.cal-card { padding: 14px; }
.weekdays {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
    margin-bottom: 8px; font-size: 10.5px; text-transform: uppercase;
    color: var(--ink-2); text-align: center; letter-spacing: .06em;
}
.grid-viewport { overflow: hidden; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.grid.slide-left { animation: slide-left .32s var(--ease); }
.grid.slide-right { animation: slide-right .32s var(--ease); }
@keyframes slide-left { from { transform: translateX(26%); opacity: 0; } }
@keyframes slide-right { from { transform: translateX(-26%); opacity: 0; } }

.day {
    position: relative;
    aspect-ratio: 1 / 1;
    border: 1px solid transparent; border-radius: 12px;
    background: var(--bg-2);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    font-size: 14px; font-weight: 500; color: var(--ink-0);
    cursor: pointer; padding: 0;
    transition: transform .16s var(--spring), background .2s ease, border-color .2s ease;
    animation: pop-in .3s var(--ease) backwards;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.86); } }
.day:active { transform: scale(.9); }
.day.blank { background: transparent; cursor: default; animation: none; }
.day.weekend:not(.heat-1):not(.heat-2):not(.heat-3):not(.heat-4) { color: var(--ink-2); }
.day.today { border-color: var(--accent); font-weight: 700; }
.day.selected { border-color: var(--ink-0); }
.day.selected::after {
    content: ''; position: absolute; inset: -3px; border-radius: 14px;
    border: 1.5px solid var(--ink-0); opacity: .35;
}

/* Один тон, светлее → темнее: последовательная шкала магнитуды */
.day.heat-1 { background: color-mix(in srgb, var(--accent) 16%, var(--bg-2)); }
.day.heat-2 { background: color-mix(in srgb, var(--accent) 34%, var(--bg-2)); }
.day.heat-3 { background: color-mix(in srgb, var(--accent) 58%, var(--bg-2)); }
.day.heat-4 { background: var(--accent); color: var(--accent-ink); }
.day.heat-4 .day-hours { color: var(--accent-ink); opacity: .85; }

.day-hours { font-size: 9.5px; font-weight: 650; line-height: 1; color: var(--accent); }
.day.heat-2 .day-hours, .day.heat-3 .day-hours { color: var(--ink-0); opacity: .7; }

/* ─────────── Записи ─────────── */
.entries { display: flex; flex-direction: column; gap: 8px; }

.entry {
    background: color-mix(in srgb, var(--bg-1) 78%, transparent);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px 14px; cursor: pointer;
    display: flex; gap: 13px; align-items: flex-start;
    transition: transform .16s var(--spring), border-color .2s ease;
    animation: rise-in .34s var(--ease) backwards;
}
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } }
.entry:active { transform: scale(.985); border-color: var(--line-strong); }

.entry-hours {
    min-width: 46px; text-align: center; line-height: 1.1;
    font-size: 18px; font-weight: 680; color: var(--accent); letter-spacing: -.02em;
}
.entry-hours small { display: block; font-size: 9.5px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.entry-body { flex: 1; min-width: 0; }
.entry-title { font-size: 14px; font-weight: 600; }
.entry-title.empty { color: var(--ink-2); font-weight: 400; font-style: italic; }
.entry-desc { font-size: 13px; color: var(--ink-1); margin-top: 2px; word-break: break-word; }
.entry-meta { font-size: 11px; color: var(--ink-2); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.entry-chevron { color: var(--ink-2); align-self: center; width: 16px; height: 16px; flex: none; }
.entry-chevron svg { width: 100%; height: 100%; }

.empty-state {
    text-align: center; color: var(--ink-2); font-size: 13.5px;
    padding: 26px 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
}

/* ─────────── Недели ─────────── */
.weeks { display: flex; flex-direction: column; gap: 10px; }
.week-card {
    background: color-mix(in srgb, var(--bg-1) 80%, transparent);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px;
    animation: rise-in .34s var(--ease) backwards;
}
.week-top { display: flex; align-items: flex-start; gap: 12px; }
.week-main { flex: 1; min-width: 0; cursor: pointer; }
.week-kw { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.week-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.week-hours { font-size: 18px; font-weight: 680; color: var(--accent); letter-spacing: -.02em; }

.week-bottom { display: flex; align-items: flex-end; gap: 14px; margin-top: 14px; }

/* Мини-график недели: тонкие столбики, один тон, скруглённая вершина.
   Ширина ограничена — столбик не должен заполнять свою полосу целиком.
   Базовая линия — сплошной волосок, чтобы нулевые дни читались как нули. */
.week-spark {
    flex: 1; min-width: 0;
    display: grid; grid-template-columns: repeat(7, 1fr);
    align-items: end; height: 26px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 3px;
}
.spark-slot { display: flex; justify-content: center; align-items: flex-end; height: 100%; }
.spark-bar {
    width: 100%; max-width: 14px; min-height: 2px;
    background: var(--accent-dim); border-radius: 3px 3px 1px 1px;
    transition: height .5s var(--ease);
}
.spark-bar.filled { background: var(--accent); }

.chip-btn {
    padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: 999px;
    background: transparent; color: var(--accent);
    font-size: 12.5px; font-weight: 600; cursor: pointer;
    transition: transform .16s var(--spring), background .2s ease;
}
.chip-btn:active { transform: scale(.93); }
.chip-btn:disabled { opacity: .5; }

.week-reports { margin-top: 14px; }

/* ─────────── Формы ─────────── */
label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 14px; }
input, textarea {
    display: block; width: 100%; margin-top: 6px; padding: 12px 13px;
    font-size: 16px; font-family: inherit;
    color: var(--ink-0); background: var(--bg-2);
    border: 1px solid transparent; border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .2s ease, background .2s ease;
}
input:focus, textarea:focus { border-color: var(--accent); background: var(--bg-1); }
textarea { resize: vertical; line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }
.chips button {
    padding: 7px 13px; border: 1px solid var(--line-strong); border-radius: 999px;
    background: transparent; color: var(--ink-1); font-size: 13px; cursor: pointer;
    transition: transform .16s var(--spring), background .2s ease, color .2s ease;
}
.chips button:active { transform: scale(.94); }
.chips button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.primary-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 14px;
    border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: var(--accent-ink);
    font-size: 15px; font-weight: 620; cursor: pointer;
    transition: transform .16s var(--spring), opacity .2s ease;
}
.primary-btn:active { transform: scale(.97); }
.primary-btn:disabled { opacity: .55; }
.primary-btn svg { width: 18px; height: 18px; }
.primary-btn.ghost {
    background: transparent; color: var(--accent);
    border: 1px dashed var(--line-strong);
}

.danger-btn {
    padding: 14px 18px; border: none; border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--danger) 16%, transparent);
    color: var(--danger); font-size: 15px; font-weight: 620; cursor: pointer;
}

.link-btn {
    border: none; background: none; color: var(--accent);
    font-size: 13px; font-weight: 550; cursor: pointer; padding: 4px;
}

.icon-btn {
    width: 40px; height: 40px; flex: none;
    display: grid; place-items: center;
    border: 1px solid var(--line); border-radius: 50%;
    background: color-mix(in srgb, var(--bg-1) 70%, transparent);
    color: var(--ink-0); cursor: pointer;
    transition: transform .16s var(--spring), background .2s ease;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.wide { width: 52px; height: auto; border-radius: var(--radius-sm); }

.pill {
    font-size: 12px; font-weight: 620; padding: 5px 12px;
    border-radius: 999px; background: var(--accent-dim); color: var(--accent);
    white-space: nowrap;
}

/* ─────────── Нижняя навигация ─────────── */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(3, 1fr);
    background: color-mix(in srgb, var(--bg-0) 82%, transparent);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
}
.tabbar button {
    border: none; background: none; cursor: pointer;
    padding: 10px 4px 12px;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-size: 10px; color: var(--ink-2);
    transition: color .2s ease;
}
.tabbar svg {
    width: 22px; height: 22px; fill: none;
    stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    transition: transform .28s var(--spring);
}
.tabbar button.active { color: var(--accent); font-weight: 620; }
.tabbar button.active svg { transform: translateY(-2px) scale(1.08); }

/* ─────────── Лист записи ─────────── */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0, 0, 0, .5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: flex; align-items: flex-end;
    animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
    width: 100%; max-height: 92vh; overflow-y: auto;
    background: var(--bg-1);
    border-radius: 24px 24px 0 0;
    border-top: 1px solid var(--line-strong);
    padding: 10px 16px calc(22px + var(--safe-bottom));
    animation: rise .32s var(--ease);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-grip {
    width: 38px; height: 4px; border-radius: 999px;
    background: var(--line-strong); margin: 0 auto 14px;
}
.sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 18px;
}
.sheet-head h2 { font-size: 17px; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-actions .primary-btn { flex: 1; }

/* ─────────── Тост ─────────── */
.toast {
    position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom));
    transform: translateX(-50%); z-index: 60;
    max-width: 86vw; padding: 11px 18px;
    background: var(--ink-0); color: var(--bg-0);
    border-radius: 999px; font-size: 13px; font-weight: 550; text-align: center;
    box-shadow: var(--shadow);
    animation: toast-in .3s var(--spring);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px); } }
.toast.error { background: var(--danger); color: #fff; }

/* ─────────── Загрузка без скачка вёрстки ─────────── */
.is-loading { opacity: .45; transition: opacity .2s ease; }

@media (min-width: 620px) {
    .screen, .tabbar { max-width: 600px; margin-inline: auto; }
    .tabbar { border-radius: 18px 18px 0 0; border-inline: 1px solid var(--line); }
    .sheet { max-width: 600px; margin-inline: auto; border-radius: 24px; margin-bottom: 20px; }
    .sheet-backdrop { align-items: center; justify-content: center; padding: 20px; }
}

/* Уважаем системную настройку: без дрейфа фона и въездов */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
