:root {
  --bg: #171a21;
  --bg2: #1f2430;
  --card: #242b38;
  --line: #333c4d;
  --text: #e8ecf3;
  --muted: #9aa6b8;
  --accent: #f6c344;
  --accent-ink: #2a2205;
  --good: #81c995;
  --danger: #f28b82;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  padding: 10px 14px; border-radius: 12px; font-size: 15px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; font-size: 14px;
}
.btn-ghost:hover { color: var(--text); }
.btn-ghost.danger { color: var(--danger); border-color: transparent; }

/* ---------- Экран входа ---------- */
.gate {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 24px; text-align: center;
}
.gate-logo {
  width: 64px; height: 64px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 18px; font-size: 34px; font-weight: 800;
}
.gate h1 { margin: 8px 0 6px; font-size: 24px; }
.gate-hint { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.4; }
.gate-note { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
#gateForm { display: flex; flex-direction: column; gap: 10px; }
#codeInput {
  width: 100%; padding: 14px 16px; font-size: 17px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
#codeInput:focus { border-color: var(--accent); }
.gate-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- Основной экран ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(23,26,33,0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; }
.balance-wrap {
  margin-left: auto; display: flex; align-items: baseline; gap: 8px;
  background: var(--bg2); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 12px;
}
.balance-label { color: var(--muted); font-size: 13px; }
.balance { font-size: 22px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn { font-size: 12px; color: var(--danger); transition: color .3s; }
.conn.online { color: var(--good); }

/* ---------- Вкладки ---------- */
.tabs {
  display: flex; gap: 4px;
  max-width: 900px; width: 100%; margin: 0 auto;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  flex: 1; min-width: max-content;
  background: transparent; color: var(--muted);
  padding: 11px 14px; font-size: 15px; font-weight: 600;
  border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content {
  flex: 1; width: 100%; max-width: 900px; margin: 0 auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-head-actions { display: flex; gap: 8px; }
.panel-empty { color: var(--muted); font-size: 14px; line-height: 1.4; margin: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

/* ---------- Карточка действия ---------- */
.action {
  background: var(--card); border: 1px solid var(--line);
  border-left: 6px solid var(--ac, #888);
  border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.action-body { flex: 1; min-width: 0; }
.action-title { font-weight: 600; font-size: 15px; word-break: break-word; }
.action-points { color: var(--muted); font-size: 13px; margin-top: 2px; }
.action-points b { color: var(--accent); }
.do-btn {
  flex: none; background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 15px; padding: 9px 14px; border-radius: 10px;
}
.do-btn:active { transform: scale(0.95); }
.edit-btn {
  flex: none; background: transparent; color: var(--muted);
  font-size: 16px; padding: 4px 6px; border-radius: 8px;
}
.edit-btn:hover { color: var(--text); background: var(--bg2); }

/* ---------- Карточка награды ---------- */
.reward {
  background: var(--card); border: 1px solid var(--line);
  border-left: 6px solid var(--ac, #888);
  border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.reward-body { flex: 1; min-width: 0; }
.reward-title { font-weight: 600; font-size: 15px; word-break: break-word; }
.reward-cost { color: var(--muted); font-size: 13px; margin-top: 2px; }
.reward-cost b { color: var(--accent); }
.buy-btn {
  flex: none; background: var(--good); color: #0d1b0d;
  font-weight: 800; font-size: 15px; padding: 9px 14px; border-radius: 10px;
}
.buy-btn:active { transform: scale(0.95); }
.buy-btn:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; transform: none; }

/* ---------- Карточка цикла ---------- */
.cycle {
  background: var(--card); border: 1px solid var(--line);
  border-top: 5px solid var(--ac, #888);
  border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
}
.cycle-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 14px;
}
.cycle-title { flex: 1; font-weight: 700; font-size: 15px; word-break: break-word; }
.cycle-bonus {
  font-size: 12px; color: var(--accent-ink); background: var(--accent);
  font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.cycle-meta { color: var(--muted); font-size: 12px; padding: 0 14px 6px; }
.cycle-progress { height: 5px; background: var(--bg2); margin: 0 14px 8px; border-radius: 3px; overflow: hidden; }
.cycle-progress > i { display: block; height: 100%; background: var(--good); transition: width .25s; }
.steps { list-style: none; margin: 0; padding: 0 8px 4px; }
.step {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 6px; border-radius: 9px;
}
.step:hover { background: var(--bg2); }
.step.done .step-text { color: var(--muted); text-decoration: line-through; }
.check {
  flex: none; width: 20px; height: 20px;
  border: 2px solid var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 13px; font-weight: 800; cursor: pointer;
}
.step.done .check { background: var(--good); border-color: var(--good); color: #0d1b0d; }
.step-text { flex: 1; font-size: 14px; line-height: 1.3; word-break: break-word; }
.step-del { flex: none; background: transparent; color: var(--muted); opacity: 0; font-size: 15px; padding: 0 4px; }
.step:hover .step-del { opacity: 1; }
.step-del:hover { color: var(--danger); }
.add-step { display: flex; gap: 8px; padding: 6px 12px 12px; }
.add-step input {
  flex: 1; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 14px; outline: none;
}
.add-step input:focus { border-color: var(--accent); }
.cycle-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 12px 10px; }
.cycle-foot .btn-ghost { padding: 6px 9px; font-size: 13px; }

/* ---------- История ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.chip {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 600;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.log { list-style: none; margin: 0; padding: 0; }
.log-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 4px; border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent; border-radius: 0 8px 8px 0;
}
.log-row.earn { border-left-color: var(--good); background: rgba(129,201,149,0.06); }
.log-row.spend { border-left-color: var(--danger); background: rgba(242,139,130,0.07); }
.log-icon { flex: none; width: 26px; text-align: center; font-size: 15px; }
.log-main { flex: 1; min-width: 0; }
.log-title { font-size: 14px; word-break: break-word; }
.log-time { color: var(--muted); font-size: 12px; margin-top: 1px; }
.log-points { font-weight: 800; font-variant-numeric: tabular-nums; }
.log-points.plus { color: var(--good); }
.log-points.minus { color: var(--danger); }
.log-del { flex: none; background: transparent; color: var(--muted); opacity: 0; font-size: 16px; padding: 0 4px; }
.log-row:hover .log-del { opacity: 1; }
.log-del:hover { color: var(--danger); }

/* ---------- Модалка ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 400px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
}
.modal-card h3 { margin: 0 0 16px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { color: var(--muted); font-size: 13px; }
.field input {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.modal-colors { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.swatch { width: 30px; height: 30px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: var(--text); }
.modal-buttons { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-buttons-right { display: flex; gap: 10px; }

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .balance-wrap { padding: 5px 10px; }
  .balance { font-size: 19px; }
  .brand { font-size: 16px; }
}
