:root {
  --bg: #0d0b09;
  --panel: #1c1813;
  --text: #f1e6d2;
  --muted: #a8977c;
  --accent: #e0a53a;
  --good: #8fd18a;
  --bad: #f07a6a;
  --warn: #f2c14e;
  --info: #8fc3f0;
  --btn: #2a241c;
  --btn-active: #3d3427;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 8px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--panel);
  border-radius: 10px;
  padding: 5px 9px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.stat .timer { color: var(--accent); font-size: 13px; }
.stat .timer:empty { display: none; }
#btnNew { font-size: 17px; padding: 5px 12px; }

/* ---------- раскладка ---------- */
#main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding-bottom: 12px;
}
#board {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
canvas { display: block; touch-action: none; }

#side {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* ---------- журнал ---------- */
#log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.4;
  user-select: text;
}
.entry { padding: 4px 0; border-bottom: 1px solid #2a241c; color: var(--muted); }
.entry:first-child { color: var(--text); font-size: 15px; }
.entry .t {
  display: inline-block;
  min-width: 26px;
  margin-right: 4px;
  color: #6f6250;
  font-variant-numeric: tabular-nums;
}
.entry .good { color: var(--good); }
.entry .bad { color: var(--bad); }
.entry .warn { color: var(--warn); }
.entry .info { color: var(--info); }
.entry:not(:first-child) span:not(.t) { opacity: .8; }

/* ---------- кнопки ---------- */
button {
  font: inherit;
  color: var(--text);
  background: var(--btn);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
button:active { background: var(--btn-active); }
button:disabled { opacity: .35; cursor: default; }
button.active { outline: 2px solid var(--accent); background: var(--btn-active); }

#controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
}
.dpad button { font-size: 22px; }
.dpad .up    { grid-column: 2; grid-row: 1; }
.dpad .left  { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 3; }

.actions {
  display: grid;
  grid-template-columns: repeat(2, 70px);
  gap: 8px;
}
.actions button {
  height: 64px;
  font-size: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.actions small { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- всплывашка и оверлей ---------- */
#toast {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 24, 19, .95);
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 15px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

#overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .78);
  z-index: 10;
  padding: 16px;
}
#overlay.show { display: flex; }
.panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
  max-width: 460px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
}
.panel h1 { margin: 0 0 10px; color: var(--accent); font-size: 24px; text-align: center; }
.panel p { line-height: 1.45; margin: 8px 0; }
.panel .muted { color: var(--muted); font-size: 14px; }
.help { color: var(--muted); font-size: 14px; padding-left: 18px; line-height: 1.6; margin: 8px 0; }
.ovButtons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
button.big { font-size: 18px; padding: 12px 28px; background: var(--accent); color: #1a1208; font-weight: 600; }
button.ghost { font-size: 16px; padding: 12px 18px; }

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  #app { padding-left: 8px; padding-right: 8px; }
  #main { flex-direction: column; gap: 8px; padding-bottom: 8px; }
  #side { width: auto; flex: none; gap: 8px; }
  #log { flex: none; height: 76px; font-size: 13px; }
  .stat { font-size: 13px; padding: 4px 7px; }
  .dpad { grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); }
  .actions { grid-template-columns: repeat(2, 66px); }
  .actions button { height: 60px; }
}
@media (max-width: 360px) {
  .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
  .actions { grid-template-columns: repeat(2, 58px); }
}

/* ---------- повтор партии ---------- */
[hidden] { display: none !important; }
#btnReplay { color: var(--accent); }
#replayBar {
  background: var(--panel);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#replayCaption { font-size: 14px; min-height: 2.8em; line-height: 1.4; }
#replayCaption b { color: var(--accent); font-variant-numeric: tabular-nums; }
.replayRow { display: flex; align-items: center; gap: 8px; }
.replayRow button { min-width: 44px; height: 40px; font-size: 16px; }
#rpSlider { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* кнопка звука — во всю ширину под «Лук» и «Факел» */
.actions .wide { grid-column: span 2; flex-direction: row; gap: 8px; }
.actions .wide small { font-size: 14px; margin-top: 0; color: var(--text); }

/* «Поделиться повтором» — заметная кнопка во всю ширину панели повтора */
#replayBar .share { height: 44px; font-size: 16px; color: var(--accent); border: 1px solid var(--accent); }
