:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6b655c;
  --line: #e2ddd4;
  --accent: #d9822b;
  --accent-text: #ffffff;
  --cool: #2f7d6d;
  --warn: #c0392b;
  --track: #ebe6dd;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 24px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --surface: #1e1c18;
    --text: #ece7de;
    --muted: #9c958a;
    --line: #34312b;
    --accent: #e8964a;
    --accent-text: #1a1206;
    --cool: #5fb8a3;
    --warn: #ef6b5b;
    --track: #2b2924;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); letter-spacing: -.01em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }

#app { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.stack > * + * { margin-top: 16px; }

button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { border: none; background: none; padding: 0; color: var(--muted); text-decoration: underline; }

input[type="text"] {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; }

/* ----- Главная ----- */
.hero { text-align: center; padding: 40px 0 24px; }
.hero p { max-width: 620px; margin: 0 auto 1em; color: var(--muted); font-size: 1.1rem; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 760px; margin: 0 auto; }
.rules { max-width: 760px; margin: 24px auto 0; }
.rules li { margin-bottom: 6px; }

/* ----- Лобби ----- */
.room-code { font-family: ui-monospace, Consolas, monospace; font-size: 2.4rem; letter-spacing: .2em; font-weight: 700; }
.players { list-style: none; padding: 0; margin: 0; }
.players li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.players li:last-child { border-bottom: none; }
.players .grow { flex: 1; min-width: 0; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--track); color: var(--muted); white-space: nowrap; }
.tag.ready { background: color-mix(in srgb, var(--cool) 20%, transparent); color: var(--cool); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ----- Игра ----- */
.topbar { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: flex-end; margin-bottom: 20px; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.thermo { flex: 1; min-width: 240px; }
.thermo-bar { position: relative; height: 12px; border-radius: 99px; background: var(--track); overflow: visible; margin-top: 8px; }
.thermo-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--cool), var(--accent), var(--warn)); transition: width .6s; }
.thermo-mark { position: absolute; top: -4px; width: 2px; height: 20px; background: var(--text); opacity: .5; }
.thermo-mark span { position: absolute; top: 22px; left: 50%; transform: translateX(-50%); font-size: .7rem; color: var(--muted); white-space: nowrap; }

.game-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }

.choice-value { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 12px 0 4px; }
.scale { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }
.preview { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.preview div { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.preview b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; }

.log { max-height: 340px; overflow-y: auto; }
.log-entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.log-entry:last-child { border-bottom: none; }
.log-entry .year { font-weight: 700; }

.chat-list { max-height: 200px; overflow-y: auto; font-size: .9rem; margin-bottom: 8px; }
.chat-list p { margin: 0 0 6px; }
.chat-form { display: flex; gap: 8px; }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 160px) 1fr 40px; gap: 8px; align-items: center; font-size: .875rem; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar-row.you .name { font-weight: 700; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .dot { fill: var(--accent); }
.chart .danger { stroke: var(--warn); stroke-dasharray: 4 4; }
.chart .safe { stroke: var(--cool); stroke-dasharray: 4 4; }

/* ----- Финал ----- */
.verdict { text-align: center; padding: 24px 0; }
.verdict.collapse h1 { color: var(--warn); }
.verdict.survived h1 { color: var(--cool); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; color: var(--muted); font-weight: 500; }
td.r, th.r { text-align: right; }

/* ----- Аккаунт, режимы, рейтинг ----- */
.small-hero { padding: 16px 0 20px; }
.small-hero h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
.narrow { max-width: 440px; margin: 0 auto; }
.row.nowrap { flex-wrap: nowrap; }
code { font-family: ui-monospace, Consolas, monospace; background: var(--track); padding: 2px 6px; border-radius: 6px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.kpis div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.kpis b { display: block; font-size: 1.3rem; }
.mode-pick { display: grid; gap: 8px; }
.mode-card { display: grid; gap: 2px; text-align: left; padding: 12px 14px; }
.mode-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
tr.me td { font-weight: 700; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; flex: none; vertical-align: baseline; }
.rules-list { margin: 0; padding-left: 20px; }
.rules-list li { margin-bottom: 6px; }

/* ----- Озеро ----- */
.lake-card { padding: 12px; }
.lake-host { width: 100%; border-radius: 10px; overflow: hidden; line-height: 0; }
.lake-host canvas { width: 100%; display: block; }
.event { display: flex; gap: 12px; align-items: flex-start; background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.event-icon { font-size: 1.6rem; line-height: 1; }
.thermo-fill.fish { background: linear-gradient(90deg, var(--warn), var(--accent), var(--cool)); }
.chart .line.fish { stroke: var(--cool); }
.chart .dot.fish { fill: var(--cool); }
.stars { font-size: 2rem; color: var(--accent); letter-spacing: .1em; margin-bottom: 8px; }

/* ----- Экран партии: всё в одном окне ----- */
body.playing #app { max-width: 1440px; padding: 0; }
.play {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 12px 16px;
}
.play-head { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.play-stats { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 24px; flex: 1; min-width: 0; }
.play .stat .value { font-size: 1.3rem; }
.play .thermo { min-width: 200px; padding-bottom: 16px; }
.play-main { min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.lake-host.fill { position: relative; flex: 1; min-height: 0; }
.lake-host.fill canvas { position: absolute; inset: 0; width: 100%; height: 100% !important; }
.play-side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.panel-title { font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel table { font-size: .875rem; }
.panel th, .panel td { padding: 6px 4px; }
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 8px; }

.picker { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.pick {
  padding: 10px 0; border-radius: 8px; border: 2px solid transparent;
  font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text);
}
.pick.safe { background: color-mix(in srgb, var(--cool) 24%, var(--surface)); }
.pick.risky { background: color-mix(in srgb, #e0a020 30%, var(--surface)); }
.pick.deadly { background: color-mix(in srgb, var(--warn) 28%, var(--surface)); }
.pick:hover { border-color: var(--muted); }
.pick.sel { border-color: var(--text); background: var(--text); color: var(--bg); }
.legend { margin-top: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 3px 0 6px; }
.dot:first-child { margin-left: 0; }
.dot.safe { background: var(--cool); }
.dot.risky { background: #e0a020; }
.dot.deadly { background: var(--warn); }
.safe-text { color: var(--cool); }
.risky-text { color: #c98a10; }
.deadly-text { color: var(--warn); }
.accent { color: var(--accent); }
.preview-line { margin-top: 8px; min-height: 2.8em; }
.waiting { margin-top: 4px; }
.play .event { margin: 0; }
.last { margin: 0; padding: 0 4px; }

.players-compact { display: grid; gap: 4px; }
.pc { display: grid; grid-template-columns: auto 1fr auto 18px; align-items: center; gap: 6px; font-size: .875rem; }
.pc .swatch { margin: 0; }
.pc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc.you .pc-name { font-weight: 700; }
.pc-ready { color: var(--cool); text-align: center; }

/* Чей ход: при одновременных ходах важно одно — ждут ли вас */
.turn { padding: 6px 14px; border-radius: 99px; font-weight: 700; white-space: nowrap; }
.turn.mine { background: var(--accent); color: var(--accent-text); animation: turnPulse 1.4s ease-in-out infinite; }
.turn.wait { background: var(--track); color: var(--muted); }
@keyframes turnPulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent); } }
.panel.your-turn { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }

/* Итог хода поверх сцены */
.play-main { position: relative; }
.turn-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 28px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  pointer-events: none; animation: bannerLife 3.5s ease forwards;
}
.b-title { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.b-big { font-family: Georgia, "Times New Roman", serif; font-size: 2.6rem; font-weight: 700; line-height: 1.1; }
.b-big small { font-size: 1.2rem; }
.b-line { font-weight: 600; }
@keyframes bannerLife {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.96); }
  10%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%); }
}
@media (prefers-reduced-motion: reduce) {
  .turn.mine { animation: none; }
  .turn-banner { animation-name: bannerFade; }
  @keyframes bannerFade { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }
}

/* Поделиться */
.share-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.share-btns .btn, .share-btns button { padding: 6px 12px; font-size: .875rem; text-decoration: none; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.ad-slot { min-height: 120px; }
.ad-slot > .small { margin-bottom: 6px; }

.verdict-inline b { font-family: Georgia, "Times New Roman", serif; font-size: 1.6rem; }
.verdict-inline.collapse b { color: var(--warn); }
.verdict-inline.survived b { color: var(--cool); }
.verdict-inline .stars { font-size: 1.4rem; margin: 0 0 0 10px; }

.climate-main { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.climate-main p { margin: 0; }
.big-temp { font-size: clamp(2.6rem, 7vw, 4.5rem); font-weight: 700; line-height: 1; }
.climate-main .chart { min-height: 0; }
.climate-main .chart svg { max-height: 55vh; }

/* ----- Главная ----- */
.landing { padding-top: 8px; }
.land-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.kicker { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; color: var(--muted); }
.kicker b { color: var(--text); font-family: Georgia, "Times New Roman", serif; font-size: 1rem; }
.land-hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 32px; align-items: start; }
.hero-title { font-size: clamp(2.4rem, 6.5vw, 4.6rem); line-height: 1.02; letter-spacing: -.02em; margin: 0 0 18px; }
.accent-word { color: var(--accent); }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0 16px; }
.counters div { border-top: 2px solid var(--line); padding-top: 8px; }
.counters b { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 2rem; line-height: 1.1; }
.counters span { font-size: .8rem; color: var(--muted); }
.feed { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.feed li { padding: 4px 0 4px 14px; position: relative; }
.feed li::before { content: ""; position: absolute; left: 0; top: .75em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.feed li:first-child::before { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .feed li:first-child::before { animation: none; } }

.start { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 16px; }
.seg { display: flex; gap: 4px; background: var(--track); padding: 4px; border-radius: 12px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px 10px; font-size: .9rem; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.mode-tagline { margin: 0; }
button.big { width: 100%; padding: 14px 16px; font-size: 1.05rem; }
.way { margin: -4px 0 6px; }
.solo { align-self: center; margin-top: 4px; }

.land-section { margin-top: 48px; }
.land-section > p { max-width: 70ch; }
.memo-grid, .cases { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.memo { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 4px; color: inherit; text-decoration: none; }
a.memo:hover { border-color: var(--muted); }
.memo-img { width: 100%; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: 8px; margin-bottom: 6px; }
.memo-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }

/* Страница истории /s/<id> */
.story-page { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }
.story-page h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 16px 0 8px; }
.story-img { width: 100%; height: auto; border-radius: 12px; margin: 8px 0 16px; border: 1px solid var(--line); }
.story-cta { display: block; margin-top: 20px; }
.case { border-top: 2px solid var(--line); padding-top: 10px; }
.case-icon { font-size: 1.6rem; }
.case p { margin: 6px 0 0; }
.land-foot { margin: 48px 0 0; border-top: 1px solid var(--line); padding-top: 16px; max-width: 80ch; }

.waiting-room { padding-top: 24px; }
.big-count { font-family: Georgia, "Times New Roman", serif; font-size: 3rem; font-weight: 700; line-height: 1; }
.big-count span { font-size: 1.4rem; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  .home-grid, .game-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }

  .play {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(200px, 1fr) auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .thermo-mark.opt span, .legend-tail { display: none; }
  .players-compact { grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .play .event { padding: 8px 10px; gap: 8px; font-size: .85rem; }
  .play .event .small { font-size: inherit; }
  .event-icon { font-size: 1.2rem; }
  .preview-line { min-height: 0; }
  .play-stats { gap: 2px 16px; }
  .play .stat .label { font-size: .7rem; }
  .play .stat .value { font-size: 1.05rem; }
  .play .thermo { min-width: 0; flex-basis: 100%; }
  .play-side { max-height: 56dvh; gap: 8px; }
  .lake-caption { display: none; }
  .panel { padding: 10px; }
  .picker { gap: 3px; }
  .pick { padding: 9px 0; font-size: .9rem; }
  .legend { font-size: .75rem; }
  .verdict-inline b { font-size: 1.25rem; }
  .climate-main p, .climate-main .chart { display: none; }
  .room-code { font-size: 1.8rem; }

  .land-hero { grid-template-columns: 1fr; gap: 20px; }
  .counters { grid-template-columns: repeat(2, 1fr); }
  .seg { flex-direction: column; }
}
