/* Nephelie - minimal glass UI over bright cartoon art */

:root {
  --font: ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", "Nunito", Roboto, system-ui, sans-serif;
  --ink: #1d1d1f;
  --ink-2: #5d5d66;
  --ink-3: #8e8e98;
  --glass: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(255, 255, 255, 0.8);
  --glass-line: rgba(255, 255, 255, 0.85);
  --glass-shadow: 0 10px 30px rgba(30, 40, 80, 0.16), 0 1px 2px rgba(30, 40, 80, 0.08);
  --blue: #0a84ff;
  --green: #30c25a;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffcc00;
  --pink: #ff5c9a;
  --purple: #a259ff;
  --coin: #ffc93c;
  --btn: clamp(54px, 7vmin, 72px);
  --gap: clamp(10px, 1.6vmin, 18px);
  --radius: 22px;
  --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; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html, body {
  margin: 0; width: 100%; height: 100%; height: 100dvh; overflow: hidden;
  background: #bfe7ff;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
input { font-family: inherit; }

#app { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; overflow: hidden; }
.scene { position: absolute; inset: 0; overflow: hidden; }
.scene > svg.stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#defs-root { position: absolute; width: 0; height: 0; overflow: hidden; }

/* -------------------------------------------------- glass */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}
.glass-strong {
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  backdrop-filter: blur(28px) saturate(190%);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

/* -------------------------------------------------- HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
#hud > div { position: absolute; display: flex; gap: var(--gap); align-items: center; pointer-events: none; }
#hud > div > * { pointer-events: auto; }
.hud-tl { top: calc(var(--gap) + var(--safe-t)); left: calc(var(--gap) + var(--safe-l)); }
.hud-tc { top: calc(var(--gap) + var(--safe-t)); left: 50%; transform: translateX(-50%); }
.hud-tr { top: calc(var(--gap) + var(--safe-t)); right: calc(var(--gap) + var(--safe-r)); }
.hud-bl { bottom: calc(var(--gap) + var(--safe-b)); left: calc(var(--gap) + var(--safe-l)); }
.hud-br { bottom: calc(var(--gap) + var(--safe-b)); right: calc(var(--gap) + var(--safe-r)); }

.hud-btn {
  width: var(--btn); height: var(--btn); border-radius: 50%;
  display: grid; place-items: center; padding: 0;
  transition: transform .18s cubic-bezier(.3, 1.6, .5, 1), background .2s;
}
.hud-btn:active { transform: scale(.88); }
.hud-btn .ico { width: 46%; height: 46%; }
.hud-btn.active { background: rgba(10, 132, 255, 0.92); color: #fff; border-color: rgba(255, 255, 255, .6); }
.hud-build { color: var(--blue); }
.hud-build.active { animation: glow 1.8s ease-in-out infinite; }
.hud-btn.muted { color: var(--ink-3); }
.hud-btn.attn { animation: attn 1.6s ease-in-out infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(10, 132, 255, .45), var(--glass-shadow); } 50% { box-shadow: 0 0 0 10px rgba(10, 132, 255, 0), var(--glass-shadow); } }
@keyframes attn { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.title-pill {
  height: calc(var(--btn) * .78); padding: 0 22px; border-radius: 999px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: clamp(16px, 2.4vmin, 22px); letter-spacing: -.01em; white-space: nowrap;
}
.title-pill .ico { color: var(--ink-2); }
.room-dots { display: flex; gap: 6px; margin-left: 4px; }
.room-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(0, 0, 0, .16); }
.room-dots i.on { background: var(--blue); }

.coin-pill {
  height: var(--btn); padding: 0 20px 0 8px; border-radius: 999px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: clamp(18px, 2.8vmin, 26px); font-variant-numeric: tabular-nums;
}
.coin-pill:active { transform: scale(.94); }
.coin-pill.bump { animation: bump .45s cubic-bezier(.3, 1.8, .5, 1); }
.coin-pill.dip { animation: dip .35s ease; }
@keyframes bump { 40% { transform: scale(1.14); } }
@keyframes dip { 40% { transform: scale(.92); } }
.coin-dot {
  display: inline-grid; place-items: center; border-radius: 50%;
  width: 20px; height: 20px; background: linear-gradient(160deg, #ffe27a, #ffb21e); color: #8a5a00;
  box-shadow: inset 0 -2px 0 rgba(160, 90, 0, .25);
}
.coin-dot.big { width: calc(var(--btn) * .7); height: calc(var(--btn) * .7); }
.coin-dot.big .ico { width: 62%; height: 62%; }
.fly-coin {
  position: fixed; z-index: 90; pointer-events: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; background: linear-gradient(160deg, #ffe27a, #ffb21e); color: #8a5a00;
  box-shadow: 0 4px 10px rgba(160, 100, 0, .3);
}
.price { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.price .coin-dot { width: 18px; height: 18px; }
.price.free { color: var(--green); }

/* -------------------------------------------------- pills & buttons */
.pill-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 999px; border: 0;
  font-size: 17px; font-weight: 700; letter-spacing: -.01em;
  background: rgba(255, 255, 255, .85); color: var(--ink);
  box-shadow: 0 4px 14px rgba(30, 40, 80, .12), inset 0 0 0 1px rgba(0, 0, 0, .05);
  transition: transform .16s cubic-bezier(.3, 1.6, .5, 1), background .2s, opacity .2s;
}
.pill-btn:active { transform: scale(.94); }
.pill-btn.primary { background: var(--blue); color: #fff; }
.pill-btn.green { background: var(--green); color: #fff; }
.pill-btn.danger { background: var(--red); color: #fff; }
.pill-btn.ghost { background: rgba(0, 0, 0, .06); box-shadow: none; }
.pill-btn.big { min-height: 64px; padding: 0 32px; font-size: 21px; }
.pill-btn[disabled] { opacity: .45; pointer-events: none; }

/* -------------------------------------------------- modals */
#overlay { position: absolute; inset: 0; z-index: 40; pointer-events: none; }
.modal-back {
  position: absolute; inset: 0; pointer-events: auto; display: grid; place-items: center;
  background: rgba(20, 30, 60, .18);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .22s ease;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
}
.modal-back.in { opacity: 1; }
.modal {
  width: min(880px, 96vw); max-height: min(92vh, 900px); max-height: min(92dvh, 900px); border-radius: 30px;
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(18px) scale(.97); transition: transform .3s cubic-bezier(.2, 1.3, .4, 1);
}
.modal-back.in .modal { transform: none; }
.modal-back.out .modal { transform: translateY(10px) scale(.98); }
.modal.small { width: min(460px, 94vw); }
.modal.wide { width: min(1100px, 97vw); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 18px 8px 24px; min-height: 72px; }
.modal-title { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 800; letter-spacing: -.02em; flex: 1; }
.modal-title .ico { color: var(--ink-2); }
.modal-x {
  width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .06); flex: none; margin-left: auto;
}
.modal-x:active { transform: scale(.9); }
.modal-body { padding: 8px 24px 24px; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }

.dialog { display: flex; flex-direction: column; gap: 18px; }
.dialog-text { margin: 0; font-size: 18px; line-height: 1.4; color: var(--ink-2); }
.dialog-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.text-input {
  width: 100%; height: 58px; border-radius: 16px; border: 0; padding: 0 18px; font-size: 20px; font-weight: 600;
  background: rgba(0, 0, 0, .05); outline: none; color: var(--ink); -webkit-user-select: text; user-select: text;
}
.text-input:focus { box-shadow: 0 0 0 3px rgba(10, 132, 255, .35); }

/* -------------------------------------------------- toasts + status */
#toasts { position: absolute; z-index: 60; top: calc(var(--btn) + var(--gap) * 2 + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; width: min(640px, 92vw); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 18px; border-radius: 22px;
  font-size: 17px; font-weight: 600; line-height: 1.3;
  opacity: 0; transform: translateY(-10px) scale(.97); transition: opacity .25s, transform .3s cubic-bezier(.2, 1.4, .4, 1);
}
.toast.in { opacity: 1; transform: none; }
.toast > .ico { flex: none; color: var(--blue); }
.toast.good > .ico { color: var(--green); }
.toast.warn > .ico { color: var(--orange); }
.toast-act {
  margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px;
  border: 0; border-radius: 999px; background: var(--blue); color: #fff; font-size: 15px; font-weight: 700;
}
.status {
  position: absolute; z-index: 70; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translate(-50%, 20px);
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--ink-2);
  opacity: 0; transition: opacity .25s, transform .3s; pointer-events: none;
}
.status.show { opacity: 1; transform: translate(-50%, 0); }
.status.warn { color: #b25e00; }
.status-bar { width: 46px; height: 5px; border-radius: 5px; background: rgba(0, 0, 0, .1); overflow: hidden; }
.status-bar i { display: block; height: 100%; width: 40%; border-radius: 5px; background: var(--blue); animation: slide 0.9s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

/* -------------------------------------------------- fade + boot */
#fade { position: absolute; inset: 0; z-index: 80; pointer-events: none; background: #f3f8ff; opacity: 0; transition: opacity .23s ease; }
#fade.on { opacity: 1; pointer-events: auto; }
#boot {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: linear-gradient(180deg, #a9e2ff, #e8f7ff);
  transition: opacity .4s ease;
}
#boot.done { opacity: 0; pointer-events: none; }
.boot-card { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 28px 36px; border-radius: 28px; max-width: 560px; text-align: center; }
.boot-title { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.boot-text { font-size: 16px; color: var(--ink-2); line-height: 1.45; }
.boot-text code { background: rgba(0, 0, 0, .06); padding: 2px 6px; border-radius: 6px; font-size: 14px; }
.boot-bar { width: 220px; height: 8px; border-radius: 8px; background: rgba(0, 0, 0, .08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: var(--blue); border-radius: 8px; transition: width .3s ease; }

#rotate-hint {
  position: fixed; inset: 0; z-index: 95; display: none; place-items: center; background: rgba(191, 231, 255, .92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
#rotate-hint .boot-card .ico { width: 64px; height: 64px; color: var(--blue); animation: tilt 2s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (pointer: coarse) {
  body:not(.portrait-ok) #rotate-hint { display: grid; }
}

/* -------------------------------------------------- SVG art helpers */
.tap { cursor: pointer; }
.tap:hover { filter: brightness(1.04); }
.bob { animation: bob 2.6s ease-in-out infinite; }
.blink { transform-box: fill-box; transform-origin: center; animation: blink 4.2s infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(.1); } }
.sway { transform-box: fill-box; transform-origin: 50% 100%; animation: sway 4s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-1.4deg); } 50% { transform: rotate(1.4deg); } }
.twinkle { transform-box: fill-box; transform-origin: center; animation: twinkle 1.6s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .2; transform: scale(.5); } 50% { opacity: 1; transform: scale(1.1); } }
.float { animation: floaty 3.4s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
.cloud { animation: drift linear infinite; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(var(--drift, 600px)); } }
.jump { animation: jump .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-36px) scaleY(1.04); } 70% { transform: translateY(0) scaleY(.94); } }
.popin { transform-box: fill-box; transform-origin: 50% 100%; animation: popin .4s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes popin { 0% { transform: scale(.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.wiggle { transform-box: fill-box; transform-origin: 50% 0%; animation: wiggle .8s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.swimbob { animation: swimbob 2s ease-in-out infinite; }
@keyframes swimbob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }
.spin { transform-box: fill-box; transform-origin: center; animation: spinr 6s linear infinite; }
@keyframes spinr { to { transform: rotate(360deg); } }
.fish { animation: fish 7s ease-in-out infinite alternate; }
@keyframes fish { from { transform: translateX(0); } to { transform: translateX(var(--swim, 80px)); } }
.recdot { animation: rec 1.2s steps(2) infinite; }
@keyframes rec { 50% { opacity: 0; } }
.pulse { transform-box: fill-box; transform-origin: center; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.25); opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  .bob, .sway, .twinkle, .float, .cloud, .wiggle, .swimbob, .spin, .fish, .pulse { animation: none !important; }
}
.wave-arm { transform-origin: 25px -118px; animation: wave 9s ease-in-out infinite; }
@keyframes wave {
  0%, 84%, 100% { transform: rotate(0deg); }
  87% { transform: rotate(-142deg); }
  90% { transform: rotate(-112deg); }
  93% { transform: rotate(-142deg); }
  96% { transform: rotate(-112deg); }
}
@media (prefers-reduced-motion: reduce) { .wave-arm { animation: none !important; } }
