/* Lava Puzzle — casual, blocky UI. No rounded corners anywhere. */

:root {
  --bg: #1b1624;
  --panel: #2a2236;
  --panel-edge: #120e18;
  --ink: #f6f1fb;
  --muted: #a99cbb;
  --lava: #f2581c;
  --lava-light: #ffa53c;
  --lava-dark: #b2340f;
  --water: #2e86e6;
  --water-light: #7cc0ff;
  --water-dark: #1b5cad;
  --obsidian: #2a2040;
  --gold: #ffd25e;
}

* {
  box-sizing: border-box;
  border-radius: 0 !important;
  -webkit-tap-highlight-color: transparent;
}

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

button { font-family: inherit; cursor: pointer; }

#app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
  user-select: none;
}

/* ───── chunky block buttons (raised with a hard bottom edge) ───── */

.icon-btn,
.square-btn,
.block-btn {
  border: 0;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 -4px 0 var(--panel-edge), inset 0 2px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.08s;
}
.icon-btn:active:not(:disabled),
.square-btn:active:not(:disabled),
.block-btn:active,
.element-btn:active:not(.empty) { transform: translateY(2px); }
.icon-btn:disabled,
.square-btn:disabled { opacity: 0.3; }

/* ───── header ───── */

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0 8px;
}

h1 {
  margin: 0;
  display: flex;
  flex-direction: column; /* LAVA over PUZZLE: a compact two-line logo */
  font-size: 19px;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
h1 .lava { color: var(--lava); }
h1 .water { color: var(--water); }

.spacer { flex: 1; }

.icon-btn.install {
  background: var(--water);
  box-shadow: inset 0 -4px 0 var(--water-dark), inset 0 2px 0 rgba(255, 255, 255, 0.2);
  animation: nudge 2.4s ease-in-out 1s 3;
}
@keyframes nudge {
  0%, 80%, 100% { transform: none; }
  88% { transform: translateY(-3px); }
}
.rule b { color: var(--ink); }
/* Safari's share icon (a box with an arrow), drawn in CSS */
.ios-share {
  position: relative;
  display: inline-block;
  width: 13px;
  height: 12px;
  margin: 0 5px;
  border: 2px solid var(--water-light);
  border-top: 0;
  vertical-align: -1px;
}
.ios-share::before {
  content: "↑";
  position: absolute;
  left: 50%;
  top: -11px;
  transform: translateX(-50%);
  color: var(--water-light);
  font-size: 14px;
  font-weight: 900;
}
.rule p { text-align: left; }

.icon-btn {
  height: 42px;
  min-width: 42px;
  padding: 0 10px 4px;
  font-size: 18px;
}

#puzzleLabel { min-width: 64px; font-size: 20px; }
.bump { animation: bump 0.45s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ───── energy meter ───── */

#energyRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 10px;
}
.energy-label {
  min-width: 64px;
  font-size: 20px;
  color: var(--gold);
}
.energy-label b {
  display: inline-block;
  margin-left: 2px;
  font-size: 24px;
  color: var(--ink);
}
#energyBar {
  position: relative;
  flex: 1;
  height: 14px;
  background: var(--panel-edge);
  box-shadow: inset 0 0 0 2px var(--panel);
}
#energyFill {
  width: 0;
  height: 100%;
  background: #cfc5dd;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  transition: width 0.5s ease-out;
}
#energyBar .tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  margin-left: -1px;
  background: var(--muted);
}
.energy-best { min-width: 30px; text-align: right; font-size: 16px; font-weight: 800; color: var(--muted); }

/* ───── board ───── */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}
#board {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

#stuck {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 12, 24, 0.2);
  animation: fade-in 0.25s ease-out;
}
#stuck.hidden { display: none; }
.stuck-box {
  padding: 18px 20px 20px;
  background: var(--panel);
  border: 4px solid #e23b3b;
  box-shadow: inset 0 -6px 0 var(--panel-edge), 0 10px 30px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: stuck-in 0.35s ease-out;
}
@keyframes stuck-in {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.06); }
  100% { transform: none; }
}
.stuck-box h2 { margin: 0 0 4px; font-size: 34px; font-weight: 900; color: #ff8a7a; }
#stuckReason { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--muted); }
.stuck-buttons { display: flex; gap: 10px; }
@keyframes fade-in { from { opacity: 0; } }

/* ───── bottom: undo + lava/water ───── */

#picker {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 14px 0 18px;
}

.square-btn {
  width: 56px;
  height: 56px;
  padding-bottom: 4px;
  font-size: 26px;
}
.square-btn.placeholder { visibility: hidden; }

/* lava / water buttons: drawn with plain CSS — flat colour, a few soft bubbles, hard 3D edge */
.element-btn {
  position: relative;
  width: 92px;
  height: 92px;
  border: 0;
  color: #fff;
  font-size: 38px;
  font-weight: 900;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.12s, opacity 0.12s, box-shadow 0.12s;
}
.element-btn.lava {
  background:
    radial-gradient(circle at 24% 28%, var(--lava-light) 0 8px, transparent 9px),
    radial-gradient(circle at 74% 66%, var(--lava-light) 0 11px, transparent 12px),
    radial-gradient(circle at 70% 22%, rgba(255, 210, 120, 0.8) 0 5px, transparent 6px),
    var(--lava);
  box-shadow: inset 0 -7px 0 var(--lava-dark), inset 0 4px 0 rgba(255, 255, 255, 0.25);
}
.element-btn.water {
  background:
    radial-gradient(ellipse at 30% 30%, rgba(255, 255, 255, 0.35) 0 10px, transparent 11px),
    radial-gradient(ellipse at 70% 62%, rgba(255, 255, 255, 0.25) 0 14px, transparent 15px),
    var(--water);
  box-shadow: inset 0 -7px 0 var(--water-dark), inset 0 4px 0 rgba(255, 255, 255, 0.25);
}
.element-btn.selected {
  transform: translateY(-6px);
  outline: 4px solid #fff;
  outline-offset: 3px;
}
.element-btn.empty { opacity: 0.3; }

@media (max-width: 380px) {
  h1 { font-size: 17px; }
  .icon-btn { min-width: 38px; padding: 0 8px 4px; }
  .element-btn { width: 82px; height: 82px; }
  .square-btn { width: 50px; height: 50px; }
}

/* ───── dialogs ───── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 16, 0.7);
  animation: fade-in 0.2s ease-out;
}
.overlay.hidden { display: none; }

.sheet {
  width: 100%;
  max-width: 380px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 22px 20px 18px;
  background: var(--panel);
  box-shadow: inset 0 -8px 0 var(--panel-edge), 0 12px 40px rgba(0, 0, 0, 0.5);
}
.sheet.centered { text-align: center; }
.sheet h2 { margin: 0 0 14px; font-size: 28px; font-weight: 900; letter-spacing: 0.03em; }

.rule {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  font-weight: 800;
  font-size: 18px;
}
.rule p { margin: 0 0 0 6px; font-size: 15px; font-weight: 600; color: var(--muted); }
.big-icon { width: 28px; text-align: center; font-size: 24px; }
.chip { display: inline-block; width: 22px; height: 22px; }
.chip.lava { background: var(--lava); box-shadow: inset 0 -3px 0 var(--lava-dark); }
.chip.water { background: var(--water); box-shadow: inset 0 -3px 0 var(--water-dark); }
.chip.obsidian { background: var(--obsidian); box-shadow: inset 0 -3px 0 #120c1e, inset 0 0 0 1px #4a3a70; }
.chip.empty { background: #a39a8f; box-shadow: inset 0 -3px 0 #6f675e; }
.chip.sm { width: 13px; height: 13px; }
.chip.sm.lava { box-shadow: inset 0 -2px 0 var(--lava-dark); }
.chip.sm.water { box-shadow: inset 0 -2px 0 var(--water-dark); }
/* little block diagrams in front of each rule */
.rule .pic {
  flex: 0 0 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 15px;
  font-weight: 900;
  color: var(--muted);
}
.rule .pic .chip:not(.sm) { width: 18px; height: 18px; }
.rule p { flex: 1; }
.pic .stack { display: flex; flex-direction: column; gap: 3px; }
.pic .stack > span { display: flex; gap: 2px; }
.pic .grid { display: grid; grid-template-columns: repeat(2, 13px); gap: 2px; }
.rule p small { display: block; margin-top: 2px; font-size: 13px; font-weight: 600; color: #7d7190; }

#stars { font-size: 46px; letter-spacing: 6px; color: #4a3f5a; }
#stars .on { color: var(--gold); text-shadow: 0 3px 0 #a87a10; }
#stars .gem { margin-left: 6px; font-size: 40px; }
.score-line { font-size: 22px; color: var(--gold); }
.score-line b { font-size: 34px; color: var(--ink); }
.score-line span { color: var(--muted); font-size: 20px; }
#winText { min-height: 20px; margin: 6px 0 4px; color: var(--gold); font-weight: 800; }
#winPuzzle { margin: 0 0 4px; font-size: 14px; font-weight: 800; letter-spacing: 0.08em; color: var(--muted); }
.share-row { display: flex; gap: 10px; margin-top: 10px; }
.block-btn.share {
  flex: 1;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  font-size: 17px;
  padding: 14px 8px 18px;
  color: #fff;
}
.block-btn.share.x {
  background: #0f0f10;
  box-shadow: inset 0 -5px 0 #000, inset 0 3px 0 rgba(255, 255, 255, 0.12), 0 0 0 2px #3a3048;
}
.block-btn.share.copy {
  background: #4a3f5c;
  box-shadow: inset 0 -5px 0 #241c30, inset 0 3px 0 rgba(255, 255, 255, 0.12);
}
#shareHint { min-height: 18px; margin: 6px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
#shareFallback {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border: 0;
  background: var(--panel-edge);
  color: var(--ink);
  font: 600 14px/1.4 system-ui, sans-serif;
  resize: none;
}
.link-btn.get-app { color: var(--water-light); font-size: 15px; font-weight: 800; }
.win-buttons { display: flex; gap: 10px; margin-top: 10px; }
.win-buttons .block-btn { flex: 1; }
#nextPuzzle { margin-top: 12px; font-size: 15px; color: var(--muted); }
#nextPuzzle b { color: var(--ink); font-size: 17px; }

.block-btn {
  padding: 12px 18px 16px;
  font-size: 17px;
  background: var(--lava);
  box-shadow: inset 0 -5px 0 var(--lava-dark), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}
.block-btn.dark {
  background: #3a3048;
  box-shadow: inset 0 -5px 0 var(--panel-edge), inset 0 3px 0 rgba(255, 255, 255, 0.08);
}
.block-btn.wide { display: block; width: 100%; margin-top: 10px; font-size: 19px; }
.link-btn {
  margin-top: 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

/* ───── stats (top of the Puzzles window) ───── */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 4px 0 10px;
}
.stat-tiles div {
  padding: 8px 2px 10px;
  background: var(--panel-edge);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.stat-tiles b { display: block; font-size: 22px; color: var(--ink); }
.star-bars { margin-bottom: 12px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; font-weight: 800; }
.bar-row .label { width: 42px; color: var(--gold); letter-spacing: 1px; }
.bar-row .bar { flex: 1; height: 12px; background: var(--panel-edge); }
.bar-row .bar i { display: block; height: 100%; background: #cfc5dd; min-width: 2px; }
.bar-row .count { width: 26px; text-align: right; color: var(--ink); }
#winText.practice { color: var(--muted); font-size: 14px; }

/* ───── level select ───── */

.levels-sheet { max-width: 420px; }
.levels-head { display: flex; align-items: baseline; justify-content: space-between; }
.levels-head .total { font-size: 20px; color: var(--gold); font-weight: 900; }
.levels-head .total b { color: var(--ink); }
#levelGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 56dvh;
  overflow-y: auto;
  padding: 4px 2px 8px;
}
/* blocky scrollbar for the level grid: thin dark track, square lava-coloured thumb */
#levelGrid { padding-right: 8px; }
#levelGrid::-webkit-scrollbar { width: 6px; }
#levelGrid::-webkit-scrollbar-track { background: var(--panel-edge); }
#levelGrid::-webkit-scrollbar-thumb { background: var(--lava); }
#levelGrid::-webkit-scrollbar-thumb:active { background: var(--lava-light); }
#levelGrid::-webkit-scrollbar-button { display: none; }
/* browsers without the -webkit- scrollbar styling (Firefox) */
@supports not selector(::-webkit-scrollbar) {
  #levelGrid { scrollbar-width: thin; scrollbar-color: var(--lava) var(--panel-edge); }
}

.level-cell {
  aspect-ratio: 4 / 5;
  border: 0;
  padding: 0 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #3a3048;
  color: var(--ink);
  box-shadow: inset 0 -4px 0 var(--panel-edge), inset 0 2px 0 rgba(255, 255, 255, 0.08);
}
.level-cell:active:not(:disabled) { transform: translateY(2px); }
.level-cell .num { font-size: 20px; font-weight: 900; }
.level-cell .mini-stars { font-size: 11px; letter-spacing: 1px; }
.level-cell .mini-stars i { font-style: normal; color: #5a4e6a; }
.level-cell .mini-stars i.on { color: var(--gold); }
.level-cell .num { font-size: 18px; }
.level-cell .date { font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }
.level-cell.today .date { color: var(--gold); }
.level-cell.current { outline: 3px solid #fff; outline-offset: -3px; }
.level-cell.perfect { background: #2c5a8a; box-shadow: inset 0 -4px 0 #173556, inset 0 2px 0 rgba(255, 255, 255, 0.15); }
.level-cell.perfect .num::after { content: "💎"; font-size: 11px; margin-left: 2px; vertical-align: top; }
.level-cell.locked { opacity: 0.35; }

.hidden { display: none !important; }

/* dialogs opened from another dialog sit on top of it */
#iosInstall,
#help { z-index: 40; }

/* ───── PUZZLES window tabs ───── */
.tabs { display: flex; gap: 6px; }
.tab {
  border: 0;
  padding: 8px 12px 10px;
  background: var(--panel-edge);
  color: var(--muted);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.tab.on { background: var(--lava); color: #fff; box-shadow: inset 0 -4px 0 var(--lava-dark); }
.stat-tiles.hidden, .star-bars.hidden, .share-row.hidden, #nextPuzzle.hidden { display: none; }
#nextPuzzle .block-btn.wide { margin-top: 12px; font-size: 16px; }
.help-more { display: block; margin: 6px 0 2px; color: var(--muted); font-weight: 800; font-size: 15px; text-align: center; }
noscript p { padding: 20px; color: var(--ink); }
noscript a { color: var(--gold); }
