:root {
  --cream: #F8F5EC;
  --paper: #FFFDF7;
  --ink: #24464D;
  --muted: #6b7f83;
  --teal: #5BA4AD;
  --teal-dark: #2F6E7A;
  --pink: #F08CA8;
  --pink-light: #F6B8C3;
  --magenta: #A8467F;
  --gold: #D9A441;
  --line: #2F6E7A;
  --bs: min(calc(100vh - 24px), calc(100vw - 400px));
}
@media (max-width: 900px) { :root { --bs: calc(100vw - 12px); } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--cream); color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- кнопки ---------- */
.btn {
  border: 1.5px solid var(--teal); background: #fff; color: var(--teal-dark);
  border-radius: 10px; padding: 9px 14px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: #EEF6F7; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--teal-dark); color: #fff; border-color: var(--teal-dark); }
.btn.primary:hover { background: #255a64; }
.btn.accent { background: var(--magenta); color: #fff; border-color: var(--magenta); }
.btn.accent:hover { background: #8f3a6b; }
.btn.big { font-size: 18px; padding: 13px 22px; width: 100%; margin-top: 16px; }
.btn.small { font-size: 13px; padding: 6px 10px; }
.btn:disabled { opacity: .4; cursor: default; }

/* ---------- экран настройки ---------- */
#setup { display: flex; justify-content: center; padding: 20px 10px; }
.setup-card {
  background: var(--paper); border-radius: 16px; padding: 22px 20px; width: 100%; max-width: 520px;
  box-shadow: 0 10px 40px rgba(47,110,122,.18); text-align: center;
}
.setup-emblem { width: 120px; mix-blend-mode: multiply; border-radius: 50%; }
.setup-card h1 { font-family: Georgia, serif; color: var(--teal-dark); letter-spacing: 3px; margin: 4px 0 0; font-size: 40px; font-weight: 400; }
.setup-sub { color: var(--magenta); font-size: 14px; margin-bottom: 8px; }
.setup-card h2 { font-size: 16px; text-align: left; margin: 18px 0 8px; color: var(--teal-dark); }
.setup-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; text-align: left; flex-wrap: wrap; }
.setup-row.check { font-size: 14px; flex-wrap: nowrap; align-items: flex-start; }
.setup-row.check input { margin-top: 3px; }
.setup-row select { font-size: 15px; padding: 5px; border-radius: 8px; border: 1px solid #c9d6d8; }
.pl-row { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.pl-row input[type=text] {
  flex: 1; min-width: 0; font-size: 16px; padding: 8px 10px; border-radius: 8px; border: 1px solid #c9d6d8;
}
.pl-token { font-size: 22px; width: 42px; height: 42px; border-radius: 50%; border: 2px solid; background: #fff; cursor: pointer; flex: none; }
.pl-bot { font-size: 13px; display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.pl-del { border: 0; background: none; font-size: 20px; color: #9ab; cursor: pointer; }
.resume-box { background: #EAF5F6; border-radius: 10px; padding: 10px; margin: 10px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; }
.howto { text-align: left; margin-top: 16px; font-size: 14px; line-height: 1.5; color: #3c5a60; }
.howto summary { cursor: pointer; font-weight: 600; color: var(--teal-dark); }

/* ---------- раскладка игры ---------- */
.layout { display: flex; gap: 12px; padding: 12px; align-items: flex-start; justify-content: center; }
.panel {
  width: 370px; flex: none; display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100vh - 24px); overflow: auto;
}
@media (max-width: 900px) {
  .layout { flex-direction: column; padding: 6px; align-items: stretch; }
  .panel { width: 100%; max-height: none; }
  .turn-box { order: -1; }
}

/* ---------- поле ---------- */
.board {
  --u: calc(var(--bs) / 10.6);
  width: var(--bs); height: var(--bs);
  display: grid;
  grid-template-columns: 1.8fr repeat(7, 1fr) 1.8fr;
  grid-template-rows: 1.8fr repeat(7, 1fr) 1.8fr;
  background: var(--line); gap: 2px; padding: 2px; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(47,110,122,.25);
  margin: 0 auto; user-select: none;
}
.cell {
  background: var(--paper); display: flex; position: relative; overflow: hidden;
  font-size: calc(var(--u) * 0.135); line-height: 1.15; cursor: pointer;
}
.cell:hover { filter: brightness(.96); }
.cell .band { flex: 0 0 20%; position: relative; }
.cell .body {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; padding: 2px; gap: 1px; min-width: 0;
}
.bottom { flex-direction: column; }
.top    { flex-direction: column-reverse; }
.left   { flex-direction: row-reverse; }
.right  { flex-direction: row; }
.left .band, .right .band { flex-basis: 16%; }
.name { font-weight: 600; overflow-wrap: normal; }
.price { color: var(--muted); font-size: .92em; }
.icon { font-size: 1.8em; line-height: 1; }
.sub { font-style: italic; color: var(--magenta); font-size: .88em; }
.city { font-size: .7em; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; filter: brightness(.75); }
.what { font-size: .78em; color: var(--muted); font-style: italic; }
.special .body { background: #F3F8F8; }
.card-belem .body { background: #EAF5F6; }
.card-yazmysh .body { background: #FCEFF3; }
.corner { font-size: calc(var(--u) * 0.16); }
.corner .icon { font-size: 2.2em; }
.corner .name { font-size: 1.12em; }
.corner .hint { font-size: .78em; color: var(--muted); padding: 0 5px; }
.c-start { background: #E3F1F2; }
.c-saban { background: #FDE6EC; }

/* владение и постройки */
.owner-mark {
  position: absolute; display: flex; align-items: center; justify-content: center;
  width: calc(var(--u)*0.3); height: calc(var(--u)*0.3); border-radius: 50%;
  font-size: calc(var(--u)*0.17); background: #fff; border: 2px solid; z-index: 2;
}
.bottom .owner-mark { top: 2px; left: 2px; }
.top .owner-mark { bottom: 2px; left: 2px; }
.left .owner-mark { right: 2px; top: 2px; }
.right .owner-mark { left: 2px; top: 2px; }
.builds { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 1px; font-size: calc(var(--u)*0.16); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.left .builds, .right .builds { flex-direction: column; }
.cell.mortgaged .body { opacity: .35; }
.cell.mortgaged::after {
  content: 'в залоге'; position: absolute; inset: auto 0 35% 0; text-align: center;
  font-size: calc(var(--u)*0.13); color: var(--magenta); font-weight: 700; transform: rotate(-12deg);
}
.cell.hl { box-shadow: inset 0 0 0 3px var(--gold); }

/* фишки */
.tokens { position: absolute; inset: 0; display: flex; flex-wrap: wrap; align-content: flex-end; justify-content: center; gap: 1px; padding: 2px; pointer-events: none; z-index: 3; }
.token {
  width: calc(var(--u)*0.4); height: calc(var(--u)*0.4); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: calc(var(--u)*0.24);
  background: #fff; border: 2.5px solid; box-shadow: 0 2px 5px rgba(0,0,0,.25);
}
.token.active { animation: bob 1s infinite ease-in-out; }
@keyframes bob { 50% { transform: translateY(-3px); } }

/* центр поля */
.center {
  grid-column: 2 / 9; grid-row: 2 / 9;
  background: radial-gradient(circle at 50% 42%, #fff 0, var(--paper) 55%, #F3EEE0 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative;
}
.center-emblem { width: 26%; mix-blend-mode: multiply; border-radius: 50%; }
.title { font-family: Georgia, "Times New Roman", serif; font-size: calc(var(--u)*0.8); color: var(--teal-dark); letter-spacing: 2px; line-height: 1; }
.subtitle { font-size: calc(var(--u)*0.18); color: var(--magenta); letter-spacing: 1px; }
.dice { display: flex; gap: calc(var(--u)*0.15); margin-top: calc(var(--u)*0.12); }
.die {
  width: calc(var(--u)*0.75); height: calc(var(--u)*0.75); background: #fff; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: calc(var(--u)*0.75); line-height: 1;
  color: var(--teal-dark); box-shadow: 0 3px 10px rgba(47,110,122,.25);
}
.dice.rolling .die { animation: shake .12s infinite; }
@keyframes shake { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
.center-msg { margin-top: calc(var(--u)*0.12); font-size: calc(var(--u)*0.17); color: var(--teal-dark); text-align: center; min-height: 1.4em; padding: 0 10%; }
.orn { position: absolute; width: 16%; opacity: .5; }
.orn.a { right: 5%; top: 5%; }
.orn.b { left: 5%; bottom: 5%; transform: rotate(180deg); }

/* справка о клетке */
.info {
  position: absolute; left: 6%; right: 6%; top: 50%; transform: translateY(-50%);
  background: #fff; border-radius: 12px; border-top: 8px solid var(--teal);
  box-shadow: 0 12px 40px rgba(36,70,77,.28);
  padding: calc(var(--u)*0.25) calc(var(--u)*0.3);
  display: none; flex-direction: column; gap: calc(var(--u)*0.06); z-index: 6; text-align: left;
}
.info.show { display: flex; }
.info .x { position: absolute; top: 4px; right: 8px; border: 0; background: none; font-size: calc(var(--u)*0.4); color: #8aa0a4; cursor: pointer; line-height: 1; }
.i-city { font-size: calc(var(--u)*0.15); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; filter: brightness(.75); }
.i-name { font-family: Georgia, serif; font-size: calc(var(--u)*0.34); color: var(--teal-dark); line-height: 1.1; }
.i-what { font-size: calc(var(--u)*0.16); color: var(--magenta); font-style: italic; }
.i-text { font-size: calc(var(--u)*0.18); line-height: 1.45; }
.i-rent { font-size: calc(var(--u)*0.15); color: var(--muted); border-top: 1px solid #e3ecee; padding-top: 4px; margin-top: 2px; }
@media (max-width: 900px) {
  .info { position: fixed; left: 8px; right: 8px; top: auto; bottom: 8px; transform: none; max-height: 60vh; overflow: auto; padding: 12px 14px; z-index: 40; }
  .i-text { font-size: 14px; } .i-name { font-size: 19px; } .i-city, .i-what, .i-rent { font-size: 12px; }
  .info .x { font-size: 26px; }
}

/* ---------- панель ---------- */
.round { font-size: 14px; color: var(--muted); text-align: center; }
.pcard {
  background: var(--paper); border-radius: 12px; padding: 8px 10px; display: flex; gap: 10px; align-items: center;
  border: 2px solid transparent; box-shadow: 0 2px 8px rgba(47,110,122,.1); margin-bottom: 6px;
}
.pcard.active { border-color: var(--gold); box-shadow: 0 2px 12px rgba(217,164,65,.35); }
.pcard.out { opacity: .4; }
.pcard .tk { font-size: 22px; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 2.5px solid; background: #fff; flex: none; }
.pcard .pn { font-weight: 700; font-size: 15px; }
.pcard .ps { font-size: 13px; color: var(--muted); }
.pcard .money { margin-left: auto; text-align: right; font-size: 15px; font-weight: 700; color: var(--teal-dark); white-space: nowrap; }
.turn-box { background: var(--paper); border-radius: 12px; padding: 12px; box-shadow: 0 2px 8px rgba(47,110,122,.1); display: flex; flex-direction: column; gap: 8px; }
.turn-box .who { font-size: 16px; font-weight: 700; }
.turn-box .row { display: flex; gap: 6px; flex-wrap: wrap; }
.turn-box .row .btn { flex: 1; }
.log { background: var(--paper); border-radius: 12px; padding: 8px 10px; font-size: 13px; line-height: 1.45; max-height: 210px; overflow: auto; color: #3c5a60; }
.log div { border-bottom: 1px dashed #e3ecee; padding: 2px 0; }
.panel-foot { text-align: right; }

/* ---------- окно ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(36,70,77,.45); display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 10px;
}
.modal-card {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  padding: 18px 18px 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); border-top: 8px solid var(--teal);
}
.modal-card h3 { margin: 0 0 4px; font-family: Georgia, serif; font-weight: 400; font-size: 24px; color: var(--teal-dark); }
.modal-card .m-sub { color: var(--magenta); font-size: 14px; margin-bottom: 8px; }
.modal-card p { line-height: 1.5; margin: 8px 0; }
.modal-card .m-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.modal-card .m-actions .btn { flex: 1; min-width: 120px; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.levels .btn { padding: 10px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.levels .btn small { font-weight: 400; font-size: 11px; color: var(--muted); }
.levels .btn:hover small { color: var(--magenta); }
.q-text { font-size: 19px; font-weight: 600; margin: 10px 0 12px; line-height: 1.35; }
.q-opts { display: flex; flex-direction: column; gap: 8px; }
.q-opts .btn { text-align: left; font-weight: 500; font-size: 16px; padding: 12px 14px; }
.q-opts .btn.right { background: #E2F3E6; border-color: #3E9A5C; color: #1f6b3a; }
.q-opts .btn.wrong { background: #FBE3E8; border-color: var(--magenta); color: var(--magenta); }
.q-expl { background: #F3F8F8; border-radius: 10px; padding: 10px 12px; margin-top: 10px; line-height: 1.5; font-size: 15px; }
.q-res { font-size: 18px; font-weight: 700; margin-top: 10px; }
.q-res.ok { color: #2d7d47; } .q-res.bad { color: var(--magenta); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .btn { padding: 4px 12px; }
.prop-list { display: flex; flex-direction: column; gap: 4px; max-height: 230px; overflow: auto; margin: 6px 0; }
.prop-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #F7FAFA; font-size: 14px; }
.prop-item .dot { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.prop-item .pi-name { flex: 1; }
.prop-item .btn { padding: 4px 8px; font-size: 13px; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .trade-cols { grid-template-columns: 1fr; } }
.trade-cols h4 { margin: 6px 0 4px; font-size: 14px; color: var(--teal-dark); }
.trade-cols label.prop-item { cursor: pointer; }
.money-in { width: 100%; font-size: 15px; padding: 6px 8px; border-radius: 8px; border: 1px solid #c9d6d8; }
.results { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.results th, .results td { padding: 6px 4px; border-bottom: 1px solid #e3ecee; text-align: right; }
.results th:first-child, .results td:first-child { text-align: left; }
.results tr.win td { background: #FFF6E0; font-weight: 700; }
.event-card { text-align: center; padding: 6px 0; }
.event-card .ev-icon { font-size: 54px; }
.event-card .ev-text { font-size: 18px; line-height: 1.45; margin-top: 6px; }
.small-note { font-size: 13px; color: var(--muted); }
.q-opts .btn.chosen { background: #EAF5F6; border-color: var(--teal-dark); }
/* заметная кнопка «Строить» */
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.gold:hover { background: #c38f30; }
.build-box { background: #FFF6E0; border: 1.5px solid var(--gold); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; animation: glow 2s infinite ease-in-out; }
.build-box .btn { width: 100%; }
.build-hint { font-size: 13px; color: #7a5a17; line-height: 1.4; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(217,164,65,.25); } }
/* очень узкие экраны: строка игрока переносится, список кругов не шире экрана */
.setup-row select { max-width: 100%; }
@media (max-width: 420px) {
  .pl-row { flex-wrap: wrap; }
  .pl-row input[type=text] { flex: 1 1 150px; }
  .pl-bot { margin-left: 48px; }
}
/* выбор режима сложности */
.modes { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.mode-card { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1.5px solid #d6e3e5; border-radius: 10px; cursor: pointer; background: #fff; font-size: 15px; line-height: 1.35; }
.mode-card input { margin-top: 3px; }
.mode-card.on { border-color: var(--teal-dark); background: #EEF6F7; }

/* ---------- сетевая игра: вход, комнаты, ожидание ---------- */
#s-name, #s-lobby, #s-room { display: flex; justify-content: center; padding: 20px 10px; }
#s-name.hidden, #s-lobby.hidden, #s-room.hidden { display: none; }
.setup-card.wide { max-width: 640px; }
.big-in { font-size: 17px; padding: 10px 12px; }
.token-pick { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pl-token.on { box-shadow: 0 0 0 3px var(--gold); }
.lobby-head { display: flex; align-items: center; gap: 12px; text-align: left; flex-wrap: wrap; }
.lobby-emblem { width: 56px; mix-blend-mode: multiply; border-radius: 50%; }
.lobby-title { font-family: Georgia, serif; font-size: 26px; color: var(--teal-dark); letter-spacing: 2px; }
.lobby-me { margin-left: auto; font-size: 15px; }
.room-list { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.room-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1.5px solid #d6e3e5; border-radius: 10px; background: #fff; }
.ri-main { flex: 1; min-width: 0; }
.create-box { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.err { color: var(--magenta); font-size: 14px; min-height: 1.2em; margin-top: 6px; }
.badge { font-size: 11px; background: var(--gold); color: #fff; border-radius: 6px; padding: 1px 6px; vertical-align: middle; }
.room-pl { text-align: left; }
.room-pl .pl-token { cursor: default; display: inline-flex; align-items: center; justify-content: center; }
.room-pl .pi-name { flex: 1; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
/* рейтинг */
.rating { text-align: left; }
.rating .results td:nth-child(n+3), .rating .results th:nth-child(n+3) { text-align: center; }
/* предупреждение о закрытии комнаты */
.idle-warn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 70; background: #FFF6E0; border: 2px solid var(--gold);
  border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 15px; display: flex; gap: 10px; align-items: center; max-width: 94vw; }
.idle-warn.hidden { display: none; }
@media (max-width: 600px) { .idle-warn { top: auto; bottom: 8px; font-size: 13px; padding: 8px 10px; width: 94vw; justify-content: space-between; } .idle-warn .btn { flex: none; } }
