/* PathSlider - web port
   Palette lifted from the original Godot scenes (see tools/extract_levels.py). */

:root {
  --cream:      #f4edd7;
  --red:        #ff0000;
  --gold:       #ffd500;
  --gold-dim:   #a57c00;
  --blue:       #52b5ff;
  --blue-dim:   #006cbd;
  --green:      #8ae64a;
  --green-dim:  #43a300;
  --ink:        #111111;
  --bg:         #383838;   /* recoloured per level pack at runtime */
  --panel:      #232323;
  --line:       rgba(244, 237, 215, 0.16);
  --hud:        rgba(244, 237, 215, 0.8);

  --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; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--cream);
  font: 500 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* Kill iOS rubber-banding, pinch-zoom and double-tap-to-zoom. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color .35s ease;
}

#safe-probe {
  position: fixed;
  top: 0; left: 0;
  width: 0; height: 0;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ------------------------------------------------------------- screens -- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  pointer-events: none;               /* only controls inside are tappable */
}
.screen[hidden] { display: none; }
.screen > * { pointer-events: auto; }

/* Play screen is a pure overlay on the canvas: only the controls themselves
   take input, so a swipe can start anywhere including over the HUD. */
#scr-play { justify-content: space-between; }
#scr-play > * { pointer-events: none; }
#scr-play button { pointer-events: auto; }

/* ----------------------------------------------------------------- bar -- */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: 56px;
}
.bar-title {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .02em;
}
.footer { margin-top: auto; }
.hud { color: var(--hud); transition: opacity .5s ease; }
.hud.faded { opacity: 0; pointer-events: none; }

.icon-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-family: inherit; font-size: 22px; line-height: 1;
  color: inherit;
  background: rgba(0, 0, 0, .18);
  border: 0; border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { background: rgba(0, 0, 0, .38); transform: scale(.94); }
.icon-btn[disabled] { opacity: .25; pointer-events: none; }

.score-wrap {
  flex: 1;
  display: flex; align-items: baseline; justify-content: center; gap: 10px;
}
.score { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.best  { font-size: 15px; opacity: .75; font-variant-numeric: tabular-nums; }
.level-name { flex: 1; text-align: center; font-size: 15px; font-weight: 600; opacity: .75; }

.tutorial {
  margin: auto auto 4vh;
  padding: 0 24px;
  font-size: 18px;
  text-align: center;
  opacity: .55;
  pointer-events: none;
}

/* -------------------------------------------------------------- title -- */

.title-wrap { margin: auto; text-align: center; padding: 24px; }
.logo { font-size: clamp(38px, 12vw, 68px); font-weight: 800; font-style: italic; letter-spacing: -.02em; }
.logo span { color: var(--gold); }
.logo i { display: inline-block; width: .22em; height: .22em; background: var(--red); margin-left: .1em; vertical-align: baseline; }
.tagline { margin: 10px 0 28px; opacity: .55; }
.title-wrap .btn { display: block; width: 220px; margin: 0 auto; }

/* Attribution to the original author, on the title screen and in settings. */
.credit {
  font-size: 13px;
  line-height: 1.6;
  opacity: .55;
  text-align: center;
  margin-top: 22px;
}
.credit a {
  color: var(--gold);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 213, 0, .4);
  /* Links are the one place inside the no-select shell worth selecting. */
  -webkit-user-select: text;
  user-select: text;
}
.credit a:active { opacity: .7; }
.panel .credit { margin-top: 18px; font-size: 12px; }
.btn.ghost { margin-top: 10px; background: transparent; opacity: .7; }

/* ------------------------------------------------------------- scroll -- */

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;                /* the one place vertical panning is ok */
  padding: 4px 14px 28px;
}

/* --------------------------------------------------------- pack cards -- */

.pack {
  display: block; width: 100%; text-align: left;
  margin: 0 0 12px; padding: 16px 18px;
  background: rgba(0, 0, 0, .22);
  border: 0; border-left: 5px solid var(--cream);
  border-radius: 14px;
  color: inherit; font: inherit; cursor: pointer;
  touch-action: manipulation;
}
.pack:active { transform: scale(.99); background: rgba(0, 0, 0, .34); }
.pack.locked { border-left-color: var(--line); opacity: .55; cursor: default; }
.pack h3 { font-size: 19px; font-weight: 700; }
.pack p { font-size: 14px; opacity: .6; margin-top: 2px; }
.pack .meter { height: 5px; margin-top: 12px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
.pack .meter i { display: block; height: 100%; background: var(--cream); }
.pack .count { float: right; font-size: 14px; opacity: .75; font-variant-numeric: tabular-nums; }
.pack[data-rank="0"] { border-left-color: var(--gold); }
.pack[data-rank="0"] .meter i { background: var(--gold); }
.pack[data-rank="1"] { border-left-color: var(--blue); }
.pack[data-rank="1"] .meter i { background: var(--blue); }

/* --------------------------------------------------------- level grid -- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
}
.cell {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, .2);
  color: var(--cream);
  /* Longhands, not the `font` shorthand: a shorthand cannot take `inherit`
     for one component, and an invalid declaration drops back to the browser's
     tiny default button font. */
  font-family: inherit;
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}
.cell:active { transform: scale(.94); }
.cell[data-rank="0"] { background: var(--gold);  color: var(--ink); border-color: var(--gold); }
.cell[data-rank="1"] { background: var(--blue);  color: #fff;       border-color: var(--blue); }
.cell[data-rank="2"] { background: var(--cream); color: var(--ink); border-color: var(--cream); }

/* ------------------------------------------------------------ overlay -- */

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px)
           calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }

.panel {
  width: 100%; max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.panel h2 { font-size: 20px; margin-bottom: 14px; }
.end-panel { text-align: center; }
.rank { font-size: 26px; font-weight: 800; letter-spacing: .01em; }
.stars { font-size: 26px; letter-spacing: 6px; margin: 6px 0 4px; height: 32px; }
.end-moves { font-size: 14px; opacity: .7; margin-bottom: 18px; }

.row { display: flex; gap: 10px; margin-top: 14px; }
.row .btn { flex: 1; }

.btn {
  padding: 13px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  color: var(--cream);
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1;
  cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.btn.danger  { background: transparent; border-color: rgba(255, 90, 90, .55); color: #ff8080; }
.btn[disabled] { opacity: .3; pointer-events: none; }

.toggle { display: flex; align-items: center; gap: 10px; padding: 9px 0; font-size: 15px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); }

textarea {
  width: 100%; height: 108px; margin-top: 12px; padding: 10px;
  background: #111; color: var(--cream);
  border: 1px solid var(--line); border-radius: 10px;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
  touch-action: auto; user-select: text; -webkit-user-select: text;
}
.hint { font-size: 13px; opacity: .65; margin-top: 8px; min-height: 18px; }
.hint.ok  { color: var(--green); opacity: 1; }
.hint.err { color: #ff8080; opacity: 1; }
.version { text-align: center; opacity: .35; font-size: 11px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 84px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: 80vw;
  padding: 11px 20px; border-radius: 999px;
  background: var(--gold); color: var(--ink);
  font-size: 14px; font-weight: 700; text-align: center;
  pointer-events: none;
  animation: toast-in .3s ease;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
