/* style.css — 2048. Brend Terminia (R6) + dnevni/noćni režim (R5) + bez preliva (R14).
   Deca ≤7 (R13): velike pločice (mete ≥44px), malo teksta, dečji režim (životinje). */
:root {
  --brand: #0F6E56; --brand-dark: #085041; --brand-light: #E1F5EE; --accent: #5DCAA5;
  --paper: #EFE9DA; --ink: #2A2622; --muted: #6B6358; --chrome: #F5F2EA; --chip: #D8CFBB;
  --bg: var(--paper); --text: var(--ink); --panel: var(--chrome); --border: var(--ink);
  --border-soft: color-mix(in srgb, var(--ink) 16%, transparent);
  --shadow: rgba(42,38,34,.28);
  --board-bg: #b8ac97;        /* okvir table (neutralno topло) */
  --cell-bg: color-mix(in srgb, var(--board-bg) 78%, #fff 22%);
  --font: 'Instrument Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-play: 'Fredoka', var(--font);
}
:root[data-theme="night"] {
  --paper: #1A1F26; --ink: #D8D1BD; --muted: #8A8473; --chrome: #0A0C10; --chip: #2A3037;
  --shadow: rgba(0,0,0,.5); --border-soft: color-mix(in srgb, var(--ink) 20%, transparent);
  --board-bg: #2A3037; --cell-bg: color-mix(in srgb, var(--board-bg) 72%, #000 28%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* R14: nikad horizontalni preliv */
html, body { margin: 0; height: 100dvh; width: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
body { display: flex; flex-direction: column; user-select: none; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; flex-wrap: wrap; row-gap: 8px;
  background: var(--panel); border-bottom: 1px solid var(--border-soft); flex: 0 0 auto;
}
.back { color: var(--brand); font-weight: 600; text-decoration: none; white-space: nowrap; }
.title { flex: 1; min-width: 0; text-align: center; font-size: 20px; margin: 0; color: var(--ink); font-weight: 800; font-family: var(--font-play); }
.controls { display: flex; align-items: center; gap: 8px; }
.controls select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.btn { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-round { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 18px; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand-dark); font-weight: 800; }
.btn-primary:hover { background: var(--brand-dark); }

.stage { flex: 1 1 auto; display: flex; padding: 12px; min-height: 0; }
.game { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; max-width: 520px; margin: 0 auto; width: 100%; }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; row-gap: 8px; }
.scores { display: flex; gap: 10px; }
.scorebox {
  display: flex; flex-direction: column; align-items: center; min-width: 78px;
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: 12px; padding: 6px 12px;
}
.score-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.score-num { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); font-family: var(--font-play); }
.hud-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 8px; }
.modes { display: inline-flex; border: 1px solid var(--border-soft); border-radius: 10px; overflow: hidden; }
.mode, .size {
  font: inherit; font-weight: 700; font-size: 13px; padding: 9px 12px; cursor: pointer; min-height: 40px;
  background: var(--bg); color: var(--text); border: 0; border-right: 1px solid var(--border-soft);
}
.size { font-variant-numeric: tabular-nums; padding: 9px 10px; }
.mode:last-child, .size:last-child { border-right: 0; }
.mode[aria-pressed="true"], .size[aria-pressed="true"] { background: var(--brand-light); color: var(--brand-dark); }
:root[data-theme="night"] .mode[aria-pressed="true"],
:root[data-theme="night"] .size[aria-pressed="true"] { background: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--accent); }

/* --- Tabla --- */
.board-wrap { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 0; }
.board {
  position: relative; width: min(100%, 78dvh); aspect-ratio: 1 / 1;
  background: var(--board-bg); border-radius: 14px; touch-action: none;
  box-shadow: 0 10px 30px var(--shadow);
  container-type: size; --n: 4; /* --n = broj ćelija po strani (postavlja game.js); font se skalira */
}
.cells, .tiles, .overlay { position: absolute; inset: 0; }
.cell { position: absolute; background: var(--cell-bg); border-radius: 10px; }

.tile {
  position: absolute; display: grid; place-items: center; border-radius: 10px;
  font-family: var(--font-play); font-weight: 800; line-height: 1;
  /* font se skalira po veličini table: 100cqmin = strana table, /n = ćelija */
  font-size: calc(100cqmin / var(--n) * 0.42);
  transition: left .12s ease, top .12s ease; will-change: left, top, transform;
}
.tile.med { font-size: calc(100cqmin / var(--n) * 0.30); }
.tile.big { font-size: calc(100cqmin / var(--n) * 0.23); }
.tile.emoji { font-size: calc(100cqmin / var(--n) * 0.52); background: var(--cell-bg); }
.tile.emoji.med, .tile.emoji.big { font-size: calc(100cqmin / var(--n) * 0.52); }
:root[data-theme="night"] .tile.emoji { background: color-mix(in srgb, var(--cell-bg) 70%, #000); }

@keyframes appear { from { transform: scale(0); } 60% { transform: scale(1.06); } to { transform: scale(1); } }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); } }
.tile.appear { animation: appear .16s ease; }
.tile.pop { animation: pop .16s ease; }

/* Overlay (pobeda / kraj) */
.overlay { display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(2px); border-radius: 14px; padding: 16px; text-align: center; }
.overlay[hidden] { display: none; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: 18px;
  padding: 22px 20px; max-width: 320px; width: 100%; box-shadow: 0 12px 40px var(--shadow);
}
.ov-title { margin: 0 0 6px; font-family: var(--font-play); font-size: 26px; color: var(--brand); }
:root[data-theme="night"] .ov-title { color: var(--accent); }
.ov-text { margin: 0 0 16px; color: var(--muted); font-size: 15px; }
.ov-actions { display: flex; justify-content: center; }
.ov-actions .btn { padding: 12px 24px; }

.footer { display: flex; align-items: center; justify-content: center; min-height: 22px; flex: 0 0 auto; }
.hint { color: var(--brand); font-size: 14px; font-weight: 700; text-align: center; padding: 0 8px; }
:root[data-theme="night"] .hint { color: var(--accent); }

@media (max-width: 420px) {
  .title { font-size: 18px; }
  .scorebox { min-width: 66px; padding: 5px 10px; }
  .score-num { font-size: 19px; }
  .stage { padding: 8px; }
}
