/* Daily Accountant — shared design system. Ledger-paper aesthetic, light + dark. */

:root {
  --bg: #f6f4ed;
  --surface: #fffdf8;
  --surface-2: #efece1;
  --ink: #1c2721;
  --muted: #64716a;
  --faint: #8b968f;
  --accent: #0d7a4e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0e8;
  --gold: #a17f00;
  --gold-soft: #f6ecce;
  --danger: #bf3a30;
  --danger-soft: #f9e5e3;
  --purple: #6d4fa1;
  --purple-soft: #ece5f6;
  --warn: #c77800;
  --border: #e0dccf;
  --border-strong: #c9c4b2;
  --shadow: 0 1px 2px rgba(28, 39, 33, 0.06), 0 8px 24px rgba(28, 39, 33, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #171e19;
    --surface-2: #1e2721;
    --ink: #e9e7dc;
    --muted: #9aa79f;
    --faint: #6d7a72;
    --accent: #3ecb8b;
    --accent-ink: #0b241a;
    --accent-soft: #16331f;
    --gold: #d9b13b;
    --gold-soft: #33290f;
    --danger: #e5695f;
    --danger-soft: #3a201d;
    --purple: #a98fd8;
    --purple-soft: #2a2138;
    --warn: #e09b3d;
    --border: #273129;
    --border-strong: #364439;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="light"] {
  --bg: #f6f4ed;
  --surface: #fffdf8;
  --surface-2: #efece1;
  --ink: #1c2721;
  --muted: #64716a;
  --faint: #8b968f;
  --accent: #0d7a4e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0e8;
  --gold: #a17f00;
  --gold-soft: #f6ecce;
  --danger: #bf3a30;
  --danger-soft: #f9e5e3;
  --purple: #6d4fa1;
  --purple-soft: #ece5f6;
  --warn: #c77800;
  --border: #e0dccf;
  --border-strong: #c9c4b2;
  --shadow: 0 1px 2px rgba(28, 39, 33, 0.06), 0 8px 24px rgba(28, 39, 33, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0f1411;
  --surface: #171e19;
  --surface-2: #1e2721;
  --ink: #e9e7dc;
  --muted: #9aa79f;
  --faint: #6d7a72;
  --accent: #3ecb8b;
  --accent-ink: #0b241a;
  --accent-soft: #16331f;
  --gold: #d9b13b;
  --gold-soft: #33290f;
  --danger: #e5695f;
  --danger-soft: #3a201d;
  --purple: #a98fd8;
  --purple-soft: #2a2138;
  --warn: #e09b3d;
  --border: #273129;
  --border-strong: #364439;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* ---------------- base ---------------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }
.big { font-size: 1.5rem; font-weight: 700; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}
.container.wide { max-width: 880px; }

/* ---------------- header ---------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 30;
}
.header-title {
  font-weight: 800;
  letter-spacing: 0.01em;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-side { display: flex; gap: 6px; min-width: 44px; }
.header-side.right { justify-content: flex-end; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }

/* ---------------- buttons ---------------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.07); background: var(--danger); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-big { font-size: 1.08rem; padding: 14px 24px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-small { min-height: 34px; padding: 5px 12px; font-size: 0.88rem; }

/* ---------------- cards & chips ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.flat { box-shadow: none; }
.card.selectable { cursor: pointer; transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s; }
.card.selectable:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow); }
.card.correct { border-color: var(--accent); background: var(--accent-soft); }
.card.wrong { border-color: var(--danger); background: var(--danger-soft); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
}
.chip-green { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-red { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.chip-gold { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }
.chip-purple { background: var(--purple-soft); border-color: var(--purple); color: var(--purple); }

/* ---------------- fingerprint bars & stats ---------------- */

.fbar { margin: 7px 0; }
.fbar .fbar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 3px;
}
.fbar .fbar-track {
  height: 14px;
  border-radius: 7px;
  background: var(--surface-2);
  overflow: hidden;
}
.fbar .fbar-fill {
  height: 100%;
  border-radius: 7px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.fbar.negative .fbar-fill { background: var(--danger); }

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--border);
  gap: 12px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-row .stat-value { font-family: var(--mono); font-weight: 700; }

/* ---------------- tables ---------------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table td.num, .data-table th.num { text-align: right; font-family: var(--mono); }
.data-table th { color: var(--muted); font-weight: 650; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: none; }

/* ---------------- inputs & search ---------------- */

.text-input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  min-height: 48px;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-wrap { position: relative; }
.search-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
  z-index: 40;
}
.search-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-item:hover, .search-item.active { background: var(--accent-soft); }
.search-item .sub { color: var(--faint); font-size: 0.8rem; margin-left: auto; }

/* ---------------- dots / progress pips ---------------- */

.dots { display: flex; gap: 8px; justify-content: center; }
.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  transition: background 0.2s, transform 0.2s;
}
.dot.on { background: var(--accent); border-color: var(--accent); transform: scale(1.15); }
.dot.bad { background: var(--danger); border-color: var(--danger); }
.dot.cur { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------- modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s;
}
.modal-backdrop.show .modal { transform: none; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; }

/* ---------------- toast ---------------- */

.toast-host {
  position: fixed;
  bottom: 22px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: none; }

/* ---------------- share block ---------------- */

.share-block {
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.7;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------- animations ---------------- */

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.pop { animation: pop 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.shake { animation: shakeX 0.4s both; }

@keyframes flipInY {
  0% { transform: rotateX(80deg); opacity: 0; }
  100% { transform: rotateX(0); opacity: 1; }
}
.flipIn { animation: flipInY 0.45s ease-out both; transform-origin: top center; }

@keyframes slideUpIn {
  0% { transform: translateY(14px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.slideUp { animation: slideUpIn 0.35s ease-out both; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fadeIn { animation: fadeIn 0.3s ease-out both; }

/* ---------------- misc ---------------- */

.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 750;
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
