/* ===== Viidoku — тёплое дерево ===== */
:root {
  --cell: 38px;            /* выставляется из JS под размер экрана */
  --mini: 0.55;
  --table-1: #4a3324;
  --table-2: #2e1f15;
  --frame: #6b4528;
  --sand-a: #f1dfbf;
  --sand-b: #e4cca2;
  --ink: #fff4e2;
  --ink-dim: #d9bf9a;
  --accent: #f3c46b;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0; height: 100%; width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed; inset: 0;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 200, 140, .14), transparent 60%),
    repeating-linear-gradient(92deg, rgba(0,0,0,.06) 0 3px, transparent 3px 11px),
    repeating-linear-gradient(88deg, rgba(255,255,255,.025) 0 1px, transparent 1px 23px),
    linear-gradient(180deg, var(--table-1), var(--table-2));
}

button { font: inherit; color: inherit; touch-action: manipulation; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 10px);
}

/* ---------- Шапка ---------- */
.hud {
  width: 100%; max-width: calc(var(--cell) * 9 + 24px);
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; flex: none;
}
.scores { text-align: center; line-height: 1; }
.score {
  font-size: 40px; font-weight: 800; letter-spacing: .5px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
  transition: transform .12s;
}
.score.bump { transform: scale(1.12); }
.best {
  margin-top: 4px; font-size: 15px; font-weight: 700; color: var(--accent);
  display: inline-flex; gap: 5px; align-items: center; font-variant-numeric: tabular-nums;
}
.best svg { width: 16px; height: 16px; fill: var(--accent); }

.icon-btn {
  width: 46px; height: 46px; border: 0; border-radius: 14px; padding: 10px;
  background: linear-gradient(180deg, #8a5a35, #6a4227);
  box-shadow: inset 0 2px 0 rgba(255,230,190,.3), inset 0 -3px 0 rgba(0,0,0,.3), 0 3px 6px rgba(0,0,0,.35);
  cursor: pointer;
}
.icon-btn:active { transform: translateY(1px) scale(.96); }
.icon-btn svg { width: 100%; height: 100%; fill: var(--ink); stroke: var(--ink); stroke-width: 0; }
.icon-btn svg .wave, .icon-btn svg .stroke { fill: none; stroke-width: 2.2; stroke-linecap: round; }
.icon-btn .ico-off { display: none; }
.icon-btn[aria-pressed="false"] .ico-on { display: none; }
.icon-btn[aria-pressed="false"] .ico-off { display: block; }

/* ---------- Поле ---------- */
.play {
  flex: 1; width: 100%; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
}
.board-wrap {
  padding: 7px; border-radius: 16px;
  background:
    repeating-linear-gradient(95deg, rgba(0,0,0,.08) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, #7d5131, var(--frame));
  box-shadow: inset 0 2px 0 rgba(255,220,170,.25), inset 0 -3px 0 rgba(0,0,0,.35), 0 10px 24px rgba(0,0,0,.45);
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  border-radius: 10px; overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(60,30,10,.35);
}
.cell {
  position: relative;
  background: var(--sand-a);
  box-shadow: inset 0 0 0 .5px rgba(120, 80, 40, .16);
}
.cell.z1 {
  background: var(--sand-b);
}
.cell::before { /* лёгкая текстура волокон */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(100deg, rgba(140, 90, 40, .05) 0 1px, transparent 1px 7px);
}
.cell.bl { box-shadow: inset 1.5px 0 0 rgba(110, 70, 35, .35), inset 0 0 0 .5px rgba(120,80,40,.16); }
.cell.bt { box-shadow: inset 0 1.5px 0 rgba(110, 70, 35, .35), inset 0 0 0 .5px rgba(120,80,40,.16); }
.cell.bl.bt { box-shadow: inset 1.5px 0 0 rgba(110,70,35,.35), inset 0 1.5px 0 rgba(110,70,35,.35), inset 0 0 0 .5px rgba(120,80,40,.16); }

/* ---------- Деревянный блок ---------- */
.blk {
  --wood: #9c6435;
  position: absolute; inset: calc(var(--s, var(--cell)) * .045);
  border-radius: calc(var(--s, var(--cell)) * .16);
  background:
    linear-gradient(180deg, rgba(255,240,210,.28) 0%, rgba(255,240,210,0) 38%, rgba(0,0,0,0) 62%, rgba(40,15,0,.18) 100%),
    repeating-linear-gradient(104deg, rgba(60,25,5,.10) 0 1.5px, transparent 1.5px 5px, rgba(255,220,170,.06) 5px 6px, transparent 6px 9px),
    var(--wood);
  box-shadow:
    inset 0 2px 0 rgba(255, 228, 180, .55),
    inset 1.5px 0 0 rgba(255, 228, 180, .18),
    inset -1.5px 0 0 rgba(50, 20, 0, .22),
    inset 0 -3px 0 rgba(50, 20, 0, .38),
    0 2px 3px rgba(50, 25, 5, .35);
}
.blk::after { /* блик */
  content: ""; position: absolute; left: 14%; right: 14%; top: 9%; height: 18%;
  border-radius: 999px; background: linear-gradient(180deg, rgba(255,250,235,.38), rgba(255,250,235,0));
}
.t1 .blk, .blk.t1 { --wood: #9c6435; }
.t2 .blk, .blk.t2 { --wood: #84522c; }
.t3 .blk, .blk.t3 { --wood: #ad7442; }

.cell > .blk { animation: none; }
.cell.pop > .blk { animation: pop .22s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(.82); } to { transform: scale(1); } }

/* Призрак фигуры */
.cell.ghost::after {
  content: ""; position: absolute; inset: calc(var(--cell) * .045);
  border-radius: calc(var(--cell) * .16);
  background: rgba(132, 82, 44, .38);
  box-shadow: inset 0 0 0 2px rgba(110, 66, 30, .35);
}
/* Подсветка линий, которые сгорят */
.cell.hl { background: #f8e7b8; }
.cell.hl.z1 { background: #f2dca6; }
.cell.hl > .blk { filter: brightness(1.18) saturate(1.1); box-shadow:
    inset 0 2px 0 rgba(255,240,200,.7), inset 0 -3px 0 rgba(50,20,0,.3), 0 0 10px 2px rgba(255, 205, 110, .75); }
.cell.hl.ghost::after { background: rgba(170, 110, 50, .55); box-shadow: 0 0 10px 2px rgba(255, 205, 110, .7); }
.board.has-hl .cell.hl { animation: hlpulse .9s ease-in-out infinite alternate; }
@keyframes hlpulse { from { filter: brightness(1); } to { filter: brightness(1.08); } }

/* ---------- Док с фигурами ---------- */
.tray {
  width: 100%; max-width: calc(var(--cell) * 9 + 24px);
  height: calc(var(--cell) * 3.1);
  display: grid; grid-template-columns: repeat(3, 1fr);
  flex: none;
}
.slot {
  position: relative; display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.piece { position: relative; transition: opacity .25s, filter .25s, transform .25s; }
.piece .pc { position: absolute; }
.slot .piece { cursor: grab; }
.slot .piece.dim { opacity: .32; filter: grayscale(.5); }
.slot .piece.hidden { visibility: hidden; }
.slot .piece.enter { animation: enter .35s cubic-bezier(.2,1.4,.5,1) both; }
@keyframes enter { from { transform: translateY(30px) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Слои эффектов ---------- */
.fx-layer, .drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.drag-layer { z-index: 30; }
.drag-piece { position: absolute; left: 0; top: 0; will-change: transform; transform-origin: 50% 50%; }
.drag-piece .pc { position: absolute; }
.drag-piece .blk { box-shadow:
    inset 0 2px 0 rgba(255,228,180,.55), inset 0 -3px 0 rgba(50,20,0,.38), 0 8px 14px rgba(30,12,0,.35); }

.fx-blk { position: absolute; will-change: transform, opacity; }
.chip {
  position: absolute; width: 7px; height: 3px; border-radius: 1px;
  background: #b07a48; will-change: transform, opacity;
}
.chip.dark { background: #7a4a26; }
.chip.light { background: #e0b57e; }

.float-text {
  position: absolute; transform: translate(-50%, -50%);
  white-space: nowrap; font-weight: 900; letter-spacing: .5px;
  color: #fff7e6;
  text-shadow: 0 2px 0 #7a4520, 0 0 2px #7a4520, 0 4px 10px rgba(0,0,0,.45);
  will-change: transform, opacity;
}
.float-text.pts { font-size: 30px; color: #fff3cf; }
.float-text.combo { font-size: 26px; color: #ffd27a; }
.float-text.streak { font-size: 22px; color: #ffb36b; }
.float-text.praise { font-size: 34px; color: #fff; }

/* ---------- Оверлеи ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 20px);
  background: rgba(25, 14, 6, .55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .45s ease;
}
.overlay.show { opacity: 1; }
.overlay[hidden] { display: none; }
.panel {
  width: min(340px, 100%); padding: 24px 22px 22px; border-radius: 22px; text-align: center;
  background:
    repeating-linear-gradient(98deg, rgba(120,70,30,.06) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #f6e6c8, #e8d0a6);
  color: #4a2c16;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.6), inset 0 -4px 0 rgba(120,70,30,.25), 0 20px 50px rgba(0,0,0,.5);
  transform: translateY(16px) scale(.96); transition: transform .45s cubic-bezier(.2,1.3,.4,1);
}
.overlay.show .panel { transform: none; }
.panel-title { font-size: 26px; font-weight: 900; }
.record {
  display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 999px;
  background: #e2a33c; color: #fff; font-weight: 800; font-size: 14px;
  animation: pop .5s cubic-bezier(.3,1.6,.5,1);
}
.record[hidden] { display: none; }
.go-score { font-size: 56px; font-weight: 900; margin: 6px 0 10px; font-variant-numeric: tabular-nums; color: #6b3a17; }
.stats { margin: 0 0 18px; display: grid; gap: 6px; }
.stats > div { display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 10px; background: rgba(120, 70, 30, .1); }
.stats dt { opacity: .8; }
.stats dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }
.muted { opacity: .75; margin: 8px 0 18px; }
.row { display: flex; gap: 10px; }
.row .wood-btn { flex: 1; }
.wood-btn {
  width: 100%; border: 0; border-radius: 14px; padding: 14px 18px;
  font-size: 18px; font-weight: 800; color: #fff6e6; cursor: pointer;
  background: linear-gradient(180deg, #a86a3a, #7d4a25);
  box-shadow: inset 0 2px 0 rgba(255,230,190,.4), inset 0 -4px 0 rgba(0,0,0,.3), 0 4px 10px rgba(60,30,10,.35);
}
.wood-btn.ghost { background: rgba(120,70,30,.15); color: #5a3418; box-shadow: inset 0 0 0 2px rgba(120,70,30,.3); }
.wood-btn:active { transform: translateY(1px) scale(.98); }

@media (prefers-reduced-motion: reduce) {
  .board.has-hl .cell.hl { animation: none; }
}
