:root {
  --panel: rgba(18, 24, 42, 0.74);
  --panel-border: rgba(255, 255, 255, 0.13);
  --text: #f5f1e8;
  --muted: #a9b2c7;
  --accent: #ffb454;
  --good: #6ee7a0;
  --bad: #ff7676;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1226; color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font: inherit; }

#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 18px; height: 18px; }

/* ---- top bar ---- */
#topbar {
  position: fixed; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; gap: 6px 22px; flex-wrap: wrap;
  padding: 8px 14px; user-select: none;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 6px; }
.logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #3d9a6a, #2d6a4f); color: #fff; }
.city-name { font-weight: 700; letter-spacing: 0.2px; line-height: 1.1; }
.rank { font-size: 12px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; }

.stat { display: flex; flex-direction: column; position: relative; min-width: 92px; outline: none; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; display: flex; align-items: center; gap: 6px; }
.stat .sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat .sub.pos { color: var(--good); }
.stat .sub.neg { color: var(--bad); }
#money.neg { color: var(--bad); }
#money.flash { animation: flash 0.5s; }
@keyframes flash { 0%, 100% { transform: none; } 20% { transform: translateX(-4px); color: var(--bad); } 40% { transform: translateX(4px); color: var(--bad); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.clock .value svg { color: var(--accent); }
.clock.night .value svg { color: #9db4ff; }

.popover {
  position: absolute; top: calc(100% + 14px); left: -8px; width: 270px; padding: 12px 14px;
  background: rgba(14, 19, 36, 0.95); border: 1px solid var(--panel-border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); opacity: 0; pointer-events: none; transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s; z-index: 5;
}
.has-pop:hover .popover, .has-pop:focus .popover { opacity: 1; transform: none; }
.popover h4 { margin: 0 0 8px; font-size: 12px; letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.popover .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 2px 0; }
.popover .row b { font-variant-numeric: tabular-nums; }
.popover .total { border-top: 1px solid var(--panel-border); margin-top: 6px; padding-top: 6px; font-weight: 700; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.controls { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.seg { display: flex; background: rgba(255, 255, 255, 0.07); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; min-width: 34px; height: 30px; border-radius: 8px; font-weight: 600; font-size: 13px; display: grid; place-items: center; color: var(--muted); }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent); color: #1c1a14; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, 0.07); display: grid; place-items: center; color: var(--text); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.15); }
.icon-btn.off { color: var(--muted); opacity: 0.6; }

/* ---- toolbar ---- */
#toolbar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: stretch; gap: 6px; padding: 8px; user-select: none; max-width: calc(100vw - 16px);
}
.sep { width: 1px; background: var(--panel-border); margin: 4px 2px; }
.tool {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 78px; padding: 8px 8px 6px; border: 1px solid transparent; border-radius: 11px;
  background: rgba(255, 255, 255, 0.05); transition: background 0.12s, transform 0.12s, border-color 0.12s;
}
.tool:hover { background: rgba(255, 255, 255, 0.13); transform: translateY(-2px); }
.tool.on { background: rgba(255, 180, 84, 0.2); border-color: var(--accent); }
.tool.on .ico { color: var(--accent); }
.tool.danger.on { background: rgba(255, 118, 118, 0.2); border-color: var(--bad); }
.tool.danger.on .ico { color: var(--bad); }
.tool .ico { width: 26px; height: 26px; margin-bottom: 2px; }
.tool .name { font-size: 13px; font-weight: 600; }
.tool .price { font-size: 12px; color: var(--good); font-variant-numeric: tabular-nums; }
.tool.poor .price { color: var(--bad); }
.tool.poor .ico { opacity: 0.5; }
.tool kbd { position: absolute; top: 4px; left: 6px; font-size: 10px; color: var(--muted); opacity: 0.85; }

#hint {
  position: fixed; left: 50%; bottom: 112px; transform: translateX(-50%); font-size: 12px; color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); pointer-events: none; transition: opacity 1s; white-space: nowrap; max-width: 96vw; overflow: hidden; text-overflow: ellipsis;
}
#hint.hide { opacity: 0; }

/* ---- toasts / floaty ---- */
#toasts { position: fixed; top: 92px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 8; }
.toast {
  padding: 9px 16px; border-radius: 12px; background: rgba(14, 19, 36, 0.9); border: 1px solid var(--panel-border);
  font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); animation: toast-in 0.25s ease-out; max-width: 90vw; text-align: center;
}
.toast.good { border-color: rgba(110, 231, 160, 0.6); }
.toast.bad { border-color: rgba(255, 118, 118, 0.6); }
.toast.rank { font-size: 18px; font-weight: 700; padding: 12px 24px; border-color: var(--accent); color: var(--accent); }
.toast.out { opacity: 0; transform: translateY(-8px); transition: opacity 0.4s, transform 0.4s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.96); } to { opacity: 1; transform: none; } }

#floaty { position: fixed; pointer-events: none; z-index: 8; }
.float { position: fixed; font-weight: 700; font-size: 16px; color: var(--good); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); animation: float-up 1.8s ease-out forwards; }
@keyframes float-up { 0% { opacity: 0; transform: translateY(6px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-34px); } }

/* ---- tooltip ---- */
#tip {
  position: fixed; z-index: 7; pointer-events: none; min-width: 190px; max-width: 270px; padding: 10px 12px; font-size: 13px; line-height: 1.4;
  background: rgba(14, 19, 36, 0.93); border: 1px solid var(--panel-border); border-radius: 11px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
#tip .t-title { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
#tip .t-title span { color: var(--accent); font-weight: 600; font-size: 12px; }
#tip .t-row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
#tip .t-row b { color: var(--text); font-variant-numeric: tabular-nums; }
#tip ul { list-style: none; margin: 6px 0 0; padding: 0; }
#tip li { padding-left: 20px; position: relative; color: var(--muted); }
#tip li::before { content: "·"; position: absolute; left: 6px; }
#tip li.ok { color: var(--text); }
#tip li.ok::before { content: "✓"; color: var(--good); left: 3px; }
#tip li.bad { color: #ffd1d1; }
#tip li.bad::before { content: "✗"; color: var(--bad); left: 3px; }
#tip .t-note { margin-top: 6px; color: var(--muted); font-size: 12px; }
#tip .t-note.warn { color: #ffcf8a; }
#tip .t-note.err { color: var(--bad); }
#tip .bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); margin-top: 7px; overflow: hidden; }
#tip .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---- overlays ---- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(6, 9, 20, 0.55); backdrop-filter: blur(3px); z-index: 20; padding: 16px; }
.overlay[hidden] { display: none; }
.card { padding: 26px 30px; max-width: 520px; width: 100%; background: rgba(18, 24, 42, 0.92); animation: toast-in 0.3s ease-out; }
.card.small { max-width: 360px; }
.card h1 { margin: 0 0 6px; font-size: 26px; }
.card h2 { margin: 0 0 6px; }
.card .lead { color: #d6dbea; margin: 0 0 16px; line-height: 1.5; }
.steps { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.4; }
.steps .ico { width: 30px; height: 30px; padding: 5px; border-radius: 9px; background: rgba(255, 180, 84, 0.16); color: var(--accent); }
.steps em { color: var(--accent); font-style: normal; font-weight: 600; }
.tiny { color: var(--muted); font-size: 13px; }
.primary { background: var(--accent); color: #1c1a14; border: 0; border-radius: 11px; padding: 11px 22px; font-weight: 700; font-size: 15px; margin-top: 6px; }
.primary:hover { filter: brightness(1.08); }
.row-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.row-btns button:not(.primary) { background: rgba(255, 255, 255, 0.09); border: 0; border-radius: 11px; padding: 11px 18px; }

/* ---- small screens ---- */
@media (max-width: 860px) {
  #topbar { gap: 4px 14px; padding: 8px 10px; }
  .stat { min-width: 70px; }
  .stat .value { font-size: 18px; }
  .controls { margin-left: 0; width: 100%; justify-content: space-between; }
  .brand .city-name { display: none; }
  #toasts { top: 150px; }
  .tool { min-width: 56px; padding: 6px 4px; }
  .tool .name { font-size: 11px; }
  #hint { display: none; }
  #toolbar { bottom: 10px; gap: 3px; padding: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
