:root {
  --marble: #f4efe4; --marble-2: #e9e1cf; --ink: #2b2620; --quiet: #6f6657; --line: #cfc4ab;
  --aegean: #1f4e79; --aegean-soft: #bcd3e6; --sky: #dfeaf1; --terra: #b4472c; --terra-soft: #e6b7a2;
  --gold: #b8892b; --tile: #f7e7bd; --tile-edge: #c9a96a; --ok: #2f7d4f; --bad: #b4472c;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
html.framed { overflow: hidden; }
html.framed body { height: 100%; overflow: hidden auto; overscroll-behavior: contain; }
body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; background: var(--marble); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h1, h2, h3, .score .p b, .game-score { font-family: Georgia, "Times New Roman", serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: #fffdf8; border-radius: 10px; padding: 9px 12px; min-height: 42px; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--aegean); border-color: var(--aegean); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; padding: 4px 0; min-height: 0; color: var(--aegean); text-decoration: underline; }
#app { flex: 1 0 auto; width: 100%; max-width: 620px; margin: 0 auto; padding: 8px 18px calc(10px + env(safe-area-inset-bottom)); }
/* Рамка-меандр: сверху и снизу в потоке страницы, нижняя видна в конце прокрутки; по бокам всегда на экране. */
body::before, body::after { content: ""; flex: none; height: 12px; opacity: .8; }
body::before { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12'%3E%3Cpath fill='none' stroke='%231f4e79' stroke-width='1.4' d='M0 1H16M13 1V11H3V4H9V8H6'/%3E%3C/svg%3E") repeat-x left top; }
body::after { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12'%3E%3Cpath fill='none' stroke='%231f4e79' stroke-width='1.4' d='M0 11H16M13 11V1H3V8H9V4H6'/%3E%3C/svg%3E") repeat-x left bottom; }
html::before, html::after { content: ""; position: fixed; top: 0; bottom: 0; width: 12px; z-index: 5; pointer-events: none; opacity: .8; background-color: var(--marble); }
html::before { left: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='16'%3E%3Cpath fill='none' stroke='%231f4e79' stroke-width='1.4' d='M1 0V16M1 13H11V3H4V9H8V6'/%3E%3C/svg%3E"); background-repeat: repeat-y; }
html::after { right: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='16'%3E%3Cpath fill='none' stroke='%231f4e79' stroke-width='1.4' d='M11 0V16M11 13H1V3H8V9H4V6'/%3E%3C/svg%3E"); background-repeat: repeat-y; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: .02em; }
.stats { display: flex; gap: 8px; color: var(--quiet); font-size: 14px; flex-wrap: wrap; }
.stats b { color: var(--ink); }
.card { background: #fbf8f0; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(60,45,20,.06); }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.levels button { display: flex; flex-direction: column; gap: 2px; align-items: center; min-width: 0; padding: 9px 4px; }
.levels b { font-size: clamp(12px, 3.8vw, 15px); }
.levels small { color: var(--quiet); font-size: 12px; }
.game-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; width: 100%; text-align: left; margin-bottom: 6px; }
.game-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.game-score { white-space: nowrap; font-size: 18px; }
.tag { font-size: 12px; color: var(--quiet); }
.tag.you { color: var(--terra); font-weight: 700; }
/* Партии: раскрывающиеся блоки по тому, чей ход. */
.games-card { padding: 4px 14px; margin-top: 10px; }
details.games { border-bottom: 1px solid var(--marble-2); }
details.games:last-child { border-bottom: 0; }
details.games summary { display: flex; align-items: center; gap: 8px; padding: 11px 0; cursor: pointer; list-style: none; font-family: Georgia, "Times New Roman", serif; font-size: 17px; font-weight: 700; }
details.games summary::-webkit-details-marker { display: none; }
details.games summary::after { content: ""; margin-left: 2px; width: 7px; height: 7px; border-right: 2px solid var(--quiet); border-bottom: 2px solid var(--quiet); transform: rotate(-45deg); transition: transform .15s; }
details.games[open] summary::after { transform: rotate(45deg); }
details.games .count { margin-left: auto; order: 1; min-width: 26px; text-align: center; padding: 1px 8px; border-radius: 999px; background: var(--marble-2); color: var(--quiet); font: 600 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
details.games summary::after { order: 2; }
details.games .count.hot { background: var(--aegean); color: #fff; }
details.games > .quiet { margin: 0 0 10px; }
details.games .game-row:last-child { margin-bottom: 10px; }
.nav { display: flex; flex-wrap: wrap; gap: 8px; }
.nav button { flex: 1 1 88px; padding: 9px 4px; font-size: 14px; }

.score { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.score .p { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: #fbf8f0; }
.score .p.active { border-color: var(--aegean); box-shadow: inset 0 0 0 1px var(--aegean); }
.score .p b { font-size: 20px; display: block; }
.score .p span { font-size: 12px; color: var(--quiet); }
/* Чей ход и сколько времени: средний акцент, заметнее счета, но спокойнее кнопки «Сходить». */
.turn-status { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 7px 10px; margin-bottom: 8px; border-radius: 8px; border: 1px solid var(--aegean); }
.turn-status .ts-who { font-family: Georgia, "Times New Roman", serif; font-size: 17px; font-weight: 700; }
.turn-status .ts-clock { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.turn-status.mine { background: var(--aegean); color: #fff; }
.turn-status.wait { background: var(--sky); color: var(--ink); }
.turn-status.urgent { border-color: var(--terra); }
.turn-status.urgent .ts-clock { color: var(--terra); background: #fbf8f0; padding: 1px 7px; border-radius: 6px; }

.board-wrap { overflow: hidden; box-sizing: border-box; width: min(100%, 62vh); margin: 0 auto; border: 2px solid var(--ink); border-radius: 4px; background: var(--ink); }
.board-wrap.zoomed { overflow: auto; width: 100%; max-height: 62vh; -webkit-overflow-scrolling: touch; }
.board { display: grid; grid-template-columns: repeat(15, 1fr); gap: 1px; aspect-ratio: 1; width: 100%; container-type: inline-size; }
.board.zoom { width: 170%; }
.cell { background: var(--marble); display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 0; min-height: 0; font-size: 9px; color: rgba(0,0,0,.55); position: relative; aspect-ratio: 1; overflow: hidden; line-height: 1; }
.cell.w3 { background: var(--terra); color: #fff; }
.cell.w2 { background: var(--terra-soft); }
.cell.l3 { background: var(--aegean); color: #fff; }
.cell.l2 { background: var(--aegean-soft); }
.cell.center::after { content: "Ω"; font-size: 13px; color: var(--ink); }
.cell:active { transform: none; }
.tile { background: var(--tile); color: var(--ink); box-shadow: inset 0 -2px 0 var(--tile-edge); display: flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; position: relative; }
.cell .tile { position: absolute; inset: 0; font-size: clamp(12px, 3.6vw, 20px); font-size: clamp(9px, 4.2cqw, 28px); }
.board.zoom .cell .tile { font-size: clamp(18px, 5.6vw, 28px); font-size: clamp(12px, 4.2cqw, 34px); }
.tile sub { position: absolute; right: 1px; bottom: 1px; font-size: .48em; font-weight: 400; line-height: 1; }
.cell .tile.new { background: #ffe58a; box-shadow: inset 0 0 0 2px var(--gold); }
.cell.placed { touch-action: none; }
.cell .tile.new.moving { outline: 3px solid var(--aegean); outline-offset: -1px; z-index: 2; }
.cell .tile.bad { background: #f3c2b4; box-shadow: inset 0 0 0 2px var(--bad); }
.cell .tile.last { box-shadow: inset 0 0 0 2px var(--aegean); }

button.word-ok { color: var(--ok); font-weight: 700; }
button.word-bad { color: var(--bad); font-weight: 700; }
input[type=search] { width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mod-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--marble-2); flex-wrap: wrap; }
.mod-act { margin-left: auto; display: flex; gap: 6px; }
/* Журналы словаря компактные: своя прокрутка, значение в одну строку, полностью по нажатию на слово. */
.mod-list { max-height: 300px; overflow-y: auto; margin-top: 8px; }
.mod-list[hidden] { display: none; }
.mod-list .mod-row { padding: 4px 0; }
.mod-list .mod-mean { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rack { display: flex; gap: 5px; justify-content: center; margin: 10px 0 6px; min-height: 48px; }
.rack button { width: 44px; height: 46px; padding: 0; font-size: 22px; border-radius: 6px; border: 1px solid var(--tile-edge); background: var(--tile); box-shadow: inset 0 -3px 0 var(--tile-edge); font-weight: 700; text-transform: uppercase; position: relative; }
.rack button { touch-action: none; user-select: none; -webkit-user-select: none; }
.cell.target { outline: 3px solid var(--gold); outline-offset: -3px; z-index: 2; }
.ghost { position: fixed; z-index: 60; pointer-events: none; display: flex; align-items: center; justify-content: center; background: var(--tile); border: 1px solid var(--tile-edge); box-shadow: inset 0 -3px 0 var(--tile-edge); border-radius: 6px; font-weight: 700; font-size: 22px; text-transform: uppercase; transform-origin: top left; }
.ghost.drag { width: 52px; height: 54px; font-size: 26px; box-shadow: 0 8px 18px rgba(0,0,0,.35); }
.ghost[hidden] { display: none; }
.rack button sub { position: absolute; right: 3px; bottom: 3px; font-size: 10px; font-weight: 400; }
.rack button.sel { outline: 3px solid var(--aegean); }
.rack button.used { visibility: hidden; }
.preview:empty { display: none; }
.preview { min-height: 36px; font-size: 14px; padding: 6px 8px; border-radius: 8px; background: #fbf8f0; border: 1px solid var(--line); margin-bottom: 8px; }
.preview .ok { color: var(--ok); font-weight: 700; }
.preview .bad { color: var(--bad); font-weight: 700; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.actions button { padding: 8px 4px; font-size: 14px; }
.actions .main { grid-column: 1 / -1; min-height: 50px; font-size: 17px; }
.minor { display: flex; justify-content: center; gap: 22px; margin: 4px 0 12px; }
.minor button.link { font-size: 14px; color: var(--quiet); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand img { border-radius: 14px; flex: none; box-shadow: 0 2px 6px rgba(31,78,121,.3); }
.brand h1 { font-size: 24px; margin: 0 0 4px; }
.chip { background: var(--marble-2); border-radius: 999px; padding: 2px 10px; font-size: 13px; color: var(--quiet); }
.chip b { color: var(--ink); margin-left: 2px; }
/* После партии: одна кнопка на всю ширину, две поровну. */
.actions-end { display: flex; gap: 8px; margin-bottom: 6px; }
.actions-end button { flex: 1; min-height: 50px; }
.game .actions-end { order: 7; }
/* Назад всегда слева, как на экране партии. */
.top:has(h1) { flex-direction: row-reverse; justify-content: flex-end; }
.mod-row.solo button { flex: 1; }
.banner { padding: 8px 10px; border-radius: 8px; background: var(--sky); margin-bottom: 8px; font-size: 14px; }
.banner.end { background: var(--marble-2); }
/* Итог партии: выигрыш золотом, проигрыш красным. */
.banner.end b { font-family: Georgia, "Times New Roman", serif; font-size: 18px; }
.banner.end.win { background: #f4dd9b; border: 1px solid var(--gold); color: #4a3608; }
.banner.end.loss { background: #f3c2b4; border: 1px solid var(--terra); color: #5d1e0d; }
.tag .res.win { color: #8a6416; font-weight: 700; }
.tag .res.loss { color: var(--terra); font-weight: 700; }
/* Мешок: той же формы, что значки на главном экране. */
.bag { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; background: var(--marble-2); border-radius: 999px; font-size: 13px; color: var(--quiet); white-space: nowrap; }
.bag svg { color: var(--tile-edge); flex: none; }
.bag b { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 15px; }
.history { font-size: 14px; }
.history div { padding: 3px 0; border-bottom: 1px solid var(--marble-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.bonus { background: var(--gold); color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.history .pts { margin-left: auto; font-weight: 700; }
/* Ход со всеми фишками: цвет строки и бонус над суммой, ширина строки не растет. */
.pts.allin { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.15; vertical-align: middle; }
.pts.allin small { color: #8a6416; font-size: 11px; font-weight: 700; white-space: nowrap; }
.history div.allin-row { background: #f8edcc; box-shadow: inset 3px 0 0 var(--gold); padding: 4px 6px 4px 9px; border-radius: 4px; }
table.weights { border-collapse: collapse; width: 100%; font-size: 14px; }
table.weights td { border-bottom: 1px solid var(--marble-2); padding: 4px 6px; }
tr.me td { font-weight: 700; background: var(--sky); }
ul.rules { padding-left: 20px; margin: 6px 0; }
ul.rules li { margin-bottom: 5px; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; max-width: 90vw; z-index: 50; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal > div { background: var(--marble); border-radius: 12px; padding: 14px; max-width: 460px; width: 100%; max-height: 80vh; overflow: auto; white-space: pre-line; }
.modal h3 { margin: 0 0 8px; }
.modal h3::first-letter { text-transform: uppercase; }
.modal .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.swap { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; white-space: normal; }
.swap button { width: 42px; height: 44px; padding: 0; text-transform: uppercase; font-weight: 700; background: var(--tile); }
.swap button.sel { outline: 3px solid var(--terra); }
.quiet { color: var(--quiet); font-size: 13px; }
.mod-mean { flex-basis: 100%; font-size: 13px; line-height: 1.35; color: var(--ink); margin-top: 2px; }
.mod-mean.quiet { color: var(--quiet); }

/* Экран партии. На телефоне одна колонка: доска под счетом, порядок задан через order. */
.game { display: flex; flex-direction: column; }
.g-side, .g-board { display: contents; }
.game .top { order: 1; } .game .turn-status { order: 1; } .game .score { order: 2; } .game .banner { order: 3; } .game .board-wrap { order: 4; } .game .rack { order: 5; }
.game .preview { order: 6; } .game .actions { order: 7; } .game .minor { order: 8; } .game .history { order: 9; } .game .history ~ .minor { order: 10; }

/* На большом экране и в окне VK две колонки: слева счет, управление и ходы, справа доска на всю высоту окна. */
@media (min-width: 720px) {
  #app:has(.game) { max-width: 1040px; padding-bottom: 12px; }
  .game { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px; align-items: start; }
  .g-side { display: flex; flex-direction: column; min-width: 0; }
  .g-board { display: flex; flex-direction: column; min-width: 0; }
  .game .board-wrap, .game .board-wrap.zoomed { width: min(100%, calc(100vh - 104px)); max-height: none; overflow: hidden; margin: 0 auto; }
  .game .board.zoom { width: 100%; }
  .game [data-zoom] { display: none; }
  .game .top { justify-content: flex-start; }
  .game .top .bag { margin-left: auto; }
  .game .history { max-height: 240px; overflow-y: auto; }
}

/* Вкладки режимов */
.modes { display: flex; gap: 4px; padding: 4px; margin: 0 0 12px; background: var(--marble-2); border-radius: 12px; }
.modes button { flex: 1; border: 0; background: none; min-height: 38px; padding: 6px; font-size: 15px; color: var(--quiet); }
.modes button.on { background: #fffdf8; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(60,45,20,.15); }
.card.note { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; }
.card.note button { flex: none; }
.rack.drop { outline: 2px dashed var(--aegean); outline-offset: 2px; border-radius: 8px; }

/* Магазин и настройки модератора */
.shop { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.shop button { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.shop small { color: var(--quiet); font-size: 12px; }
.set-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; margin-bottom: 12px; }
.set-cols .card { margin: 0; }
.settings input[type=number] { font: inherit; width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); text-align: right; }
.set-flag { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.set-num { display: grid; grid-template-columns: minmax(0, 1fr) 72px; align-items: center; gap: 10px; padding: 3px 0; font-size: 14px; }
.set-pack { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 3px 0; }
.set-pack.head { font-size: 13px; color: var(--quiet); padding: 0; }
.nav button[data-queue-nohints] { flex: 1; }

/* Окна внутри игры: одна ширина, кнопки равного размера */
.modal > div { max-width: 420px; padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.modal .row { gap: 10px; margin-top: 14px; }
.modal .row button { flex: 1 1 120px; min-height: 42px; }
.modal input[type=search] { display: block; }
.modal > div { white-space: normal; }
.modal p { margin: 0 0 8px; }
/* Слово и кнопка в первой строке, дата с комментарием и значение под ними. */
.mod-list .mod-row { row-gap: 2px; }
.mod-list .mod-row > span.quiet { order: 1; flex-basis: 100%; }
.mod-list .mod-mean { order: 2; margin-top: 0; }
.mod-list .mod-act button { min-height: 0; padding: 3px 9px; font-size: 13px; }

/* Страница для тех, кто открыл адрес напрямую */
.explorer { margin-top: 12vh; text-align: center; padding: 26px 20px; }
.explorer img { border-radius: 16px; box-shadow: 0 2px 6px rgba(31,78,121,.3); }
.explorer h1 { font-size: 26px; margin: 14px 0 10px; }
.explorer p { margin: 0 0 10px; }
.explorer-link { display: block; margin-top: 16px; padding: 13px 12px; border-radius: 10px; background: var(--aegean); color: #fff; font-weight: 600; text-decoration: none; }
