/* Цвета берутся из темы Telegram (telegram-web-app.js выставляет --tg-theme-*),
   запасные значения — для открытия в обычном браузере. */
:root {
    --bg: var(--tg-theme-bg-color, #f4f1e8);
    --card: var(--tg-theme-secondary-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #2b2a26);
    --hint: var(--tg-theme-hint-color, #8a8577);
    --accent: var(--tg-theme-button-color, #5b8c3a);
    --ok: #3f8f3a;
    --error: var(--tg-theme-destructive-text-color, #c0392b);
    --warn-text: #8a5a00;
    --warn-bg: rgba(255, 176, 32, 0.18);

    /* Отступы от краёв, которые занимает не игра: вырез и строка состояния телефона (safe-area)
       плюс кнопки Telegram поверх приложения — «Закрыть», меню (content-safe-area, считается от safe-area). */
    --inset-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
    --inset-bottom: calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px));
    --inset-left: calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px));
    --inset-right: calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px));
}

/* Тёмная тема Telegram (data-scheme ставит app.js из Telegram.WebApp.colorScheme). */
:root[data-scheme="dark"] {
    --warn-text: #ffc861;
}

* {
    box-sizing: border-box;
}

/* Иначе display: flex у карточек перебивает атрибут hidden. */
[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- участок во весь экран ---------- */

.scene {
    position: fixed;
    inset: 0;
}

.scene canvas {
    display: block;
    touch-action: none;
}

/* ---------- верхняя панель поверх участка ---------- */

.hud {
    position: fixed;
    top: calc(8px + var(--inset-top));
    left: calc(8px + var(--inset-left));
    right: calc(8px + var(--inset-right));
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    pointer-events: none;
}

.hud__chip {
    pointer-events: auto;
    border: 0;
    border-radius: 999px;
    padding: 6px 12px;
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: var(--card);
    background: color-mix(in srgb, var(--card) 88%, transparent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.hud__chip--plain {
    cursor: default;
}

/* ---------- заставка до загрузки и при ошибке ---------- */

.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 24px;
    text-align: center;
    background: var(--bg);
}

.splash p {
    margin: 0;
}

.splash__logo {
    font-size: 56px;
}

.splash__title {
    margin: 0 0 8px;
    font-size: 26px;
}

.splash__greeting {
    font-size: 18px;
    font-weight: 600;
}

/* ---------- нижняя шторка с карточками ---------- */

.sheet {
    position: fixed;
    inset: 0;
}

.sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}

.sheet__panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: calc(100% - var(--inset-top) - 56px);
    overflow-y: auto;
    padding: 40px 12px calc(16px + var(--inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-radius: 18px 18px 0 0;
    background: var(--bg);
    animation: sheet-in 0.2s ease-out;
}

@keyframes sheet-in {
    from {
        transform: translateY(30%);
        opacity: 0;
    }
}

.sheet__close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: 0;
    background: none;
    font-size: 18px;
    color: var(--hint);
    cursor: pointer;
}

.card {
    background: var(--card);
    border-radius: 14px;
    padding: 14px 16px;
}

.card p {
    margin: 0;
}

.card__title {
    margin: 0 0 10px;
    font-size: 20px;
}

.card__hint {
    color: var(--hint);
    font-size: 14px;
}

.card__subtitle {
    margin: 0 0 8px;
    font-size: 16px;
}

/* ---------- ярмарка ---------- */

.fair {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fair .card__title {
    margin: 0;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 3px;
    border-radius: 10px;
    background: rgba(128, 128, 128, 0.15);
}

.segmented__item {
    border: 0;
    border-radius: 8px;
    padding: 7px;
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: none;
    cursor: pointer;
}

.segmented__item--on {
    background: var(--card);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    font-weight: 600;
}

.goods {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.good {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg);
}

.good__info {
    flex: 1;
    min-width: 0;
}

.good__name {
    font-weight: 600;
}

.good__meta {
    font-size: 13px;
    color: var(--hint);
}

.trend--up {
    color: #c0392b;
}

.trend--down {
    color: #3f8f3a;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stepper button {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-size: 18px;
    color: var(--text);
    background: rgba(128, 128, 128, 0.18);
    cursor: pointer;
}

.stepper output {
    min-width: 46px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.fair__trip {
    width: 100%;
}

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

.tariffs .action {
    font-size: 13px;
    line-height: 1.3;
}

/* ---------- дачник ---------- */

.dachnik {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dachnik .card__title {
    margin: 0;
}

.scales {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.scale__head {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.scale .meter__track {
    height: 8px;
    border-radius: 4px;
}

.meter__fill--satiety {
    background: #d9902b;
}

.meter__fill--warmth {
    background: #d9483b;
}

.meter__fill--energy {
    background: #3f9a3a;
}

.meter__fill--low {
    background: #c0392b;
}

.tasks {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.task {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg);
}

.task label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.task input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.task__up {
    border: 0;
    background: none;
    font-size: 16px;
    color: var(--hint);
    cursor: pointer;
}

.journal {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
}

.journal time {
    color: var(--hint);
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}

/* ---------- виноградник ---------- */

.vineyard {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vineyard .card__title {
    margin: 0;
}

.advice {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.advice li {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 14px;
    color: var(--warn-text);
    background: var(--warn-bg);
}

.bushes {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.bush {
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg);
    font-size: 13px;
}

.bush--dead {
    opacity: 0.55;
}

.bush__name {
    font-weight: 600;
}

.bush__state {
    color: var(--hint);
    margin-bottom: 4px;
}

.meter {
    display: flex;
    align-items: center;
    gap: 4px;
}

.meter__track {
    flex: 1;
    height: 5px;
    border-radius: 3px;
    background: rgba(128, 128, 128, 0.2);
    overflow: hidden;
}

.meter__fill {
    height: 100%;
}

.meter__fill--moisture {
    background: #3a86d9;
}

.meter__fill--health {
    background: #3f9a3a;
}

.meter__fill--disease {
    background: #b5651d;
}

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

.action {
    border: 0;
    border-radius: 10px;
    padding: 10px 4px;
    font: inherit;
    font-size: 14px;
    color: var(--tg-theme-button-text-color, #ffffff);
    background: var(--accent);
    cursor: pointer;
}

.action[aria-disabled="true"] {
    color: var(--hint);
    background: rgba(128, 128, 128, 0.15);
}

.action-result {
    font-size: 14px;
}

.status {
    margin-top: 6px !important;
    font-size: 14px;
    color: var(--hint);
}

.status--ok {
    color: var(--ok);
}

.status--error {
    color: var(--error);
}

.calendar {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.calendar__head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.calendar__icon {
    font-size: 36px;
    line-height: 1;
}

.calendar__date {
    font-size: 22px;
    font-weight: 700;
}

.calendar__meta,
.calendar__hint {
    color: var(--hint);
    font-size: 14px;
}

.calendar__progress {
    height: 6px;
    border-radius: 3px;
    background: rgba(128, 128, 128, 0.25);
    background: color-mix(in srgb, var(--hint) 25%, transparent);
    overflow: hidden;
}

.calendar__bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.4s ease;
}

.calendar__local {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
    border-top: 1px solid color-mix(in srgb, var(--hint) 20%, transparent);
}

.weather {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.weather__now {
    display: flex;
    align-items: center;
    gap: 16px;
}

.weather__temp {
    font-size: 44px;
    font-weight: 700;
    line-height: 1.1;
}

.weather__type::first-letter {
    text-transform: uppercase;
}

.weather__range {
    color: var(--hint);
    font-size: 14px;
}

.weather__warnings {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.weather__warnings li {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 14px;
    color: var(--warn-text);
    background: var(--warn-bg);
}

/* Термометр: шкала от −25° до +45°, ртуть синяя в мороз. */
.thermometer {
    --mercury: #d9483b;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: none;
}

.thermometer--cold {
    --mercury: #3a86d9;
}

.thermometer__tube {
    position: relative;
    width: 14px;
    height: 110px;
    border-radius: 7px 7px 0 0;
    background: rgba(128, 128, 128, 0.2);
    overflow: hidden;
}

.thermometer__mercury {
    position: absolute;
    left: 3px;
    right: 3px;
    bottom: 0;
    height: 0;
    border-radius: 4px 4px 0 0;
    background: var(--mercury);
    transition: height 0.6s ease;
}

.thermometer__zero {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 35.7%;
    height: 2px;
    background: var(--hint);
    opacity: 0.6;
}

.thermometer__bulb {
    width: 28px;
    height: 28px;
    margin-top: -4px;
    border-radius: 50%;
    background: var(--mercury);
}

.forecast {
    list-style: none;
    margin: 0;
    padding: 10px 0 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
    text-align: center;
    font-size: 13px;
}

.forecast__day {
    color: var(--hint);
}

.forecast__icon {
    font-size: 22px;
    line-height: 1.6;
}

.forecast__night {
    color: var(--hint);
}

.facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    margin: 0;
}

.facts dt {
    color: var(--hint);
}

.facts dd {
    margin: 0;
    text-align: right;
    overflow-wrap: anywhere;
}
