/*
 * Остров: холст на весь экран, интерфейс поверх него карточками.
 *
 * Панели полупрозрачные и не перекрывают середину экрана — город должен
 * оставаться главным, а цифры только подсказывать. Всё, что не холст,
 * пропускает щелчки мимо себя (`pointer-events: none` у контейнеров),
 * иначе пустое место между карточками мешало бы таскать карту.
 */

:root {
    --ink: #1f2a33;
    --muted: #6b7a86;
    --card: rgba(255, 253, 247, 0.9);
    --line: rgba(31, 42, 51, 0.1);
    --accent: #e39b3b;
    --good: #5fae4e;
    --warn: #e2a33a;
    --bad: #d9534f;
    --radius: 14px;
    --shadow: 0 6px 24px rgba(20, 40, 60, 0.18);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #2c7fb8;
    color: var(--ink);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

[hidden] {
    display: none !important;
}

.stage {
    position: fixed;
    inset: 0;
    touch-action: none;
}

.stage canvas {
    display: block;
}

/* ----------------------------------------------------------------- шапка */

.hud {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    pointer-events: none;
}

.hud__card,
.panel {
    background: var(--card);
    backdrop-filter: blur(8px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    pointer-events: auto;
}

.hud__card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 14px;
}

.hud__city {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 220px;
}

.hud__title {
    font-weight: 700;
    font-size: 16px;
}

.hud__level {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.hud__muted {
    color: var(--muted);
    font-weight: 400;
}

.hud__speed {
    gap: 4px;
    padding: 6px;
    margin-left: auto;
}

.stat b {
    font-variant-numeric: tabular-nums;
}

.speed {
    border: 0;
    border-radius: 9px;
    padding: 6px 10px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.speed:hover {
    background: var(--line);
}

.speed--active {
    background: var(--ink);
    color: #fff;
}

.bar {
    position: relative;
    flex: 1;
    height: 6px;
    min-width: 60px;
    border-radius: 3px;
    background: var(--line);
    overflow: hidden;
}

.bar__fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.3s;
}

/* ---------------------------------------------------------------- панели */

.side {
    position: fixed;
    top: 84px;
    bottom: 40px;
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.side--left {
    left: 12px;
}

.side--right {
    right: 12px;
    width: 320px;
}

.panel {
    padding: 12px 14px;
    min-height: 0;
}

.panel--grow {
    flex: 1;
    overflow: auto;
}

.panel__title {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.projects,
.people,
.events {
    list-style: none;
    margin: 0;
    padding: 0;
}

.projects li {
    padding: 6px 0;
    border-top: 1px solid var(--line);
}

.projects li:first-child {
    border-top: 0;
}

.projects__name {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-weight: 600;
}

.projects__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

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

.people li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    margin: 0 -6px;
    border-radius: 8px;
    cursor: pointer;
}

.people li:hover {
    background: var(--line);
}

.people li.is-selected {
    background: rgba(227, 155, 59, 0.18);
}

.people__dot {
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.people__name {
    font-weight: 600;
}

.people__doing {
    margin-left: auto;
    max-width: 55%;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.events li {
    padding: 4px 0;
    font-size: 13px;
    border-top: 1px solid var(--line);
}

.events li:first-child {
    border-top: 0;
}

.events time {
    margin-right: 6px;
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.events li[data-citizen] {
    cursor: pointer;
}

/* -------------------------------------------------------- карточка жителя */

.citizen {
    position: relative;
    flex: none;
}

.citizen__close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: 0;
    background: transparent;
    font-size: 18px;
    color: var(--muted);
    cursor: pointer;
}

.citizen__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding-right: 20px;
}

.citizen__avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
}

.citizen__name {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.2;
}

.citizen__nick {
    color: var(--muted);
    font-size: 12px;
}

.citizen__row {
    margin: 6px 0;
    font-size: 13px;
}

.citizen__row b {
    font-weight: 600;
}

.citizen__label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.citizen__thought {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(31, 42, 51, 0.05);
    font-size: 13px;
    font-style: italic;
}

.needs {
    display: grid;
    grid-template-columns: auto 1fr 28px;
    align-items: center;
    gap: 5px 8px;
    margin: 10px 0;
    font-size: 12px;
}

.needs .bar {
    height: 8px;
}

.needs__value {
    text-align: right;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.relations {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    font-size: 13px;
}

.relations li {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 0;
    cursor: pointer;
}

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

.relations__kind--crush {
    color: #d6457a;
    font-weight: 600;
}

/* ------------------------------------------------------------ панель Бога */

.god {
    flex: none;
    border: 2px solid rgba(227, 155, 59, 0.55);
}

.god__form {
    display: grid;
    gap: 6px;
    margin-bottom: 8px;
}

.god__fields {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 6px;
}

.god__row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.god__row--split {
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.input {
    width: 100%;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.button {
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.button:hover {
    border-color: rgba(31, 42, 51, 0.3);
}

.button--primary {
    flex: 1;
    border-color: var(--ink);
    background: var(--ink);
    color: #fff;
}

.button--danger {
    border-color: rgba(217, 83, 79, 0.4);
    color: var(--bad);
}

.citizen__remove {
    width: 100%;
    margin-top: 8px;
}

.login {
    position: fixed;
    left: 50%;
    top: 30%;
    z-index: 6;
    width: min(320px, calc(100vw - 32px));
    transform: translateX(-50%);
    display: grid;
    gap: 8px;
}

.login__error {
    margin: 0;
    color: var(--bad);
    font-size: 13px;
}

/* ------------------------------------------------- карточки зданий и мэрии */

.citizen {
    max-height: 72vh;
    overflow: auto;
}

.citizen__avatar--icon {
    background: rgba(31, 42, 51, 0.06);
    font-size: 22px;
}

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

.tile {
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    border-radius: 10px;
    background: rgba(31, 42, 51, 0.05);
}

.tile b {
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

.tile span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.2;
}

.tile--warn {
    background: rgba(217, 83, 79, 0.1);
}

.tile--warn b {
    color: var(--bad);
}

.jobs__wrap {
    overflow-x: auto;
}

.jobs {
    width: 100%;
    margin-top: 4px;
    border-collapse: collapse;
    font-size: 13px;
}

.jobs th {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-align: left;
}

.jobs td,
.jobs th {
    padding: 3px 2px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.jobs__num {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.jobs__row--open td:nth-child(2) {
    color: var(--good);
    font-weight: 600;
}

.jobs__tag {
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 6px;
    background: rgba(227, 155, 59, 0.2);
    font-size: 10px;
}

.jobs__btn {
    min-width: 24px;
    margin-left: 3px;
    padding: 1px 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.jobs__btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.hint {
    margin: 6px 0;
    color: var(--muted);
    font-size: 12px;
}

.god {
    max-height: 62vh;
    overflow: auto;
}

.god__subtitle {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.button--small {
    padding: 4px 8px;
    font-size: 12px;
}

/* ------------------------------------------------------------- статистика */

.stats {
    position: fixed;
    top: 72px;
    left: 50%;
    z-index: 4;
    width: min(980px, calc(100vw - 32px));
    max-height: calc(100vh - 120px);
    overflow: auto;
    transform: translateX(-50%);
}

.stats__head {
    position: relative;
}

.stats__charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
}

.stats__columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px 18px;
    margin: 12px 0;
}

.stats__title {
    margin: 0 0 6px;
    font-size: 13px;
}

.chart {
    margin: 0;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(31, 42, 51, 0.04);
}

.chart__head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
}

.chart__legend {
    display: flex;
    gap: 8px;
    font-size: 11px;
}

.chart__svg {
    display: block;
    width: 100%;
    height: auto;
}

.chart__day {
    stroke: rgba(31, 42, 51, 0.12);
    stroke-width: 1;
}

.chart__scale {
    fill: var(--muted);
    font-size: 9px;
}

.chart__foot {
    color: var(--muted);
    font-size: 10px;
}

.hbar {
    display: grid;
    grid-template-columns: minmax(90px, 40%) 1fr auto;
    align-items: center;
    gap: 8px;
    margin: 3px 0;
    font-size: 12px;
}

.hbar__label {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.hbar__track {
    height: 8px;
    border-radius: 4px;
    background: var(--line);
    overflow: hidden;
}

.hbar__fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.hbar__value {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- прочее */

.toast {
    position: fixed;
    left: 50%;
    top: 90px;
    transform: translateX(-50%);
    padding: 10px 16px;
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 13px;
    z-index: 5;
}

.footnote {
    position: fixed;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 253, 247, 0.7);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.link {
    border: 0;
    padding: 0;
    background: none;
    color: var(--ink);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/*
 * Телефон: город на весь экран, от интерфейса остаются шапка и карточка
 * выбранного жителя снизу. Списки жителей и событий на узком экране закрыли бы
 * остров целиком — жителя здесь выбирают тапом по карте.
 */
@media (max-width: 860px) {
    .hud {
        top: 8px;
        left: 8px;
        right: 8px;
        gap: 6px;
    }

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

    .hud__speed {
        margin-left: 0;
    }

    .side--left > .panel:not(.god),
    .side--right .panel--grow {
        display: none;
    }

    /* Богу панель нужна и на телефоне — сверху, под шапкой */
    .side--left {
        top: 96px;
        left: 8px;
        right: 8px;
        bottom: auto;
        width: auto;
    }

    .side--right {
        top: auto;
        left: 8px;
        right: 8px;
        bottom: 36px;
        width: auto;
    }

    .citizen {
        max-height: 55vh;
        overflow: auto;
    }
}
