/* Summit Peak in the browser: the app's Juicy theme (godot/autoload/themes.gd, web/style.css in the summit repo).
   No web fonts, no third-party requests. Tiles carry dark ink for contrast. */

:root {
  color-scheme: dark;
  --bg: linear-gradient(160deg, #3a1078 0%, #4e31aa 45%, #3795bd 100%);
  --bg-solid: #4e31aa;
  --panel: rgba(255, 255, 255, 0.12);
  --panel-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.82);
  --accent: #ffd23f;
  --danger: #ff4d6d;
  --good: #4cd18a;
  --ink: #1b1030;
  --radius: 24%;
  --font: "Baloo 2", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gap: 8px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: #3a1078; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-solid);
  background: var(--bg) fixed;
  color: var(--text);
  font: 600 1rem/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 8px; z-index: 30; background: var(--accent); color: var(--ink); padding: 8px 12px; border-radius: 10px; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px env(safe-area-inset-bottom);
}

/* ---------- header ---------- */
.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 0 6px;
}
.brand { display: inline-flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; font-weight: 800; }
.brand img { border-radius: 7px; }
.bar h1 { margin: 0; font-size: 1.15rem; font-weight: 800; text-align: center; white-space: nowrap; }
.icon-btn {
  justify-self: end;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  font-size: 1.35rem;
  font-weight: 800;
  cursor: pointer;
}

main { flex: 1; display: flex; flex-direction: column; outline: none; }
.view { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 8px 0 20px; }
.view.center { align-items: center; text-align: center; justify-content: center; }
.view h2 { margin: 0; }
.view p { margin: 0; }
.big { font-size: clamp(1.9rem, 8vw, 2.4rem); line-height: 1.1; font-weight: 800; }
.lead { font-size: 1.08rem; }
.accent { color: var(--accent); font-weight: 800; }
.muted { color: var(--muted); }
.strong { font-weight: 800; font-size: 1.15rem; }
.small { font-size: 0.88rem; }

#v-intro { justify-content: center; text-align: center; }
.howto {
  text-align: left;
  background: var(--panel);
  border-radius: 16px;
  padding: 10px 14px;
}
.howto summary { cursor: pointer; font-weight: 800; padding: 4px 0; }
.rules { margin: 8px 0 4px; padding-left: 1.4em; }
.rules li { margin: 4px 0; }

/* ---------- buttons ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn-big { min-height: 56px; font-size: 1.3rem; }
.btn-ghost { background: var(--panel-strong); color: var(--text); box-shadow: none; }

/* ---------- play ---------- */
.play { gap: 10px; padding-top: 2px; }
.status { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.status .hearts { justify-self: end; }
#play-day { white-space: nowrap; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.clock { font-weight: 800; font-variant-numeric: tabular-nums; }
.hearts { display: inline-flex; gap: 2px; color: var(--danger); font-size: 1.4rem; line-height: 1; }
.heart.lost { color: rgba(255, 255, 255, 0.55); }
.hearts.hit { animation: hit 0.45s; }
@keyframes hit { 25%, 75% { transform: translateX(-5px); } 50% { transform: translateX(5px); } }
.big-hearts { font-size: 2rem; }

.targets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.chip {
  flex: 0 1 52px;
  min-width: 0;
  padding: 3px 2px;
  border-radius: 12px;
  background: var(--panel);
  text-align: center;
  font-weight: 800;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.chip.done { opacity: 0.6; }
.chip.now { background: var(--accent); color: var(--ink); transform: scale(1.08); }

/* The board: columns hang from the top; a tile keeps its place as the ones above it go. Tile size fits both the width
   and the height left over by the other rows, between 34 and 64 px. */
.board-wrap { flex: 1 0 auto; display: flex; justify-content: center; align-items: center; }
.board {
  --t: clamp(34px, min((min(100vw, 480px) - 52px - (var(--cols) - 1) * var(--gap)) / var(--cols),
                       (100vh - 420px - (var(--rows) - 1) * var(--gap)) / var(--rows)), 64px);
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--t));
  grid-auto-rows: var(--t);
  gap: var(--gap);
  padding: 10px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.12);
}
@supports (height: 100dvh) {
  .board {
    --t: clamp(34px, min((min(100vw, 480px) - 52px - (var(--cols) - 1) * var(--gap)) / var(--cols),
                         (100dvh - 420px - (var(--rows) - 1) * var(--gap)) / var(--rows)), 64px);
  }
}
.tile {
  position: relative;
  width: var(--t);
  height: var(--t);
  padding: 2px;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.face {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--ink);
  font-size: calc(var(--t) * 0.52);
  font-weight: 800;
  line-height: 1;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.12s, opacity 0.15s, filter 0.15s;
}
.tile[data-v="1"] { --tile: #ff5d73; }
.tile[data-v="2"] { --tile: #ff9f43; }
.tile[data-v="3"] { --tile: #f7c531; }
.tile[data-v="4"] { --tile: #4cd18a; }
.tile[data-v="5"] { --tile: #2ec4d6; }
.tile[data-v="6"] { --tile: #5b8def; }
.tile[data-v="7"] { --tile: #9b6bff; }
.tile[data-v="8"] { --tile: #f368e0; }
.tile[data-v="9"] { --tile: #ff7eb3; }
.tile.selected .face { transform: scale(0.88); }
.tile.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--accent);
  border-radius: calc(var(--radius) + 3px);
  box-shadow: 0 0 14px var(--accent);
  pointer-events: none;
}
.tile.selected::after {
  content: attr(data-order);
  position: absolute;
  top: -4px;
  right: -4px;
  width: calc(var(--t) * 0.36);
  height: calc(var(--t) * 0.36);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink);
  font-size: calc(var(--t) * 0.22);
  font-weight: 800;
}
.tile.blocked { cursor: not-allowed; }
.tile.blocked .face { opacity: 0.32; filter: grayscale(0.7); }
.tile.blocked.soft .face { opacity: 0.6; filter: none; }
.tile.gone { pointer-events: none; }
.tile.gone .face { animation: pop 0.28s ease-in forwards; }
@keyframes pop { 40% { transform: scale(1.25); } to { transform: scale(0); opacity: 0; } }

.expr-row { min-height: 40px; display: flex; justify-content: center; align-items: center; }
.expr {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 0.28em;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.expr .goal { color: var(--accent); }
.slot { display: inline-block; border: 2px dashed var(--muted); }
.slot.num { width: 0.85em; height: 1em; border-radius: 0.2em; }
.slot.op { width: 0.7em; height: 0.7em; border-radius: 50%; }
.expr.shake { animation: shake 0.35s; color: var(--danger); }
.expr.solved { animation: solved 0.45s ease-out; color: var(--good); }
.expr.solved .goal { color: var(--good); }
@keyframes solved { 0% { transform: scale(0.8); } 50% { transform: scale(1.12); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.ops { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.op {
  position: relative;
  height: 54px;
  border: 3px solid var(--op);
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink);
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  opacity: 0.5;
  touch-action: manipulation;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
}
.op.enabled { opacity: 1; }
.op.empty { border-style: dashed; opacity: 0.35; }
.await-op .op.enabled { box-shadow: 0 0 14px var(--op); animation: op-ready 0.9s ease-in-out infinite alternate; }
@keyframes op-ready { to { transform: translateY(-3px); } }
.op:active { transform: translateY(2px); }
.op-left {
  position: absolute;
  top: -10px;
  right: -8px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--ink);
  border: 2px solid var(--op);
  color: #ffffff;
  font-size: 0.85rem;
  line-height: 20px;
}

.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

/* ---------- end ---------- */
#v-end { gap: 10px; }
#v-end .btn-big { max-width: 360px; }
#end-cta, #error-cta { width: 100%; }
#retry { max-width: 300px; }

.install {
  width: 100%;
  margin-top: 6px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(27, 16, 48, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-align: center;
}
.install img { border-radius: 14px; display: block; margin: 0 auto 6px; }
.install h3 { margin: 0 0 6px; font-size: 1.25rem; }
.install p { margin: 0 0 12px; }
.store-links { display: grid; gap: 10px; }
.btn.store { background: #ffffff; }

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 5px solid var(--panel-strong);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.foot { text-align: center; color: var(--muted); padding: 14px 0 18px; }
.foot a { color: var(--text); }

/* ---------- dialog and toast ---------- */
.dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 20px;
  padding: 20px;
  background: #2c1466;
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog h2 { margin: 0 0 6px; }
.dialog .btn { margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 520px) {
  .view { padding-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
