:root {
  --ink: #1b1424;
  --cream: #fbf1e4;
  --cream-2: rgba(251, 241, 228, 0.72);
  --cream-3: rgba(251, 241, 228, 0.45);
  --amber: #f2b45a;
  --rose: #ef8a7e;
  --sage: #cfe3a6;
  --glass: rgba(24, 17, 34, 0.66);
  --glass-2: rgba(36, 26, 50, 0.72);
  --line: rgba(251, 241, 228, 0.16);
  --display: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --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; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #2a1d33; color: var(--cream);
  font-family: var(--ui); font-size: 15px;
  -webkit-font-smoothing: antialiased;
  touch-action: none; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; cursor: none; }
body:has(.screen.show:not(.low)) #cv { cursor: default; }

.ico { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.22em; flex: none; }
.ico.big { width: 34px; height: 34px; stroke-width: 1.4; }

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(14px + var(--safe-t)) calc(18px + var(--safe-r)) 0 calc(18px + var(--safe-l));
  display: grid; grid-template-columns: 1fr minmax(180px, 360px) 1fr; gap: 16px; align-items: start;
  pointer-events: none; text-shadow: 0 1px 6px rgba(20, 10, 30, 0.45);
}
#hud[hidden] { display: none; }
.hud-l { display: flex; flex-direction: column; gap: 6px; }
.count { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 40px; font-weight: 600; line-height: 1; letter-spacing: 0.01em; }
.count .ico { width: 30px; height: 30px; opacity: 0.9; }
#hCount { display: inline-block; transition: color .3s; }
#hCount.up { animation: pop-up .5s ease-out; }
#hCount.down { animation: pop-down .5s ease-out; }
@keyframes pop-up { 0% { color: var(--amber); transform: scale(1.12); } 100% { color: var(--cream); transform: none; } }
@keyframes pop-down { 0% { color: var(--rose); transform: translateX(-3px); } 50% { transform: translateX(2px); } 100% { color: var(--cream); transform: none; } }
.energy .bar { width: 168px; height: 7px; border-radius: 4px; background: rgba(20, 12, 30, 0.42); box-shadow: inset 0 0 0 1px rgba(251, 241, 228, 0.18); overflow: hidden; }
.energy .bar i { display: block; height: 100%; width: 100%; border-radius: 4px; background: linear-gradient(90deg, #f6d38a, var(--amber)); transition: width .25s linear; }
.energy .bar.low i { background: linear-gradient(90deg, #f6a07a, var(--rose)); animation: blink 1s infinite; }
.energy .bar.empty { box-shadow: inset 0 0 0 1px var(--rose); }
@keyframes blink { 50% { opacity: 0.55; } }
.strays { font-size: 12.5px; color: #ffe7b0; min-height: 16px; letter-spacing: 0.02em; }

.hud-c { display: flex; flex-direction: column; gap: 9px; padding-top: 6px; }
.track { position: relative; height: 14px; }
.track .line { position: absolute; left: 0; right: 0; top: 6px; height: 2px; background: rgba(251, 241, 228, 0.35); border-radius: 2px; }
.track .dot { position: absolute; top: 2px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--cream); box-shadow: 0 0 0 3px rgba(251, 241, 228, 0.22); transition: left .3s linear; }
.track .roost { position: absolute; right: -4px; top: 0; width: 8px; height: 14px; border-radius: 3px 3px 1px 1px; background: rgba(251, 241, 228, 0.65); }
.sunline { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--cream-2); }
.sunbar { position: relative; flex: 1; height: 2px; background: linear-gradient(90deg, rgba(255, 220, 150, 0.55), rgba(255, 130, 90, 0.55) 70%, rgba(80, 70, 140, 0.6)); border-radius: 2px; }
.sunbar i { position: absolute; top: -4px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: #ffd98f; box-shadow: 0 0 10px #ffb860; transition: left .5s linear; }
.sunline.dusk { color: #ffc2a0; }
.sunline.night { color: #b9c0ff; }
.sunline.night .sunbar i { background: #cfd4ff; box-shadow: 0 0 8px #8f9cff; }

.hud-r { display: flex; justify-content: flex-end; align-items: center; gap: 12px; font-size: 14px; color: var(--cream-2); }
.hud-r b { color: var(--cream); font-weight: 600; }
.icon-btn { pointer-events: auto; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(24, 17, 34, 0.35); color: var(--cream); display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); }
.icon-btn:hover { background: rgba(24, 17, 34, 0.6); }

/* ------------------------------------------------------------------ hints / banner / toasts */
.hint {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translate(-50%, 12px);
  max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); color: var(--cream); font-size: 15px; line-height: 1.45; text-align: center;
  opacity: 0; transition: opacity .35s, transform .35s; pointer-events: none;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.hint b { color: var(--amber); font-weight: 600; }

.banner { position: fixed; left: 0; right: 0; top: 24%; text-align: center; pointer-events: none; opacity: 0; text-shadow: 0 2px 18px rgba(20, 10, 30, 0.55); }
.banner.show { animation: banner 4.2s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: translateY(10px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }
.b-day { font-size: 13px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--cream-2); }
.b-title { font-family: var(--display); font-size: clamp(44px, 7vw, 76px); font-weight: 600; line-height: 1.05; margin: 6px 0 8px; }
.b-sub { font-size: 15px; color: var(--cream-2); }

.toasts { position: fixed; right: calc(16px + var(--safe-r)); top: calc(76px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; z-index: 30; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--glass-2); backdrop-filter: blur(10px); border: 1px solid rgba(242, 180, 90, 0.35); font-size: 13px; color: var(--cream-2); animation: toast-in .4s ease; transition: opacity .6s, transform .6s; }
.toast b { display: block; color: var(--cream); font-size: 14.5px; font-weight: 600; }
.toast .ico { width: 22px; height: 22px; color: var(--amber); }
.toast.out { opacity: 0; transform: translateX(16px); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }

/* ------------------------------------------------------------------ touch */
#touch { position: fixed; right: calc(18px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); display: flex; gap: 14px; align-items: flex-end; }
#touch[hidden] { display: none; }
.tbtn { width: 86px; height: 86px; border-radius: 50%; border: 1.5px solid rgba(251, 241, 228, 0.4); background: rgba(24, 17, 34, 0.38); color: var(--cream); font: 600 13px var(--ui); letter-spacing: 0.04em; backdrop-filter: blur(6px); touch-action: none; }
.tbtn.scatter { width: 66px; height: 66px; font-size: 12px; }
.tbtn.on { background: rgba(242, 180, 90, 0.45); border-color: var(--amber); }

/* ------------------------------------------------------------------ screens */
.screen { position: fixed; inset: 0; display: none; overflow-y: auto; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); z-index: 20; touch-action: pan-y; user-select: text; }
.screen.show { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; animation: fade .35s ease; }
.screen.dim { background: radial-gradient(ellipse at center, rgba(20, 12, 30, 0.35), rgba(20, 12, 30, 0.6)); }
.screen.low { background: linear-gradient(180deg, rgba(20, 12, 30, 0) 30%, rgba(20, 12, 30, 0.55)); }
@keyframes fade { from { opacity: 0; } }

.panel { width: min(720px, 100%); margin: auto; padding: 28px 30px; border-radius: 20px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(10, 5, 20, 0.35); }
.panel.narrow { width: min(460px, 100%); }
.panel.wide { width: min(1040px, 100%); }
.panel h2 { font-family: var(--display); font-size: 40px; font-weight: 600; margin: 0 0 6px; line-height: 1.05; }
.panel h3 { font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--cream-3); margin: 22px 0 10px; font-weight: 600; }
.lead { color: var(--cream-2); font-size: 16px; line-height: 1.5; margin: 0 0 18px; }
.kicker { font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--amber); margin-bottom: 8px; font-weight: 600; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

.btn {
  font: 500 16px var(--ui); color: var(--cream); background: rgba(251, 241, 228, 0.07);
  border: 1px solid rgba(251, 241, 228, 0.22); border-radius: 999px; padding: 12px 26px; cursor: pointer;
  transition: background .2s, border-color .2s, transform .15s; display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
}
.btn small { font-size: 11.5px; color: var(--cream-3); font-weight: 400; }
.btn:hover, .btn:focus-visible { background: rgba(251, 241, 228, 0.15); border-color: rgba(251, 241, 228, 0.45); outline: none; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(180deg, #f6c574, #e9a14a); color: #2b1a10; border-color: transparent; font-weight: 600; }
.btn.primary small { color: rgba(43, 26, 16, 0.65); }
.btn.primary:hover, .btn.primary:focus-visible { background: linear-gradient(180deg, #ffd38a, #f2ac55); box-shadow: 0 0 0 3px rgba(242, 180, 90, 0.3); }
.btn.small { padding: 9px 18px; font-size: 14px; }
.btn.danger { border-color: rgba(239, 138, 126, 0.5); color: #ffc4bb; }

/* title */
.screen.title { justify-content: space-between; background: linear-gradient(180deg, rgba(20, 12, 30, 0.12), rgba(20, 12, 30, 0) 40%, rgba(20, 12, 30, 0.35)); }
.title-wrap { margin: auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; }
.logo { font-family: var(--display); font-weight: 500; font-size: clamp(76px, 15vw, 168px); letter-spacing: 0.06em; margin: 0; line-height: 0.9; text-shadow: 0 4px 40px rgba(40, 20, 50, 0.45); }
.tag { font-family: var(--display); font-style: italic; font-size: clamp(20px, 2.8vw, 28px); color: var(--cream-2); margin: 10px 0 34px; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; width: min(340px, 86vw); }
.menu .btn { width: 100%; }
.menu-row { display: flex; gap: 8px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.menu-row .btn { width: auto; flex: 1; padding: 9px 10px; }
.best { color: var(--cream-2); margin-top: 18px; font-size: 14px; }
.best b { color: var(--amber); }
.foot { font-size: 12.5px; color: var(--cream-3); text-align: center; padding-top: 12px; }
.foot a { color: var(--cream-2); }

/* how to */
.keys { width: 100%; border-collapse: collapse; font-size: 14px; margin: 4px 0 18px; }
.keys th, .keys td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.keys th { font-weight: 600; color: var(--cream); white-space: nowrap; }
.keys th small { color: var(--cream-3); font-weight: 400; }
.keys td { color: var(--cream-2); }
.tips { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.tips > div { display: flex; gap: 12px; align-items: flex-start; }
.tips .ico { width: 24px; height: 24px; color: var(--amber); margin-top: 2px; }
.tips p { margin: 0; color: var(--cream-2); font-size: 14px; line-height: 1.5; }
.tips b { color: var(--cream); font-weight: 600; }

/* notes */
.records { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0 4px; }
.records div { padding: 12px; border-radius: 12px; background: rgba(251, 241, 228, 0.05); border: 1px solid var(--line); text-align: center; }
.records b { display: block; font-family: var(--display); font-size: 30px; font-weight: 600; color: var(--amber); }
.records span { font-size: 12px; color: var(--cream-3); }
.notes { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.notes li { display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(251, 241, 228, 0.03); border: 1px solid transparent; opacity: 0.55; }
.notes li.got { opacity: 1; border-color: rgba(242, 180, 90, 0.3); background: rgba(242, 180, 90, 0.06); }
.notes li .ico { color: var(--amber); width: 20px; height: 20px; margin-top: 2px; }
.notes li b { display: block; font-size: 14px; font-weight: 600; }
.notes li span { font-size: 12.5px; color: var(--cream-2); }
.dailies { list-style: none; padding: 0; margin: 0; }
.dailies li { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--cream-2); }
.dailies b { color: var(--cream); }

/* settings */
.set { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.set input[type=range] { width: 200px; accent-color: var(--amber); }
.set input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--amber); }
.set select { background: rgba(251, 241, 228, 0.08); color: var(--cream); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; }
.set select option { color: #1b1424; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-top: 6px; }
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; text-align: left;
  padding: 18px; border-radius: 16px; background: rgba(251, 241, 228, 0.05); border: 1px solid var(--line);
  color: var(--cream); font: inherit; cursor: pointer; transition: transform .18s, background .2s, border-color .2s, box-shadow .2s;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); background: rgba(251, 241, 228, 0.1); border-color: rgba(242, 180, 90, 0.6); box-shadow: 0 10px 30px rgba(10, 5, 20, 0.3); outline: none; }
.card > b { font-family: var(--display); font-size: 26px; font-weight: 600; line-height: 1.1; }
.card > span { color: var(--cream-2); font-size: 14px; line-height: 1.45; }
.card em { font-style: normal; font-size: 12px; color: var(--amber); letter-spacing: 0.04em; }
.card.perk .ico.big { color: var(--amber); }
.card.route { padding: 0 0 16px; overflow: hidden; }
.card.route canvas { width: 100%; height: auto; aspect-ratio: 360 / 150; display: block; border-bottom: 1px solid var(--line); }
.card.route > b, .card.route > span, .card.route .stats, .card.route .wx { margin: 0 16px; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--cream-3); }
.stats div { display: flex; flex-direction: column; gap: 4px; }
.stats em { color: var(--cream-3); font-style: normal; letter-spacing: 0.04em; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 14px; height: 5px; border-radius: 3px; background: rgba(251, 241, 228, 0.18); }
.pips i.on { background: var(--amber); }
.wx { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--cream-2); line-height: 1.4; }
.wx .ico { color: var(--amber); width: 18px; height: 18px; margin-top: 1px; }
.wx b { color: var(--cream); font-weight: 600; }
.have { margin: 16px 0 0; font-size: 13px; color: var(--cream-3); text-align: center; }

/* tally and end */
.tally, .end { text-align: center; }
.big { font-family: var(--display); font-size: clamp(64px, 11vw, 104px); font-weight: 600; line-height: 0.95; margin-top: 4px; }
.big-sub { color: var(--cream-2); font-size: 16px; margin: 6px 0 16px; }
.big-sub b { color: var(--amber); font-weight: 600; }
.gain { color: #ffd78a; }
.loss { color: #ffaea4; }
.lines { list-style: none; padding: 0; margin: 0 auto; max-width: 420px; text-align: left; }
.lines li { display: flex; gap: 12px; align-items: baseline; padding: 7px 4px; border-bottom: 1px solid var(--line); color: var(--cream-2); font-size: 15px; }
.lines li b { min-width: 64px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.lines li.gain b { color: #ffd78a; }
.lines li.loss b { color: #ffaea4; }
.small-stats { color: var(--cream-3); font-size: 13px; margin: 14px 0 0; }
.newbest { color: var(--amber); font-weight: 600; letter-spacing: 0.04em; margin: 4px 0 0; }
.unlocked { color: var(--sage); font-size: 14px; margin: 14px 0 0; }
.chart { position: relative; margin: 20px auto 26px; max-width: 560px; }
.chart svg { width: 100%; height: 140px; overflow: visible; }
.chart polyline { fill: none; stroke: var(--amber); stroke-width: 2.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart circle { fill: var(--cream); }
.chart .xl { position: relative; height: 18px; font-size: 10.5px; color: var(--cream-3); }
.chart .xl span { position: absolute; transform: translateX(-50%); white-space: nowrap; top: 4px; }
.chart .xl span:nth-child(even) { top: 16px; }

@media (max-width: 720px) {
  #hud { grid-template-columns: 1fr 1fr; gap: 8px; padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r)); }
  .hud-c { grid-column: 1 / -1; grid-row: 2; padding-top: 0; }
  .hud-r { grid-column: 2; grid-row: 1; }
  .count { font-size: 32px; }
  .energy .bar { width: 120px; }
  .tips, .notes { grid-template-columns: 1fr; }
  .records { grid-template-columns: 1fr 1fr; }
  .panel { padding: 22px 18px; }
  .panel h2 { font-size: 32px; }
  .keys { font-size: 12.5px; }
  .keys th, .keys td { padding: 6px 5px; }
  .hud-r #hDay { font-size: 12.5px; text-align: right; }
}
@media (max-height: 520px) {
  .logo { font-size: 72px; }
  .tag { margin-bottom: 14px; }
  .menu { gap: 6px; }
  .btn { padding: 8px 20px; }
  .banner { top: 14%; }
}
@media (prefers-reduced-motion: reduce) {
  .banner.show { animation-duration: 3s; }
  .card:hover { transform: none; }
}
