:root {
  --green: #2f9e5b;
  --green-d: #23824a;
  --green-l: #e5f5eb;
  --orange: #ff883e;
  --ink: #1d2a24;
  --muted: #64746c;
  --card: rgba(255, 255, 255, 0.94);
  --line: rgba(29, 42, 36, 0.09);
  --red: #d8443a;
  --gold: #f2b01e;
  --shadow: 0 10px 30px rgba(20, 40, 30, 0.16), 0 2px 6px rgba(20, 40, 30, 0.08);
  --r: 22px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #9ed4ff;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: not-allowed; }
#world { position: fixed; inset: 0; }
#world canvas { display: block; touch-action: none; }

/* ---------- Pins ---------- */
#pins { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pin {
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: auto;
  will-change: transform;
}
.pin-emoji {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: #fff; border-radius: 50%;
  font-size: 20px; line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: 2.5px solid #fff;
  transition: transform 0.15s;
  position: relative;
}
.pin-emoji::after {
  content: ''; position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.pin-label {
  margin-top: 6px;
  font-size: 11.5px; font-weight: 800; white-space: nowrap;
  background: rgba(255, 255, 255, 0.92); padding: 2px 8px; border-radius: 99px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  opacity: 0; transform: translateY(-4px); transition: 0.15s; order: 2;
}
.pin:hover .pin-emoji { transform: scale(1.15); }
.pin:hover .pin-label, .pin.here .pin-label { opacity: 1; transform: none; }
.pin.here .pin-emoji { border-color: var(--green); box-shadow: 0 0 0 5px rgba(47, 158, 91, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2); }
.pin.here .pin-emoji::after { border-top-color: var(--green); }
.pin.closed .pin-emoji { filter: grayscale(0.7); opacity: 0.8; }
.pin.far .pin-emoji { width: 28px; height: 28px; font-size: 15px; }
.pin.far .pin-label { display: none; }
.you-pin {
  position: absolute; left: 0; top: 0; pointer-events: none;
  background: var(--green); color: #fff; font-weight: 900; font-size: 12px;
  padding: 3px 10px; border-radius: 99px; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}
.you-pin::after { content: ''; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--green); border-bottom: 0; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: min(760px, 100%); padding: max(10px, env(safe-area-inset-top)) 12px 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.bar {
  width: 100%;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--card); backdrop-filter: blur(10px);
  border-radius: 999px; padding: 7px 8px 7px 16px;
  box-shadow: var(--shadow);
}
.logo { font-size: 17px; margin-right: auto; white-space: nowrap; }
.logo b { font-weight: 900; letter-spacing: -0.3px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px; background: #f1f4f2;
  font-weight: 800; font-size: 13px; white-space: nowrap;
}
.chip.soft { color: var(--muted); }
.chip small { color: var(--muted); font-weight: 700; }
.chip.money { background: var(--green); color: #fff; font-size: 14px; }
.chip.money.neg { background: var(--red); }
.chip.icon { width: 32px; height: 32px; padding: 0; justify-content: center; background: #fff; border: 1.5px solid var(--line); }
.stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.stats .chip, .stat { background: var(--card); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1); }
.stat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 13px;
}
.stat .track { width: 64px; height: 8px; border-radius: 99px; background: #e4e9e6; overflow: hidden; }
.stat .track i { display: block; height: 100%; width: 50%; border-radius: 99px; background: linear-gradient(90deg, #f2b01e, #ffd34d); transition: width 0.5s; }
.stat.mood .track i { background: linear-gradient(90deg, #2f9e5b, #6fd08f); }
.stat.low .track i { background: var(--red); }
.stat.low { animation: pulse 1.2s infinite; }
.stat em { font-style: normal; min-width: 20px; text-align: right; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(216, 68, 58, 0.25); } }

#ticker {
  max-width: 100%; overflow: hidden;
  background: var(--green); color: #fff;
  border-radius: 999px; padding: 7px 18px;
  font-weight: 800; font-size: 13px; box-shadow: var(--shadow);
}
#ticker span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ticker span::before { content: '📰 '; }
#ticker span.in { animation: tickin 0.5s ease; }
@keyframes tickin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Toasts ---------- */
#toasts { display: flex; flex-direction: column; gap: 8px; width: min(420px, 100%); pointer-events: none; }
.toast {
  background: var(--card); backdrop-filter: blur(10px);
  border-radius: 18px; padding: 11px 15px;
  box-shadow: var(--shadow); font-size: 14px;
  border-left: 5px solid var(--green);
  animation: tin 0.35s cubic-bezier(0.2, 1.4, 0.5, 1);
  transition: 0.4s;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast p { margin: 3px 0 0; color: #3b4a43; }
.toast.bad { border-left-color: var(--red); }
.toast.meh { border-left-color: var(--orange); }
.toast.info { border-left-color: #1f6fd1; }
.toast.gold { border-left-color: var(--gold); background: #fff8e1; }
@keyframes tin { from { opacity: 0; transform: translateY(-12px) scale(0.96); } }
.deltas { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.deltas span { font-weight: 900; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.up { color: var(--green-d); }
.down { color: var(--red); }
.deltas .up { background: var(--green-l); }
.deltas .down { background: #fde8e6; }
.ach-toast { display: flex; gap: 10px; align-items: center; }
.ach-toast > span { font-size: 30px; }
.ach-toast small { display: block; color: #9a7410; font-weight: 800; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.6px; }

/* ---------- Dock ---------- */
#dock {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  margin-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--card); backdrop-filter: blur(10px);
  border-radius: var(--r); padding: 12px; box-shadow: var(--shadow);
  transition: transform 0.3s, opacity 0.3s;
}
.dock-top { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.here { display: flex; gap: 8px; align-items: center; text-align: left; padding: 4px 10px 4px 4px; border-radius: 16px; flex-shrink: 0; max-width: 46%; }
.here:hover { background: #f1f4f2; }
.here-emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--green-l); display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.here small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.here b { display: block; font-weight: 900; line-height: 1.15; }
.goal { flex: 1; min-width: 0; font-size: 12.5px; }
.goal-track { height: 8px; border-radius: 99px; background: #e4e9e6; margin: 5px 0; overflow: hidden; }
.goal-track i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #6fd08f); border-radius: 99px; transition: width 0.6s; min-width: 4px; }
#rent-text { color: var(--muted); font-weight: 700; }
.warn { color: var(--red); font-weight: 900; }
.dock-btns { display: flex; gap: 8px; }
.btn {
  padding: 12px 14px; border-radius: 16px; background: #fff;
  border: 1.5px solid var(--line); font-weight: 800; white-space: nowrap;
  transition: transform 0.1s, background 0.15s;
}
.btn:hover { background: #f5f7f6; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); flex: 1; }
.btn.primary:hover { background: var(--green-d); }
.btn.big { padding: 15px 22px; font-size: 17px; width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); margin-top: 14px; }
body.busy #dock { opacity: 0.6; pointer-events: none; }

/* ---------- Sheet ---------- */
#sheet {
  position: fixed; left: 50%; bottom: 0;
  transform: translate(-50%, 110%);
  width: min(560px, 100%);
  max-height: min(66vh, 640px); overflow-y: auto;
  background: #fff; border-radius: 26px 26px 0 0;
  padding: 18px 16px max(18px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(20, 40, 30, 0.22);
  transition: transform 0.32s cubic-bezier(0.2, 1, 0.3, 1);
  z-index: 5;
}
#sheet.show { transform: translate(-50%, 0); }
.sheet-head { display: flex; gap: 12px; align-items: center; }
.sheet-emoji { width: 52px; height: 52px; border-radius: 16px; background: var(--green-l); display: grid; place-items: center; font-size: 28px; flex-shrink: 0; }
.sheet-title { flex: 1; min-width: 0; }
.sheet-title h3 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -0.3px; }
.sheet-title small { color: var(--muted); font-weight: 700; }
.open { color: var(--green-d); font-weight: 900; }
.shut { color: var(--red); font-weight: 900; }
.x { width: 36px; height: 36px; border-radius: 50%; background: #f1f4f2; font-weight: 900; flex-shrink: 0; }
.x:hover { background: #e4e9e6; }
.desc { color: #43524b; margin: 12px 2px 14px; line-height: 1.45; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.action {
  display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 11px 12px; border-radius: 16px; border: 1.5px solid var(--line); background: #fff;
  transition: 0.12s;
}
.action:not(:disabled):hover { border-color: var(--green); background: #f6fcf8; transform: translateY(-1px); }
.action:not(:disabled):active { transform: scale(0.98); }
.action:disabled { opacity: 0.55; background: #fafafa; }
.a-emoji { font-size: 24px; width: 34px; text-align: center; flex-shrink: 0; }
.a-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.a-main b { font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; font-size: 12px; font-weight: 800; color: var(--muted); }
.chips > * { background: #f1f4f2; padding: 1px 7px; border-radius: 99px; }
.chips .up { background: var(--green-l); }
.chips .down { background: #fde8e6; }
.chips .note { background: #fff3e0; color: #b05f12; }
.why { font-size: 12px; color: var(--red); font-weight: 800; }
.travel-head { font-weight: 800; margin: 0 0 8px; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 6px; border-radius: 16px; border: 1.5px solid var(--line); background: #fff;
  font-size: 12.5px; color: var(--muted); font-weight: 700; transition: 0.12s;
}
.mode b { color: var(--ink); font-size: 13.5px; }
.m-emoji { font-size: 26px; }
.mode:not(:disabled):hover { border-color: var(--green); background: #f6fcf8; transform: translateY(-2px); }
.mode:disabled { opacity: 0.5; }
.closed-note { background: #fff3e0; color: #8a4a0c; padding: 9px 12px; border-radius: 12px; font-weight: 700; font-size: 13px; margin: 10px 0 0; }
.peek { margin-top: 12px; color: var(--muted); font-weight: 700; font-size: 13.5px; }
.peek summary { cursor: pointer; }
.peek ul { margin: 6px 0 0; padding-left: 4px; list-style: none; line-height: 1.7; color: var(--ink); }

/* ---------- Modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(14, 30, 22, 0.42); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
#modal.show { display: flex; animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative; background: #fff; border-radius: 26px;
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 24px 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.5, 1);
}
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }
.modal-card > .x { position: absolute; top: 14px; right: 14px; }
.modal-card h2 { margin: 0 0 14px; font-weight: 900; font-size: 22px; letter-spacing: -0.3px; }
.modal-card h2 small { color: var(--muted); font-size: 15px; }
.muted { color: var(--muted); }

.intro { text-align: center; }
.logo-big { font-size: 56px; animation: spin 6s ease-in-out infinite; display: inline-block; }
@keyframes spin { 50% { transform: rotate(14deg) scale(1.08); } }
.intro h1 { margin: 0; font-size: 36px; font-weight: 900; letter-spacing: -1px; color: var(--green-d); }
.tag { color: var(--muted); font-weight: 700; margin: 4px 0 18px; }
.intro label, .lbl { display: block; text-align: left; font-weight: 800; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.intro input {
  display: block; width: 100%; margin-top: 6px; padding: 13px 15px;
  border: 1.5px solid var(--line); border-radius: 14px; font: inherit; font-weight: 800; font-size: 16px; color: var(--ink);
  user-select: text;
}
.intro input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 4px rgba(47, 158, 91, 0.15); }
.intro label { margin-bottom: 16px; }
.origins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.origin {
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center;
  padding: 12px 8px; border-radius: 16px; border: 2px solid var(--line); transition: 0.12s;
}
.origin span { font-size: 28px; }
.origin b { font-size: 13px; line-height: 1.2; }
.origin small { font-size: 11px; color: var(--muted); line-height: 1.3; }
.origin em { font-style: normal; font-size: 11px; font-weight: 900; color: var(--green-d); margin-top: auto; }
.origin.sel { border-color: var(--green); background: #f3fbf6; }
.jackets { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; }
.jacket { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--line); transition: 0.12s; }
.jacket.sel { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.1); }

.place-list { display: flex; flex-direction: column; gap: 6px; }
.place-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 14px; text-align: left; }
.place-row:hover { background: #f1f4f2; }
.place-row > span { width: 40px; height: 40px; border-radius: 12px; background: var(--green-l); display: grid; place-items: center; font-size: 21px; flex-shrink: 0; }
.place-row b { display: block; }
.place-row small { color: var(--muted); font-weight: 700; }
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 12px 6px; border-radius: 16px; background: #f4f6f5; opacity: 0.7; }
.ach span { font-size: 28px; }
.ach b { font-size: 12.5px; line-height: 1.2; }
.ach small { font-size: 11px; color: var(--muted); line-height: 1.25; }
.ach.got { background: #fff8e1; opacity: 1; box-shadow: inset 0 0 0 2px #f8d76b; }
.bag { display: grid; gap: 8px; }
.bag-item { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; background: #f4f6f5; opacity: 0.6; }
.bag-item.got { opacity: 1; background: var(--green-l); }
.bag-item > span { font-size: 26px; }
.bag-item small { display: block; color: var(--muted); font-weight: 700; }
.facts { margin-top: 14px; display: grid; gap: 6px; font-size: 14px; }
.diary { display: flex; flex-direction: column; gap: 10px; }
.diary small { color: var(--muted); font-weight: 800; font-size: 11.5px; }
.diary p { margin: 1px 0 0; line-height: 1.4; }
.help { padding-left: 0; list-style: none; display: grid; gap: 10px; line-height: 1.45; margin: 0; }

.ending { text-align: center; }
.big-emoji { font-size: 72px; animation: spin 3s ease-in-out infinite; display: inline-block; }
.ending h2 { font-size: 28px; margin: 6px 0 8px; }
.ending p { line-height: 1.5; }
.end-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0 10px; }
.end-stats div { background: #f4f6f5; border-radius: 14px; padding: 10px 4px; }
.end-stats b { display: block; font-size: 18px; font-weight: 900; }
.end-stats span { font-size: 11px; color: var(--muted); font-weight: 700; }

.confetti {
  position: fixed; top: -40px; z-index: 20; pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

body.night .pin-label { background: rgba(30, 38, 60, 0.9); color: #fff; }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  body { font-size: 14px; }
  .bar { padding: 6px 6px 6px 12px; gap: 4px; border-radius: 22px; }
  .logo { font-size: 15px; width: 100%; margin: 0 0 2px; }
  .chip { padding: 5px 9px; font-size: 12px; }
  #week { display: none; }
  .stat .track { width: 40px; }
  #ticker { font-size: 12px; padding: 6px 14px; }
  .dock-top { flex-direction: column; align-items: stretch; gap: 8px; }
  .here { max-width: none; }
  .btn { padding: 11px 11px; }
  .modes { grid-template-columns: repeat(2, 1fr); }
  .origins { grid-template-columns: 1fr; }
  .origin { flex-direction: row; text-align: left; gap: 10px; flex-wrap: wrap; }
  .origin small { flex-basis: 100%; }
  .ach-grid { grid-template-columns: repeat(2, 1fr); }
  .end-stats { grid-template-columns: repeat(2, 1fr); }
  .pin-emoji { width: 32px; height: 32px; font-size: 17px; }
}
