:root{
  --bg-top: #eaf6ff;
  --bg-bottom: #fff6ea;
  --panel: #ffffff;
  --panel-line: #ffe2c2;
  --ink: #4a3527;
  --ink-soft: #9a8878;
  --gold: #ffb74d;
  --gold-dim: #ff9800;
  --blue: #42a5f5;
  --blue-dim: #1e88e5;
  --red: #ff6fa5;
  --red-dim: #ec407a;
  --white-f: #c9a97e;
  --green: #66bb6a;
  --green-dim: #43a047;
  --danger: #ef5350;
  --header-a: #8bc34a;
  --header-b: #cddc39;
  --surface: #fffdf9;
  --surface-alt: #fff8ec;
  --surface-alt-active: #ffedcc;
  --code-bg: #fff3e0;
  --overlay-bg: rgba(74,53,39,0.55);
}
:root[data-theme="dark"]{
  --bg-top: #182430;
  --bg-bottom: #10161d;
  --panel: #212e3a;
  --panel-line: #33424f;
  --ink: #e9edf0;
  --ink-soft: #93a2ac;
  --gold: #ffb74d;
  --gold-dim: #ffa726;
  --blue: #64b5f6;
  --blue-dim: #42a5f5;
  --red: #ff8fbd;
  --red-dim: #ff6fa5;
  --white-f: #7c8a95;
  --green: #81c784;
  --green-dim: #66bb6a;
  --danger: #ff6f6a;
  --header-a: #33691e;
  --header-b: #558b2f;
  --surface: #1a2530;
  --surface-alt: #1e2a35;
  --surface-alt-active: #24333f;
  --code-bg: #2a3b4a;
  --overlay-bg: rgba(0,0,0,0.6);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-bottom);
  color: var(--ink);
  font-family: 'M PLUS Rounded 1c', sans-serif;
}
button { touch-action: manipulation; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.ledger {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 55%);
  padding: 24px 18px 60px;
}

.masthead {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto 22px;
  position: sticky;
  top: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  background: linear-gradient(90deg, var(--header-a), var(--header-b));
  border-radius: 18px;
  padding: 16px 22px;
  box-shadow: 0 4px 14px rgba(139,195,74,0.35);
}
.masthead h1 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-weight: 800;
  font-size: 28px;
  color: #fff;
  margin: 0;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 3px rgba(70,90,20,0.25);
}
.masthead p {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 1px 2px rgba(70,90,20,0.2);
}
.masthead-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.masthead-menu {
  display: flex;
  gap: 8px;
}
.masthead-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 16px;
  min-height: 36px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  color: #558b2f;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 5px rgba(0,0,0,0.12);
  position: relative;
  z-index: 1;
}
.masthead-btn:hover { background: #fff; }
.masthead-btn:focus-visible { outline: 2px solid var(--blue-dim); outline-offset: 2px; }

.layout {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: none;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 3px 14px rgba(139,120,90,0.1);
}
.panel h2 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 14px;
  color: var(--green-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.panel .hint {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin: -6px 0 6px;
}
.panel .hint code {
  background: var(--code-bg);
  border-radius: 5px;
  padding: 1px 5px;
}

.dropzone {
  border: 2px dashed var(--gold);
  border-radius: 14px;
  background: var(--surface-alt);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}
.dropzone.drag {
  background: var(--surface-alt-active);
  border-color: var(--gold-dim);
}
.dropzone img {
  max-width: 100%;
  max-height: 160px;
  display: block;
  margin: 0 auto 10px;
}
.dropzone input[type=file] { display: none; }

.btn {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 14px;
  font-weight: 800;
  padding: 11px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  width: 100%;
  margin-top: 12px;
  box-shadow: 0 3px 8px rgba(255,152,0,0.35);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--blue-dim); outline-offset: 2px;
}
.btn.secondary {
  background: var(--panel);
  color: var(--gold-dim);
  border: 2px solid var(--gold);
  box-shadow: none;
}
.btn.secondary:hover { background: var(--surface-alt); }
.btn.btn-inline {
  width: auto;
  margin-top: 0;
  padding: 6px 14px;
  font-size: 11px;
}

.status {
  font-size: 12px;
  margin-top: 10px;
  color: var(--ink-soft);
  min-height: 16px;
  font-weight: 600;
}
.status.error { color: var(--danger); }

.form-grid {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
label {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 700;
  display: block;
  margin-bottom: 3px;
}
input[type=text], input[type=number], input[type=password], textarea {
  width: 100%;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 13px;
  padding: 8px 10px;
  border: 1.5px solid var(--panel-line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
input[type=text]:focus, input[type=number]:focus, textarea:focus {
  border-color: var(--blue);
}
.factor-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.factor-row input[type=text] { flex: 1; }
.factor-row input[type=number] { width: 52px; }
.factor-list-edit { display: flex; flex-direction: column; gap: 6px; }
.add-line { font-size: 12px; color: var(--green-dim); font-weight: 700; background: none; border: none; cursor: pointer; padding: 2px 0; text-align: left; }
.remove-line { font-size: 13px; color: var(--danger); font-weight: 700; background: none; border: none; cursor: pointer; padding: 0 4px; }

.stack-header {
  display: flex;
  gap: 6px;
  font-size: 10px;
  color: var(--ink-soft);
  font-weight: 700;
  margin-bottom: 2px;
}
.stack-header span:nth-child(1) { flex: 1; }
.stack-header span:nth-child(2),
.stack-header span:nth-child(3),
.stack-header span:nth-child(4) { width: 44px; text-align: center; }
.stack-header span:nth-child(5) { width: 20px; }
.stack-factor-row { display: flex; gap: 6px; align-items: center; }
.stack-factor-row input[type=text] { flex: 1; }
.stack-factor-row input[type=checkbox] { width: 44px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--green-dim); }

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-field {
  flex: 1;
  min-width: 200px;
}
.search-field label {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 700;
  margin-bottom: 3px;
}
.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 38px;
  padding: 5px 8px;
  border: 1.5px solid var(--panel-line);
  border-radius: 10px;
  background: var(--surface);
}
.tag-input:focus-within { border-color: var(--blue); }
.tag-input input[type=text] {
  flex: 1;
  width: auto;
  min-width: 80px;
  border: none;
  padding: 3px 2px;
  background: transparent;
}
.tag-input input[type=text]:focus { outline: none; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--gold);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.tag-chip.optional { background: var(--blue-dim); }
.tag-remove {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.tag-remove:hover { opacity: 0.7; }

.entries { display: flex; flex-direction: column; gap: 10px; }
.entry {
  border: 1.5px solid var(--panel-line);
  border-radius: 14px;
  background: var(--surface);
  padding: 14px 16px;
}
.entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.entry-name {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-weight: 800;
  font-size: 16px;
  color: var(--green-dim);
}
.entry-parents {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.chip.blue { background: linear-gradient(135deg, #64b5f6, var(--blue-dim)); }
.chip.red { background: linear-gradient(135deg, #ff8fbd, var(--red-dim)); }
.chip.green { background: linear-gradient(135deg, #81c784, var(--green-dim)); }
.chip.white { background: var(--panel); color: var(--ink-soft); border: 1.5px solid var(--white-f); }
.chip.muted { opacity: 0.45; }
.chip.search-match {
  outline: 2px solid #00e5ff;
  outline-offset: 2px;
  animation: chip-neon-glow 1.8s ease-in-out infinite alternate;
}
@keyframes chip-neon-glow {
  0% {
    outline-color: #00e5ff;
    box-shadow: 0 0 5px 1px #00e5ff, 0 0 10px 2px rgba(0,229,255,0.55);
  }
  100% {
    outline-color: #ff2fd1;
    box-shadow: 0 0 5px 1px #ff2fd1, 0 0 10px 2px rgba(255,47,209,0.55);
  }
}
mark.search-hit {
  background: #fff176;
  color: #4a3527;
  padding: 0 1px;
  border-radius: 3px;
}
.entry-notes { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }
.entry-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.entry-edit, .entry-del {
  font-size: 12px;
  font-weight: 700;
  background: none;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.entry-edit {
  color: var(--blue-dim);
  border: 1.5px solid var(--blue-dim);
}
.entry-edit:hover { background: var(--blue-dim); color: #fff; }
.entry-del {
  color: var(--danger);
  border: 1.5px solid var(--danger);
}
.entry-del:hover { background: var(--danger); color: #fff; }

.empty {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 20px 4px;
  text-align: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: none;
  border-radius: 20px;
  padding: 22px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(74,53,39,0.3);
}
#registerModal {
  max-width: 560px;
}
.modal h2 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 14px;
  color: var(--green-dim);
}
.modal textarea {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  line-height: 1.5;
}
.modal .btn:last-of-type,
.modal .modal-close-btn {
  margin-top: 10px;
}
