:root {
  --bg: #f4f4f6; --card: #fff; --text: #1c1c1e; --muted: #8e8e93; --line: #e3e3e8;
  --ok: #2fb35d; --no: #e5484d; --accent: #ffdd2d; --accent-text: #1c1c1e; --chip: #f0f0f3;
  --shadow: 0 8px 24px rgba(0, 0, 0, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --card: #1e1e21; --text: #f2f2f5; --muted: #8e8e93; --line: #2c2c30; --chip: #2a2a2e;
    --shadow: 0 8px 24px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --card: #1e1e21; --text: #f2f2f5; --muted: #8e8e93; --line: #2c2c30; --chip: #2a2a2e;
  --shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--no); font-size: 14px; min-height: 1em; margin: 6px 0; }

.primary, .secondary { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer; }
.primary { background: var(--accent); color: var(--accent-text); }
.primary:disabled { opacity: .4; cursor: default; }
.secondary { background: var(--chip); }
.link { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px 0; }
.icon { border: 0; background: var(--chip); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: none; }
.wide { width: 100%; margin-top: 8px; }

/* вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-box { text-align: center; max-width: 320px; }
.logo-big { width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 36px; font-weight: 800; }

/* каркас */
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; padding: 0 16px calc(76px + env(safe-area-inset-bottom)); }
.top { display: flex; justify-content: space-between; align-items: baseline; padding: calc(12px + env(safe-area-inset-top)) 0 12px; }
.tab { display: none; }
.tab.on { display: block; }
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
nav.bottom button { flex: 1; border: 0; background: none; padding: 14px 4px; color: var(--muted); cursor: pointer; font-size: 14px; }
nav.bottom button.on { color: var(--text); font-weight: 600; }

/* колода */
.day-header { font-weight: 600; text-align: center; margin: 4px 0; min-height: 1.4em; }
.stack { position: relative; height: 430px; margin-top: 8px; }
.card { position: absolute; inset: 0; background: var(--card); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; transition: transform .25s, opacity .25s; overflow: hidden; }
.card.drag { transition: none; cursor: grabbing; }
.card.back { transform: scale(.95) translateY(12px); opacity: .55; pointer-events: none; }
.logo { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: #fff; background: #888; flex: none; }
.card-head { display: flex; gap: 12px; align-items: center; }
.card-title { font-size: 20px; font-weight: 600; word-break: break-word; }
.amount { font-size: 34px; font-weight: 700; margin: 14px 0 2px; }
.plus { color: var(--ok); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 10px; background: var(--chip); }
.badge.warn { background: #ffe8a3; color: #6b4e00; }
.badge.bad { background: #ffd6d6; color: #8a1c1c; }
.suggestion { margin-top: auto; padding: 12px; border-radius: 14px; background: var(--bg); border: 2px solid transparent; width: 100%; text-align: left; cursor: pointer; }
.suggestion.need { border-color: var(--accent); }
.bank-info { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bank-info .info { font-size: 12px; padding: 3px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.suggestion .part { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.suggestion .part b { font-weight: 600; }
.stamp { position: absolute; top: 20px; padding: 4px 12px; border: 3px solid; border-radius: 8px; font-weight: 800; font-size: 20px; opacity: 0; pointer-events: none; }
.stamp.yes { left: 20px; color: var(--ok); transform: rotate(-12deg); }
.stamp.no { right: 20px; color: var(--no); transform: rotate(12deg); }
.deck-actions { display: flex; justify-content: center; align-items: center; gap: 20px; margin-top: 20px; flex-wrap: wrap; }
.round { width: 62px; height: 62px; border-radius: 50%; border: 0; background: var(--card); font-size: 26px; cursor: pointer; box-shadow: var(--shadow); }
.round.small-round { width: 46px; height: 46px; font-size: 18px; color: var(--muted); }
.empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); }
.hint { margin-top: 14px; }

/* редактор частей */
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-body { background: var(--card); width: 100%; max-width: 480px; max-height: 88vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.part-edit { border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin: 10px 0; display: grid; gap: 8px; }
.part-row { display: flex; gap: 8px; }
.part-row > input[type=number] { flex: 0 0 38%; }
.new-category { display: grid; gap: 8px; padding: 10px; border-radius: 12px; border: 2px dashed var(--accent); }
.row-form { display: flex; gap: 8px; }
.row-form input { flex: 1; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.stack-form { display: grid; gap: 10px; }

/* лента, наличные, настройки */
.month { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 12px; }
.month button { border: 0; background: var(--card); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 18px; }
.summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.summary div { background: var(--card); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.day-title { color: var(--muted); font-size: 13px; margin: 16px 0 4px; }
.op-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--card); border-radius: 12px; margin: 6px 0; cursor: pointer; width: 100%; border: 0; text-align: left; }
.op-row .parts-line { color: var(--muted); font-size: 13px; }
.op-row .right { text-align: right; white-space: nowrap; }
.card-block { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.big-amount { font-size: 32px; font-weight: 700; margin: 4px 0 10px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.card-rule { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: auto; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; font-size: 14px; max-width: calc(100% - 32px); }

/* настройки: «?» и раскрывающиеся строки */
.section-head { display: flex; justify-content: space-between; align-items: center; }
.help-btn { border: 1px solid var(--line); background: var(--bg); width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-weight: 700; color: var(--muted); flex: none; }
.help-btn.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.help { background: var(--bg); border-radius: 12px; padding: 4px 12px; font-size: 14px; }
.help p { margin: 8px 0; }
.edit-row { border-bottom: 1px solid var(--line); }
.edit-row:last-child { border-bottom: 0; }
.edit-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 10px 0; border: 0; background: none; text-align: left; cursor: pointer; }
.edit-body { padding: 0 0 12px; }
.link.danger { color: var(--no); }
.new-block { border: 2px dashed var(--line); border-radius: 14px; padding: 12px; margin-top: 8px; }
.add-toggle { text-align: left; color: var(--text); font-weight: 600; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
