/* Mini App «Книга Жизни».
 * Light design based on Apple Human Interface Guidelines (iOS light) — tokens from
 * designsystems.one style-spec `apple-hig` (schema 1, checked 2026-10-27): colors, SF font stack,
 * type scale 34/28/22/17/15/13, radius 8/10/20, spacing 4/8/16/20/32, subtle shadow.
 * Always light (Ivan: «чтобы он был светлый»), independent of the Telegram dark theme.
 * Layout: inset grouped lists (iOS Settings style), 44px touch targets. */
:root {
    color-scheme: light;
    --blue: #007aff;
    --blue-press: #0062cc;
    --label: #1c1c1e;
    --label-2: #6c6c70; /* secondary label, darker than #8e8e93 for WCAG AA on #f2f2f7 */
    --bg: #f2f2f7; /* grouped background */
    --surface: #ffffff;
    --fill: #f2f2f7; /* input fill inside white cards */
    --separator: #c6c6c8;
    --red: #d70015; /* accessible variant of #ff3b30 for text */
    --green: #248a3d; /* accessible variant of #34c759 for text */
    --orange: #c93400;
    --r-ctl: 10px;
    --r-card: 12px;
    --r-large: 20px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    --font:
        -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
        "Segoe UI", Roboto, sans-serif;
    --font-display:
        -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue",
        "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--label);
    font: 17px/1.35 var(--font);
    -webkit-font-smoothing: antialiased;
}

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 8px 16px calc(48px + env(safe-area-inset-bottom));
}

/* ---------- screens: every <section> is a page ---------- */
section {
    animation: vb-in 0.18s ease-out;
}
@keyframes vb-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}
@media (prefers-reduced-motion: reduce) {
    section {
        animation: none;
    }
}

/* ---------- typography (HIG type scale) ---------- */
h1 {
    font: 700 28px/34px var(--font-display);
    letter-spacing: 0.01em;
    margin: 4px 4px 16px;
}
#screen-home > h1 {
    font-size: 34px;
    line-height: 41px;
    margin-top: 12px;
}
h2 {
    /* iOS section header above a grouped block */
    font: 600 13px/18px var(--font);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--label-2);
    margin: 28px 16px 8px;
}
h3 {
    font: 600 17px/22px var(--font);
    margin: 16px 0 6px;
}
p {
    margin: 0 0 12px;
}
a {
    color: var(--blue);
}
.muted {
    color: var(--label-2);
}
.small {
    font-size: 13px;
    line-height: 18px;
}

/* ---------- navigation: "‹ Назад" like an iOS nav bar ---------- */
button.back {
    position: sticky;
    top: 0;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    width: auto;
    min-height: 44px;
    margin: 0 0 4px -8px;
    padding: 0 8px;
    font-size: 17px;
    font-weight: 400;
    color: var(--blue);
    background: rgba(242, 242, 247, 0.92);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-radius: var(--r-ctl);
}

/* ---------- home: inset grouped list of exercises ---------- */
nav {
    background: var(--surface);
    border-radius: var(--r-card);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin: 0 0 8px;
}
nav:empty {
    display: none;
}
#screen-home nav + nav {
    margin-top: 0;
}
.nav-title {
    font: 600 13px/18px var(--font);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--label-2);
    margin: 24px 16px 8px;
}
button.tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    margin: 0;
    padding: 8px 36px 8px 12px;
    font: 400 17px/22px var(--font);
    text-align: left;
    color: var(--label);
    background: var(--surface);
    border: 0;
    border-radius: 0;
}
/* hairline separator starting after the icon, like iOS */
button.tile + button.tile::before {
    content: "";
    position: absolute;
    top: 0;
    left: 56px;
    right: 0;
    border-top: 0.5px solid var(--separator);
}
/* chevron */
button.tile::after {
    content: "";
    position: absolute;
    right: 16px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-top: 2px solid #c4c4c7;
    border-right: 2px solid #c4c4c7;
    transform: translateY(-50%) rotate(45deg);
}
button.tile:active {
    background: #e5e5ea;
}
.tile .ico {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    line-height: 1;
    border-radius: 8px;
    background: var(--ico-bg, #e8f1ff);
}
.tile .ttl {
    flex: 1 1 auto;
}

/* ---------- content cards: forms, info, history ---------- */
form,
details.info,
.card,
#goal-work,
.wish-list:not(:empty),
.photo-pick {
    background: var(--surface);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
    padding: 16px;
    margin: 0 0 12px;
}
form:empty {
    display: none;
}
form form {
    box-shadow: none;
    padding: 0;
}

label {
    display: block;
    font: 600 15px/20px var(--font);
    color: var(--label);
    margin: 16px 0 6px;
}
form > label:first-child,
form > div:first-child > label:first-child,
.field:first-child > label:first-child {
    margin-top: 0;
}

input,
textarea,
select {
    width: 100%;
    min-height: 44px;
    padding: 11px 12px;
    font: 400 17px/22px var(--font);
    color: var(--label);
    background: var(--fill);
    border: 1px solid transparent;
    border-radius: var(--r-ctl);
    -webkit-appearance: none;
    appearance: none;
}
input[type="checkbox"],
input[type="radio"] {
    width: 22px;
    min-height: 0;
    height: 22px;
    padding: 0;
    -webkit-appearance: auto;
    appearance: auto;
    accent-color: var(--blue);
}
input[type="range"] {
    padding: 0;
    min-height: 32px;
    background: none;
    -webkit-appearance: auto;
    appearance: auto;
    accent-color: var(--blue);
}
textarea {
    resize: vertical;
    min-height: 88px;
}
input::placeholder,
textarea::placeholder {
    color: #8e8e93;
}
input:focus,
textarea:focus,
select:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.18);
}
button:focus-visible,
summary:focus-visible,
.upload:focus-within {
    outline: 3px solid rgba(0, 122, 255, 0.45);
    outline-offset: 2px;
}

/* ---------- buttons ---------- */
button {
    display: block;
    width: 100%;
    min-height: 50px;
    margin-top: 16px;
    padding: 12px 16px;
    font: 600 17px/22px var(--font);
    color: #fff;
    background: var(--blue);
    border: 0;
    border-radius: var(--r-card);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        background-color 0.12s,
        transform 0.12s;
}
button:active {
    background: var(--blue-press);
    transform: scale(0.99);
}
button:disabled {
    opacity: 0.45;
    cursor: default;
}
button.secondary {
    color: var(--blue);
    background: #e8f1ff;
}
button.secondary:active {
    background: #d6e6ff;
}
button.link {
    display: inline-block;
    width: auto;
    min-height: 44px;
    margin-top: 4px;
    padding: 10px 4px;
    font-weight: 400;
    color: var(--blue);
    background: none;
}
button.link:active {
    background: none;
    opacity: 0.6;
    transform: none;
}
/* small inline buttons inside lists (wish list, photos, history) */
li button,
figcaption button,
.photo-card button,
.inline button {
    display: inline-flex;
    align-items: center;
    width: auto;
    min-height: 36px;
    margin: 0;
    padding: 6px 12px;
    font-size: 15px;
    border-radius: 18px;
}

/* ---------- status messages ---------- */
.msg {
    min-height: 1.4em;
    margin: 12px 4px 0;
    font-size: 15px;
}
.msg.error {
    color: var(--red);
}
.saved {
    display: block;
    min-height: 18px;
    margin-top: 8px;
    color: var(--green);
    text-align: center;
}
.field {
    margin-bottom: 0;
}
/* fields inside one card are split by a hairline, like grouped rows */
.field + .field {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 0.5px solid var(--separator);
}
.field > label {
    margin-top: 0;
}
.field > p.small {
    margin: -2px 0 8px;
}
/* empty "сохранено" status takes no space until it has text */
.saved:empty {
    min-height: 0;
    margin: 0;
}

/* ---------- "how to do it" disclosure ---------- */
details.info {
    padding: 0;
}
details.info summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--blue);
    cursor: pointer;
    list-style: none;
}
details.info summary::-webkit-details-marker {
    display: none;
}
details.info summary::before {
    content: "ⓘ";
    font-weight: 400;
}
details.info[open] summary {
    border-bottom: 0.5px solid var(--separator);
}
details.info > :not(summary) {
    margin: 12px 16px 16px;
}
/* nested inside a form card: inline disclosure, no card-in-card */
form details.info,
.field details.info {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    margin: 0 0 8px;
}
form details.info summary,
.field details.info summary {
    min-height: 44px;
    padding: 8px 0;
}
form details.info > :not(summary),
.field details.info > :not(summary) {
    margin: 8px 0 12px;
}

/* ---------- history: past days ---------- */
details.day {
    background: var(--surface);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
    padding: 0;
    margin-bottom: 8px;
    overflow: hidden;
}
details.day summary {
    position: relative;
    min-height: 48px;
    padding: 13px 40px 13px 16px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
details.day summary::-webkit-details-marker {
    display: none;
}
details.day summary::after {
    content: "";
    position: absolute;
    right: 18px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #c4c4c7;
    border-bottom: 2px solid #c4c4c7;
    transform: translateY(-70%) rotate(45deg);
    transition: transform 0.15s;
}
details.day[open] summary::after {
    transform: translateY(-30%) rotate(-135deg);
}
details.day[open] summary {
    border-bottom: 0.5px solid var(--separator);
}
details.day > :not(summary) {
    margin: 12px 16px;
}
.entry {
    white-space: pre-wrap;
    margin: 0 0 8px;
}
ul#goal-history,
ul.plain {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
}
ul#goal-history:empty {
    display: none;
}
ul#goal-history li,
ul.plain li {
    padding: 12px 16px;
    border-top: 0.5px solid var(--separator);
}
ul#goal-history li:first-child,
ul.plain li:first-child {
    border-top: 0;
}

[hidden] {
    display: none !important;
}

/* ---------- Утро Перемен / Моя Цель: big numbers ---------- */
.timer {
    font: 300 56px/1.1 var(--font-display);
    font-variant-numeric: tabular-nums;
    text-align: center;
    margin: 12px 0;
    color: var(--label);
}

/* ---------- day form «СТАРТ» countdown (legacy BOD) ---------- */
.dayform-timer {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 6px 0 8px;
}
.dayform-timer button {
    width: auto;
    min-height: 44px;
    padding: 0 20px;
    margin: 0;
}
.dayform-clock {
    font: 500 22px/1 var(--font-display);
    font-variant-numeric: tabular-nums;
    color: var(--label);
}

/* ---------- Квадрат Декарта step flow (legacy best/Square.php) ---------- */
.square-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 6px 0 8px;
}
.square-bar button {
    width: auto;
    margin: 0;
}
.square-step:empty {
    display: none;
}
.square-step {
    color: var(--green, #248a3d);
    font-weight: 600;
}
.cset-sub {
    margin: 0 0 4px;
    color: var(--red, #d70015);
    font-size: 17px;
}

/* ---------- wish lists ---------- */
.wish-list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0 16px;
}
.wish-list:empty {
    display: none;
}
.wish-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    min-height: 52px;
    padding: 10px 0;
    border-bottom: 0.5px solid var(--separator);
}
.wish-list li:last-child {
    border-bottom: 0;
}
.wish-list li label {
    flex: 1 1 60%;
    margin: 0;
    font-weight: 400;
}
.wish-list li.done label {
    text-decoration: line-through;
    color: var(--label-2);
}

/* ---------- life wheel ---------- */
.wheel-row {
    display: grid;
    grid-template-columns: 1fr 1.6fr 2rem;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    border-bottom: 0.5px solid var(--separator);
}
.wheel-row:last-of-type {
    border-bottom: 0;
}
/* wheel row = one element with both .field and .wheel-row: draw one hairline only */
.field.wheel-row,
.field.wheel-row + .field.wheel-row {
    margin: 0;
    padding: 0;
    border-top: 0;
    border-bottom: 0.5px solid var(--separator);
}
.field.wheel-row:not(:has(+ .wheel-row)) {
    border-bottom: 0;
}
.wheel-row label {
    display: flex;
    align-items: center;
    margin: 0;
    font-weight: 400;
}
.wheel-row output {
    text-align: right;
    font-weight: 600;
    color: var(--label);
    font-variant-numeric: tabular-nums;
}
.wheel-row label::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--c, var(--blue));
    flex: none;
}
/* sphere-coloured slider (colours from the old site) */
.wheel-row input.wheel-range {
    min-height: 0;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: linear-gradient(
        to right,
        var(--c, var(--blue)) var(--p, 0%),
        #e5e5ea var(--p, 0%)
    );
    accent-color: var(--c, var(--blue));
}
input.wheel-range:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 4px;
}
input.wheel-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fff;
    border: 0.5px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
input.wheel-range::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fff;
    border: 0.5px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
input.wheel-range:disabled {
    opacity: 0.75;
}

/* radar + energy donut */
.wheel-chart .card-title {
    margin: 0 0 8px;
    padding: 0;
}
#wheel-radar svg.radar {
    display: block;
    width: 100%;
    max-width: 360px;
    height: auto;
    margin: 0 auto;
    overflow: visible;
}
.radar-grid {
    fill: none;
    stroke: #d1d1d6;
    stroke-width: 1;
}
.radar-label {
    font-size: 11px;
    fill: var(--label-2);
}
.radar-now {
    fill-opacity: 0.22;
    stroke-width: 2.5;
    stroke-linejoin: round;
}
.radar-past {
    fill-opacity: 0.06;
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
    stroke-linejoin: round;
}
.wheel-legend {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 14px;
    color: var(--label-2);
}
.wheel-legend .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 50%;
    vertical-align: 0;
}
.wheel-energy {
    display: flex;
    align-items: center;
    gap: 16px;
}
#wheel-donut svg.donut {
    display: block;
    width: 110px;
    height: 110px;
    flex: none;
}
.donut-rest {
    fill: none;
    stroke: #20c3ed;
    stroke-width: 14;
}
.donut-value {
    fill: none;
    stroke: #b3031a;
    stroke-width: 14;
}
.donut-num {
    font-size: 26px;
    font-weight: 700;
    fill: var(--label);
}

/* ---------- photos: Доска мечты / Сценарий / Утро Перемен ---------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin: 8px 0 16px;
}
.photo-grid > p,
.photo-grid > button,
.photo-grid > a {
    grid-column: 1 / -1;
    justify-self: start;
    text-align: left;
}
.photo-pick:empty {
    display: none;
}
/* step blocks placed directly in a screen (Утро Перемен etc.) are cards too */
section > .field {
    background: var(--surface);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
    padding: 16px;
    margin: 0 0 12px;
}
section > .field + .field {
    margin-top: 0;
    padding-top: 16px;
    border-top: 0;
}
section > .field > h2:first-child {
    margin: 0 0 8px;
    color: var(--blue);
}
section > .field > .photo-pick {
    box-shadow: none;
    padding: 0;
}
.photo-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--r-ctl);
    cursor: pointer;
    background: #e5e5ea;
}
.photo-big {
    display: block;
    max-width: 100%;
    max-height: 60vh;
    margin: 8px auto;
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
}
.photo-hist {
    display: block;
    max-width: 100%;
    max-height: 220px;
    margin: 6px 0;
    border-radius: var(--r-ctl);
}
.photo-card {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.photo-card.main .photo-thumb {
    outline: 3px solid var(--blue);
    outline-offset: 2px;
}
.photo-card figcaption {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: space-between;
    font-size: 13px;
}
/* VK photo temporarily unavailable: keep the URL, only hide the broken image icon */
img.broken {
    background: #e5e5ea;
}
.photo-big.broken,
.photo-hist.broken {
    display: none;
}
.upload {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    padding: 12px 16px;
    margin: 12px 0;
    border-radius: var(--r-card);
    cursor: pointer;
    font-weight: 600;
    background: #e8f1ff;
    color: var(--blue);
}
.upload input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* ---------- Медитация: 16:9 video player ---------- */
.video-box {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--r-card);
    overflow: hidden;
    background: #000;
}
.video-box iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
#meditation-player .card-title {
    margin: 0 0 8px;
    padding: 0;
}

/* ---------- Игра в Процветание ---------- */
.game-account {
    text-align: center;
}
.game-account p {
    margin: 0;
}
.game-sum {
    font-size: 28px;
    font-weight: 700;
    color: var(--label);
    font-variant-numeric: tabular-nums;
    margin: 2px 0 10px !important;
}
#form-game .card-title {
    margin: 0 0 4px;
    padding: 0;
}
#form-game button.secondary {
    margin-top: 8px;
}
.errors {
    color: var(--red) !important;
}
button.link.danger {
    color: var(--red);
}

/* ---------- ⚙️ settings (account, «Открыть в браузере») ---------- */
button.gear {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top));
    right: 12px;
    z-index: 30;
    width: 44px;
    min-height: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    font-size: 22px;
    line-height: 44px;
    color: var(--label);
    background: var(--surface);
    border-radius: 50%;
    box-shadow: var(--shadow);
}
button.gear:active {
    background: var(--fill);
}
.gear-menu {
    position: fixed;
    top: calc(60px + env(safe-area-inset-top));
    right: 12px;
    z-index: 31;
    width: min(320px, calc(100vw - 24px));
    padding: 16px;
    background: var(--surface);
    border-radius: var(--r-large);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.gear-menu[hidden] {
    display: none;
}
.gear-who {
    font-weight: 600;
    margin-bottom: 4px;
    overflow-wrap: anywhere;
}
.gear-menu button {
    margin-top: 12px;
}
.gear-menu .msg:empty {
    display: none;
}
/* Keep page titles clear of the fixed gear button. */
section > h1 {
    padding-right: 52px;
}
