:root {
  --ink: #f7f4ee;
  --muted: rgba(247, 244, 238, 0.62);
  --glass: rgba(14, 18, 40, 0.34);
  --glass-strong: rgba(14, 18, 40, 0.62);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #ffd76a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --sans: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #111a3d; color: var(--ink);
  font-family: var(--sans); -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
canvas#sky { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#ui { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: calc(18px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.screen > * { pointer-events: auto; }
.hidden:not(.screen):not(#hud) { display: none !important; }
.screen.hidden, #hud.hidden { opacity: 0; transform: translateY(8px); visibility: hidden; transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s; }
.screen.hidden * { pointer-events: none !important; }
.reduced .screen, .reduced .screen.hidden, .reduced #hud { transition: none; transform: none; }

/* Title */
#scr-title { justify-content: space-between; }
#scr-title > .title-wrap { pointer-events: none; margin-top: 9vh; text-align: center; }
.logo {
  font-family: var(--serif); font-style: italic; font-weight: 400; margin: 0;
  font-size: clamp(56px, 17vw, 120px); letter-spacing: 0.02em; line-height: 1;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.18);
  animation: rise 1.4s cubic-bezier(.2, .7, .2, 1) both;
}
.tag { margin: 10px 0 0; color: var(--muted); font-size: 15px; letter-spacing: 0.06em; animation: rise 1.4s 0.15s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.menu { display: flex; flex-direction: column; gap: 12px; width: min(360px, 100%); animation: rise 1.2s 0.3s cubic-bezier(.2, .7, .2, 1) both; }
.title-foot { display: flex; align-items: center; justify-content: space-between; width: min(360px, 100%); }
.whisper { color: var(--muted); font-size: 12px; letter-spacing: 0.25em; text-transform: uppercase; pointer-events: none; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  backdrop-filter: blur(12px) saturate(1.2); -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-radius: 18px; padding: 15px 20px; font: 600 18px var(--sans); letter-spacing: 0.01em;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.btn small { font-weight: 500; font-size: 13px; color: var(--muted); }
.btn:active { transform: scale(0.97); }
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn.primary { background: rgba(255, 246, 225, 0.92); color: #1a1f35; border-color: transparent; }
.btn.primary small { color: rgba(26, 31, 53, 0.6); }
.btn.primary:hover { background: #fff; }
.btn.small { padding: 11px 16px; font-size: 15px; justify-content: center; }
.btn:focus-visible, .icon-btn:focus-visible, .burst:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  font-size: 26px; line-height: 1; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.icon-btn:active { transform: scale(0.94); }
.link { appearance: none; background: none; border: 0; color: var(--muted); font: 500 14px var(--sans); padding: 10px; cursor: pointer; }
.link.danger { color: #ffb3a4; }

/* Bars & panels */
.bar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; width: min(560px, 100%); gap: 12px; }
.bar h2 { margin: 0; text-align: center; font: italic 400 28px var(--serif); }
.stars-total { font-size: 14px; color: var(--gold); min-width: 44px; text-align: right; }
.panel {
  margin-top: 18px; width: min(460px, 100%); background: var(--glass-strong); border: 1px solid var(--line);
  border-radius: 22px; padding: 8px 18px 14px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  overflow-y: auto; max-height: calc(100% - 70px);
}
.toggle, .field { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 16px; cursor: pointer; }
.field { flex-direction: column; align-items: stretch; gap: 10px; cursor: default; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 46px; height: 28px; border-radius: 14px; background: rgba(255, 255, 255, 0.18); position: relative; transition: background 0.2s; flex: none; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.toggle input:checked + i { background: #7fc8a9; }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--gold); outline-offset: 2px; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg button, .skins button {
  appearance: none; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--ink);
  border-radius: 12px; padding: 9px 4px; font: 500 13px var(--sans); cursor: pointer;
}
.seg button.on, .skins button.on { background: rgba(255, 246, 225, 0.92); color: #1a1f35; }
.skins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.skins button { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.skins button[disabled] { opacity: 0.45; cursor: default; }
.skins .sw { display: flex; gap: 3px; }
.skins .sw i { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(120, 120, 140, 0.6); }
.skins small { font-size: 10px; color: inherit; opacity: 0.75; }
.panel .btn { margin: 14px auto 0; }
.credit { color: var(--muted); font-size: 12px; text-align: center; margin: 8px 0 0; }

/* Campaign */
.tabs { display: flex; gap: 6px; margin-top: 18px; background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 4px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.tabs button { appearance: none; border: 0; background: none; color: var(--ink); padding: 9px 16px; border-radius: 12px; font: 600 15px var(--sans); cursor: pointer; display: flex; gap: 6px; align-items: center; }
.tabs button small { color: var(--gold); font-weight: 500; font-size: 12px; }
.tabs button.on { background: rgba(255, 246, 225, 0.92); color: #1a1f35; }
.tabs button.on small { color: #9a6c00; }
.tabs button[disabled] { opacity: 0.4; cursor: default; }
.world-blurb { color: var(--muted); font-size: 14px; margin: 12px 0 14px; text-align: center; min-height: 1.3em; }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: min(560px, 100%); overflow-y: auto; padding-bottom: 10px; }
@media (min-width: 560px) { .levels { grid-template-columns: repeat(5, 1fr); } }
.lvl {
  appearance: none; border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  border-radius: 16px; padding: 12px 10px 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform 0.15s;
  animation: rise 0.6s cubic-bezier(.2, .7, .2, 1) both;
}
.lvl:active { transform: scale(0.96); }
.lvl .n { font: italic 400 24px var(--serif); line-height: 1; }
.lvl .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl .st { font-size: 13px; color: var(--gold); letter-spacing: 2px; }
.lvl .st .off { color: rgba(255, 255, 255, 0.25); }
.lvl.locked { cursor: default; }
.lvl.locked > * { opacity: 0.4; }
.lvl .icons { display: flex; gap: 4px; height: 20px; align-items: center; }
.lvl .icons img { width: 20px; height: 20px; opacity: 0.85; }

/* HUD */
#hud { position: absolute; inset: 0; transition: opacity 0.4s ease, transform 0.4s ease; }
#hud > * { pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: calc(12px + var(--safe-t)); left: 14px; right: 14px; display: grid; grid-template-columns: 44px 1fr 72px; align-items: center; gap: 8px; }
.hud-title { text-align: center; }
#hud-name { font: italic 400 20px var(--serif); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.25); }
.dots { display: flex; justify-content: center; gap: 6px; margin-top: 5px; min-height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.28); transition: background 0.3s, transform 0.3s; }
.dots i.done { background: var(--gold); }
.dots i.cur { background: #fff; transform: scale(1.3); }
.hud-birds { justify-self: end; display: flex; align-items: center; gap: 5px; font: 600 16px var(--sans); font-variant-numeric: tabular-nums; background: var(--glass); border: 1px solid var(--line); padding: 6px 10px; border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.hud-birds.bump { animation: bump 0.4s ease; }
.hud-birds.hurt { animation: hurt 0.4s ease; }
@keyframes bump { 50% { transform: scale(1.15); color: var(--gold); } }
@keyframes hurt { 50% { transform: scale(0.92); color: #ff9a85; } }
.timer { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(240px, 60%); height: 3px; background: rgba(255, 255, 255, 0.18); border-radius: 2px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: #fff; transform-origin: left; }
.timer.low i { background: #ff8f73; }
.hud-score { position: absolute; top: calc(76px + var(--safe-t)); left: 0; right: 0; text-align: center; font: 600 14px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-bottom { position: absolute; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.meter { position: relative; width: min(300px, 62vw); height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.18); overflow: visible; box-shadow: 0 1px 10px rgba(0, 0, 0, 0.12); }
.meter-fill { position: absolute; inset: 0; border-radius: 4px; background: linear-gradient(90deg, #fff7e6, #fff); transform-origin: left; transform: scaleX(0); transition: transform 0.12s linear; }
.meter.hold .meter-fill { background: linear-gradient(90deg, #ffe19a, var(--gold)); box-shadow: 0 0 14px rgba(255, 215, 106, 0.8); }
.meter-goal { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--gold); border-radius: 1px; }
.meter-goal::after { content: ""; position: absolute; left: -3px; top: -4px; border: 4px solid transparent; border-top-color: var(--gold); }
.meter-label { font: 600 14px var(--sans); font-variant-numeric: tabular-nums; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3); }
.muted { color: var(--muted); font-weight: 500; }
.burst {
  position: absolute; right: 16px; bottom: 0; width: 64px; height: 64px; border-radius: 50%; border: 0; padding: 0;
  background: var(--glass); color: var(--ink); cursor: pointer; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.burst svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.burst .ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.15); stroke-width: 2.5; }
.burst .ring { fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 106.8; stroke-dashoffset: 0; }
.burst span { position: relative; font: 600 12px var(--sans); letter-spacing: 0.05em; }
.burst.cool { opacity: 0.6; }
.banner {
  position: absolute; left: 0; right: 0; top: 18%; text-align: center; font: italic 400 clamp(34px, 10vw, 56px) var(--serif);
  opacity: 0; text-shadow: 0 2px 24px rgba(0, 0, 0, 0.25); pointer-events: none;
}
.banner small { display: block; font: 600 12px var(--sans); letter-spacing: 0.3em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; font-style: normal; }
.banner.show { animation: banner 2.2s ease both; }
@keyframes banner { 0% { opacity: 0; transform: translateY(10px); letter-spacing: 0.06em; } 20%, 70% { opacity: 1; transform: none; letter-spacing: 0.02em; } 100% { opacity: 0; transform: translateY(-6px); } }
.reduced .banner.show { animation: bannerR 2.2s linear both; }
@keyframes bannerR { 0%, 100% { opacity: 0; } 15%, 75% { opacity: 1; } }
.hint {
  position: absolute; left: 50%; bottom: calc(104px + var(--safe-b)); transform: translate(-50%, 8px); max-width: min(340px, 86vw);
  text-align: center; background: var(--glass-strong); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.35; opacity: 0; transition: opacity 0.4s, transform 0.4s; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* Modals */
.modal { justify-content: center; background: rgba(8, 10, 24, 0.28); }
.card {
  width: min(380px, 100%); background: var(--glass-strong); border: 1px solid var(--line); border-radius: 26px;
  padding: 24px 20px 18px; display: flex; flex-direction: column; gap: 10px; text-align: center;
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); max-height: 100%; overflow-y: auto;
}
.card h2 { margin: 0 0 6px; font: italic 400 34px var(--serif); }
.card .btn { justify-content: center; }
.card .sub { color: var(--muted); margin: -4px 0 6px; font-size: 14px; }
.big-stars { font-size: 40px; letter-spacing: 6px; color: var(--gold); margin: 2px 0 4px; }
.big-stars span { display: inline-block; animation: pop 0.5s cubic-bezier(.3, 1.6, .5, 1) both; }
.big-stars span.off { color: rgba(255, 255, 255, 0.2); }
@keyframes pop { from { transform: scale(0.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 8px; }
.stats div { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 4px; }
.stats b { display: block; font: 600 18px var(--sans); font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); letter-spacing: 0.05em; }
.share-grid { font-size: 15px; line-height: 1.55; background: rgba(0, 0, 0, 0.18); border-radius: 14px; padding: 10px; white-space: pre; font-family: var(--sans); text-align: left; display: inline-block; margin: 0 auto 6px; }
.criteria { font-size: 12px; color: var(--muted); margin: -2px 0 6px; line-height: 1.5; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; top: calc(16px + var(--safe-t)); transform: translate(-50%, -20px); opacity: 0;
  background: rgba(255, 246, 225, 0.96); color: #1a1f35; padding: 10px 18px; border-radius: 14px; font: 600 14px var(--sans);
  transition: opacity 0.3s, transform 0.3s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; }

@media (max-height: 560px) {
  #scr-title > .title-wrap { margin-top: 2vh; }
  .logo { font-size: 54px; }
  .menu { gap: 8px; }
  .btn { padding: 11px 18px; }
}
