:root {
  --bg: #000;
  --card: #0d0d0d;
  --card2: #141414;
  --line: #222;
  --text: #f2f2f2;
  --muted: #8b8b8b;
  --accent: #f5c542;
  --accent-ink: #1a1400;
  --danger: #ff5a5f;
  --ok: #4ade80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- верхняя панель ---------- */
.top { padding: 14px 16px 8px; text-align: center; }
.coins { font-size: 40px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.coins .ico { font-size: 30px; margin-right: 6px; }
.rates { margin-top: 4px; color: var(--muted); font-size: 13px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; color: var(--accent); font-weight: 600; }
.banner { background: #1a1400; color: var(--accent); text-align: center; font-size: 12px; padding: 5px 10px; border-bottom: 1px solid #332700; }

/* ---------- экраны ---------- */
#screens { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
.screen { display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.screen[hidden] { display: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.card.warn { border-color: #4a3b0a; background: #130f02; color: #e8d28a; font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.card-title { font-weight: 700; }
.lvl { color: var(--accent); font-weight: 600; font-size: 13px; margin-left: 6px; }
.muted { color: var(--muted); font-size: 13px; }
.nowrap { white-space: nowrap; }
.card p:first-child { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }
.section-title { font-weight: 700; margin-bottom: 6px; }
.list { margin: 0; padding-left: 18px; color: #c9c9c9; font-size: 14px; }
.list li { margin: 3px 0; }

.bar { height: 8px; background: #1a1a1a; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.fill.energy { background: #6ea8ff; }

/* ---------- тап ---------- */
.tap-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 6px 0; min-height: 0; }
#tap-btn {
  width: min(62vw, 38dvh, 270px);
  width: min(62vw, 38vh, 270px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid #3a2f0a;
  background: radial-gradient(circle at 50% 38%, #2a2203 0%, #0c0a00 70%);
  box-shadow: 0 0 0 6px #0a0a0a, 0 0 40px rgba(245, 197, 66, .18);
  font-size: min(22vw, 96px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: transform .06s ease, box-shadow .06s ease;
}
#tap-btn.down { transform: scale(.95); box-shadow: 0 0 0 6px #0a0a0a, 0 0 60px rgba(245, 197, 66, .35); }
#tap-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#tap-btn.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

#float-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.float { position: absolute; font-weight: 800; font-size: 22px; color: var(--accent); text-shadow: 0 1px 6px #000; transform: translate(-50%, -50%); animation: floatUp .8s ease-out forwards; }
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -90px; } }
@media (prefers-reduced-motion: reduce) {
  .float { animation: fadeOut .8s forwards; }
  @keyframes fadeOut { to { opacity: 0; } }
  #tap-btn, .fill { transition: none; }
  #tap-btn.shake { animation: none; }
}

/* ---------- кнопки ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card2); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font-weight: 700; cursor: pointer;
  min-height: 42px; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #1a0002; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.dim { opacity: .45; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; padding: 10px 6px; }
.btn.wide { width: 100%; }

/* ---------- подарки ---------- */
.gift-emoji { font-size: 34px; line-height: 1; }
.tier { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.tier:first-of-type { border-top: 0; }
.tier .t-name { flex: 1; }
.tier .t-state { color: var(--muted); font-size: 13px; }
.tier .t-state.on { color: var(--ok); }

/* ---------- нижние вкладки ---------- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; padding: 8px 0 9px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; border-top: 2px solid transparent; }
.tabs button .e { font-size: 20px; line-height: 1.1; }
.tabs button[aria-selected="true"] { color: var(--text); border-top-color: var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- всплывающие элементы ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  background: #1c1c1c; border: 1px solid #333; color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { border-color: #5a2326; color: #ffb3b6; }
#toast.ok { border-color: #1f4d33; color: #a7f3c4; }

#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .78); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 40; }
.dialog { background: #101010; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; width: 100%; max-width: 380px; max-height: 88vh; overflow-y: auto; }
.dialog h3 { margin: 0 0 10px; font-size: 18px; }
.dialog p { margin: 8px 0; color: #d0d0d0; font-size: 15px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }
.dialog-actions .btn { flex: 1; }

#fatal { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 28px; text-align: center; }
#fatal .box { max-width: 340px; }
#fatal h2 { margin: 0 0 10px; }
#fatal p { color: var(--muted); margin: 0 0 18px; }

#boot { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* ---------- юридические страницы ---------- */
.doc { max-width: 680px; margin: 0 auto; padding: 24px 18px 60px; line-height: 1.55; }
.doc h1 { font-size: 24px; }
.doc h2 { font-size: 18px; margin-top: 26px; }
.doc p, .doc li { color: #cfcfcf; }
.doc .note { background: #1a1400; border: 1px solid #332700; color: var(--accent); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
