/* Let It Flow - interface styles. Road-sign palette: highway green, sign white,
   school-bus yellow, asphalt. Layout adapts to phones (portrait and landscape). */
:root {
  --green: #0e5e3a;
  --green-2: #15784a;
  --green-3: #1d8f5a;
  --paper: #f6f4ee;
  --ink: #1b1f22;
  --yellow: #f2c14e;
  --asphalt: rgba(24, 28, 32, 0.84);
  --asphalt-solid: #1c2024;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4f2ec;
  --muted: #a7afb5;
  --danger: #e5484d;
  --ok: #4cc777;
  --gold: #ffcc4d;
  --r: 14px;
  --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);
  --font: 'Overpass', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #24371f;
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
svg { width: 1em; height: 1em; flex: none; }
.hidden { display: none !important; }

#view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; cursor: crosshair; }
body:not(.in-game) #view { cursor: default; }

/* ------------------------------------------------------------------ HUD */
.hud {
  position: fixed; z-index: 5;
  top: calc(var(--safe-t) + 10px); left: calc(var(--safe-l) + 10px);
  right: calc(var(--safe-r) + 10px);
  display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none;
  padding-right: 290px;
}
.hud > * { pointer-events: auto; }
.chip {
  height: 42px; padding: 0 13px; border-radius: 12px;
  display: flex; align-items: center; gap: 7px;
  background: var(--asphalt); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip svg { font-size: 19px; color: var(--muted); }
.icon-btn { width: 42px; justify-content: center; padding: 0; }
.icon-btn svg { color: var(--text); font-size: 22px; }
.title-chip { gap: 9px; }
.lvl-num {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px;
  background: var(--green); color: #fff; border: 2px solid var(--paper); border-radius: 7px; font-size: 13px; font-weight: 900;
}
.clock-chip .ring { width: 24px; height: 24px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.14); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--yellow); stroke-width: 5; stroke-dasharray: 0 94.2; stroke-linecap: round; transition: stroke-dasharray 0.3s; }
.stat.done { background: rgba(26, 110, 64, 0.88); }
.stat.done svg { color: #bff5cf; }
.stat[data-level="1"] span { color: #ffb4a8; }
.stat[data-level="2"] span { color: #fff; }
.stat[data-level="3"] span { color: var(--gold); }
.money svg { color: var(--yellow); }

/* ------------------------------------------------------------------ controls */
.controls {
  position: fixed; z-index: 6;
  top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 10px);
  display: flex; gap: 8px;
}
.ctl {
  min-width: 46px; height: 46px; padding: 0 12px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--asphalt); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); font-weight: 800; font-size: 15px;
  transition: transform 0.12s, background 0.2s;
}
.ctl svg { font-size: 21px; }
.ctl:active { transform: scale(0.94); }
.ctl.on { background: var(--yellow); color: var(--ink); }
.ctl.primary { background: linear-gradient(var(--green-2), var(--green)); border: 2px solid var(--paper); padding: 0 16px; min-width: 112px; }
.ctl.primary.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 193, 78, 0.65); } 50% { box-shadow: 0 0 0 9px rgba(242, 193, 78, 0); } }

/* ------------------------------------------------------------------ toolbar */
.toolbar {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 12px);
  display: flex; gap: 6px; padding: 7px;
  max-width: calc(100vw - 20px - var(--safe-l) - var(--safe-r));
  overflow-x: auto; scrollbar-width: none;
  background: var(--asphalt); border: 1px solid var(--line); border-radius: 20px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  position: relative; flex: none; width: 76px; height: 70px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid transparent; transition: background 0.15s, transform 0.12s;
}
.tool svg { font-size: 27px; margin-bottom: 2px; }
.tool .tl { font-size: 12px; font-weight: 800; line-height: 1; }
.tool .tp { font-size: 10.5px; color: var(--muted); font-weight: 700; line-height: 1.1; }
.tool kbd { position: absolute; top: 4px; right: 6px; font: 700 10px var(--font); color: rgba(255, 255, 255, 0.35); }
.tool:hover { background: rgba(255, 255, 255, 0.07); }
.tool:active { transform: scale(0.95); }
.tool.active { background: linear-gradient(var(--green-2), var(--green)); border-color: var(--paper); }
.tool.active .tp { color: #cdebd8; }
.tool.new::after {
  content: 'NEW'; position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  background: var(--yellow); color: var(--ink); font-size: 9px; font-weight: 900; padding: 1px 5px; border-radius: 5px;
}
.tool-hint {
  position: fixed; z-index: 5; left: 50%; transform: translate(-50%, 8px);
  bottom: calc(var(--safe-b) + 98px); max-width: min(560px, 92vw);
  background: rgba(14, 94, 58, 0.94); border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 8px 14px; border-radius: 12px; font-size: 13.5px; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none;
}
.tool-hint.show { animation: hint 4.2s ease forwards; }
@keyframes hint { 0% { opacity: 0; transform: translate(-50%, 8px); } 8%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 66px); width: min(520px, 92vw);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--asphalt-solid); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: translateY(-8px); transition: opacity 0.3s, transform 0.3s;
}
.toast.show { opacity: 1; transform: none; }
.toast.warn { background: #6d1d20; border-color: #e5484d; }
.toast.hint { background: var(--yellow); color: var(--ink); border: 2px solid var(--ink); font-size: 14.5px; }

/* ------------------------------------------------------------------ popover */
.popover {
  position: fixed; z-index: 25; top: 0; left: 0;
  width: min(320px, calc(100vw - 20px));
  background: var(--asphalt-solid); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 14px 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  font-size: 14px; touch-action: auto;
}
.popover p { margin: 6px 0 8px; color: var(--muted); line-height: 1.4; font-size: 13px; }
.popover p.warn { color: #ffb4a8; }
.popover p.note { font-size: 12px; }
.pop-head { display: flex; align-items: center; gap: 8px; padding-right: 26px; font-size: 16px; }
.pop-head .dot { width: 12px; height: 12px; border-radius: 50%; }
.tag { margin-left: auto; font-size: 11px; font-weight: 800; color: var(--muted); background: rgba(255, 255, 255, 0.08); padding: 2px 8px; border-radius: 8px; white-space: nowrap; }
.pop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin-top: 10px; }
.pop-grid > div { background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 7px 9px; }
.pop-grid small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.pop-grid b { font-size: 16px; font-variant-numeric: tabular-nums; }
.pop-grid b.ok { color: var(--ok); } .pop-grid b.bad { color: #ff8a80; }
.pop-x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; }
.pop-x svg { font-size: 18px; }
.seg { display: flex; gap: 6px; margin: 8px 0 2px; }
.seg button { flex: 1; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, 0.07); font-weight: 800; font-size: 12.5px; }
.seg button.on { background: var(--yellow); color: var(--ink); }
.slider { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 800; color: var(--muted); margin: 6px 0; }
.slider input { flex: 1; accent-color: var(--yellow); height: 28px; }

/* ------------------------------------------------------------------ screens */
.screen {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; touch-action: pan-y;
  background: radial-gradient(ellipse at center, rgba(10, 20, 14, 0.15) 0%, rgba(8, 16, 12, 0.72) 75%);
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 16px);
}
.title-wrap { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 30px; }
.sign {
  position: relative; text-align: center; color: #fff;
  background: linear-gradient(170deg, var(--green-3), var(--green) 70%);
  border: 5px solid var(--paper); outline: 4px solid var(--green);
  border-radius: 22px; padding: 30px clamp(22px, 6vw, 56px) 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.7s cubic-bezier(.2, .9, .3, 1.2) both;
}
.sign h1 { margin: 6px 0 4px; font-size: clamp(46px, 11vw, 96px); line-height: 0.95; font-weight: 900; letter-spacing: -0.02em; }
.sign p { margin: 8px 0 0; font-size: clamp(14px, 3.6vw, 18px); font-weight: 600; opacity: 0.92; }
.sign-route {
  display: inline-block; background: var(--paper); color: var(--green); font-weight: 900; font-size: 12px;
  letter-spacing: 0.14em; padding: 4px 10px; border-radius: 6px;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }
.title-buttons { display: flex; flex-direction: column; gap: 10px; width: min(420px, 100%); animation: rise 0.7s 0.12s both; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row.small .btn { height: 46px; }
.row.small .btn.wide { flex: 2.2; }
.row.small .btn span { white-space: nowrap; font-size: 15px; }
.card > .btn { width: 100%; }
.col { display: flex; flex-direction: column; gap: 10px; }
.btn {
  height: 52px; padding: 0 18px; border-radius: var(--r);
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--asphalt); border: 1px solid var(--line); color: var(--text);
  font-weight: 800; font-size: 16px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s, filter 0.2s;
}
.btn svg { font-size: 21px; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn.big { height: 62px; font-size: 19px; }
.btn.primary { background: linear-gradient(var(--green-2), var(--green)); border: 3px solid var(--paper); color: #fff; }
.btn.ghost { background: rgba(0, 0, 0, 0.25); box-shadow: none; }
.btn.toggle { justify-content: flex-start; }
.btn.toggle i { margin-left: auto; font-style: normal; font-size: 13px; color: var(--muted); }
.btn.toggle.on i { color: var(--yellow); }
.version { font-size: 11px; color: rgba(255, 255, 255, 0.4); font-weight: 700; }

.levels-wrap { max-width: 980px; margin: 0 auto; animation: rise 0.5s both; }
.levels-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.levels-head h2 { margin: 0; font-size: 30px; font-weight: 900; flex: 1; }
.levels-head .btn { height: 44px; }
.total-stars { display: flex; align-items: center; gap: 6px; font-weight: 900; color: var(--gold); background: var(--asphalt); padding: 8px 12px; border-radius: 12px; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.chapter { grid-column: 1 / -1; margin: 10px 2px 0; font-size: 12px; font-weight: 900; letter-spacing: 0.16em; text-transform: uppercase; color: #bfe8cf; }
.level-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 16px; background: var(--asphalt); border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); transition: transform 0.12s, background 0.2s;
}
.level-card:not(.locked):hover { background: rgba(30, 40, 36, 0.92); transform: translateY(-2px); }
.level-card.locked { opacity: 0.55; cursor: not-allowed; }
.shield {
  flex: none; width: 46px; height: 50px; display: grid; place-items: center;
  background: var(--paper); color: var(--ink); font-weight: 900; font-size: 20px;
  clip-path: polygon(50% 0, 100% 14%, 100% 64%, 50% 100%, 0 64%, 0 14%);
}
.shield.alt { background: var(--yellow); }
.shield span { margin-top: -4px; }
.lc-body { flex: 1; min-width: 0; }
.lc-name { font-weight: 900; font-size: 17px; }
.lc-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.lc-stars { display: flex; gap: 2px; font-size: 18px; color: rgba(255, 255, 255, 0.18); }
.lc-stars .on { color: var(--gold); }

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: rgba(6, 12, 9, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  padding: calc(var(--safe-t) + 12px) 12px calc(var(--safe-b) + 12px); touch-action: pan-y;
}
.card {
  width: min(470px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto;
  background: var(--paper); color: var(--ink); border-radius: 20px; padding: 22px 22px 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); animation: rise 0.4s cubic-bezier(.2, .9, .3, 1.2) both;
}
.card h2 { margin: 2px 0 10px; font-size: 32px; font-weight: 900; line-height: 1; }
.card .eyebrow { font-size: 11.5px; font-weight: 900; letter-spacing: 0.16em; text-transform: uppercase; color: var(--green-2); }
.card .blurb { font-size: 15.5px; line-height: 1.45; margin: 4px 0 14px; color: #3a4146; }
.card .btn { background: #e7e3d8; color: var(--ink); border: 0; box-shadow: none; }
.card .btn.primary { background: linear-gradient(var(--green-2), var(--green)); color: #fff; border: 3px solid #fff; outline: 2px solid var(--green); }
.card .btn.ghost { background: transparent; }
.card .btn.toggle i { color: #6b7378; }
.card .btn.toggle.on i { color: var(--green-2); }
.card .row { margin-top: 16px; }
.goals { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 14px; }
.goals > div { display: flex; align-items: center; gap: 10px; font-size: 14.5px; background: #ece8dd; border-radius: 12px; padding: 9px 12px; }
.goals .stars { display: flex; width: 54px; color: #e0a100; font-size: 15px; }
.newtools { margin: 0 0 14px; }
.newtool { display: flex; gap: 12px; align-items: center; background: #fff7dd; border: 2px solid var(--yellow); border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.newtool svg { font-size: 30px; }
.newtool small { display: block; font-size: 12.5px; color: #555c61; line-height: 1.35; }
.budget { display: flex; align-items: center; gap: 6px; font-size: 14px; margin: 0 0 14px; color: #3a4146; }
.budget svg { color: #c48d00; font-size: 18px; }
.starrow { display: flex; justify-content: center; gap: 10px; margin: 6px 0 8px; }
.bigstar { font-size: 58px; color: #d6d1c4; display: grid; }
.bigstar.on { color: var(--gold); animation: starpop 0.5s cubic-bezier(.2, 1.4, .4, 1) both; filter: drop-shadow(0 4px 6px rgba(160, 110, 0, 0.35)); }
@keyframes starpop { from { transform: scale(0.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
.card .pop-grid > div { background: #ece8dd; }
.card .pop-grid small { color: #6b7378; }
.card.end h2 { text-align: center; }
.card.end .eyebrow, .card.end .blurb { text-align: center; }
.help p { font-size: 14.5px; line-height: 1.5; margin: 0 0 10px; color: #30363a; }
.help .keys { font-size: 13px; color: #555c61; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 20px; }

/* ------------------------------------------------------------------ phones */
@media (max-width: 760px) {
  .hud { gap: 6px; padding-right: 64px; }
  .chip { height: 36px; padding: 0 10px; font-size: 13.5px; gap: 5px; border-radius: 11px; }
  .chip svg { font-size: 16px; }
  .icon-btn { width: 36px; }
  .title-chip #hud-name { display: none; }
  .clock-chip .ring { width: 20px; height: 20px; }
  .controls { flex-direction: column; top: calc(var(--safe-t) + 10px); }
  .ctl { min-width: 48px; height: 48px; padding: 0; }
  .ctl.primary { min-width: 48px; padding: 0; }
  .ctl span { display: none; }
  #btn-speed span { display: inline; position: absolute; bottom: 2px; right: 5px; font-size: 10px; }
  #btn-speed { position: relative; }
  .toolbar { left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); transform: none; max-width: none; justify-content: flex-start; bottom: calc(var(--safe-b) + 8px); padding: 6px; gap: 4px; border-radius: 18px; }
  .tool { width: 66px; height: 64px; }
  .tool svg { font-size: 25px; }
  .tool .tl { font-size: 11px; }
  .tool-hint { bottom: calc(var(--safe-b) + 86px); font-size: 12.5px; }
  .toasts { top: calc(var(--safe-t) + 92px); }
  .card { padding: 18px 16px 16px; border-radius: 18px; }
  .card h2 { font-size: 27px; }
  .bigstar { font-size: 48px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .chip { height: 32px; font-size: 13px; }
  .hud { top: calc(var(--safe-t) + 6px); }
  .controls { top: calc(var(--safe-t) + 6px); flex-direction: row; }
  .ctl { height: 40px; min-width: 40px; }
  .toolbar { bottom: calc(var(--safe-b) + 6px); }
  .tool { width: 60px; height: 52px; }
  .tool .tp { display: none; }
  .tool svg { font-size: 22px; }
  .tool-hint { bottom: calc(var(--safe-b) + 66px); }
  .title-wrap { flex-direction: row; gap: 24px; }
  .sign h1 { font-size: 52px; }
}
@media (pointer: coarse) { .tool kbd { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
