:root {
  --paper: #F7F4EC;
  --paper-raised: #FCFAF4;
  --ink: #2B2B26;
  --ink-soft: #5C574C;
  --line: #D8D2C2;
  --rust: #A8632C;
  --rust-dark: #8A4F22;
  --moss: #4A6B4F;
  --moss-soft: #DCE6DD;
  --danger: #9C4434;

  --font-mono: ui-monospace, "SF Mono", "Menlo", "Cascadia Mono", monospace;
  --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(ellipse at top left, rgba(168,99,44,0.04), transparent 50%);
}

.hidden { display: none !important; }

/* ---------- Login ---------- */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.brand {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--ink);
}

.brand-sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 32px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input, select, textarea {
  font-family: var(--font-sans);
  font-size: 16px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--paper-raised);
  color: var(--ink);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--rust);
}

.primary-btn {
  background: var(--rust);
  color: var(--paper-raised);
  border: none;
  border-radius: 8px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.primary-btn:hover { background: var(--rust-dark); }
.primary-btn:focus-visible { outline: 2px solid var(--rust-dark); outline-offset: 2px; }

.ghost-btn {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--ink-soft); color: var(--ink); }

.link-btn {
  background: none;
  border: none;
  color: var(--rust);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s ease;
}
.link-btn:hover { text-decoration-color: var(--rust); }

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 12px;
}

/* ---------- App shell ---------- */

#app-screen {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 8px;
}

.topbar .brand { font-size: 22px; margin: 0; }

.main { display: flex; flex-direction: column; gap: 28px; }

/* ---------- Gauge ---------- */

.gauge-card {
  background: var(--paper-raised);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.gauge-wrap {
  position: relative;
  width: 200px;
  height: 200px;
}

.gauge-svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.gauge-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 14;
}

.gauge-fill {
  fill: none;
  stroke: var(--rust);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 553;
  stroke-dashoffset: 553;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.3s ease;
}

.gauge-fill.complete { stroke: var(--moss); }

.gauge-center {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge-amount {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
  color: var(--ink);
}

.gauge-goal {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.gauge-stats {
  display: flex;
  width: 100%;
  justify-content: space-around;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }

.stat-num {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.stat-label {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Add button ---------- */

.add-section { display: flex; }
.add-section .primary-btn { width: 100%; }

/* ---------- Form card ---------- */

.form-card {
  background: var(--paper-raised);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.form-card h2 { margin: 0 0 16px; font-size: 17px; }

#item-form { display: flex; flex-direction: column; gap: 14px; }

#item-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.optional { font-weight: 400; text-transform: none; color: var(--ink-soft); opacity: 0.8; }

.row { display: flex; gap: 12px; }
.row label { flex: 1; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

/* ---------- List ---------- */

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-header h2 { font-size: 17px; margin: 0; }

#filter-select { width: auto; padding: 8px 12px; font-size: 13px; }

.items-list { display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  color: var(--ink-soft);
  font-size: 14px;
  text-align: center;
  padding: 32px 0;
  font-style: italic;
}

.item-card {
  background: var(--paper-raised);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.item-card:hover { border-color: var(--rust); }

.item-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.item-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  gap: 8px;
  align-items: center;
}

.category-tag {
  background: var(--moss-soft);
  color: var(--moss);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 5px;
}

.item-links {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.item-link {
  font-size: 11px;
  color: var(--rust);
  text-decoration: none;
  font-weight: 600;
}

.item-link:hover { text-decoration: underline; }

.link-sep {
  color: var(--line);
  font-size: 11px;
}

.item-profit {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  text-align: right;
}

.item-profit.positive { color: var(--moss); }
.item-profit.pending { color: var(--ink-soft); font-size: 13px; font-weight: 500; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(43,43,38,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  background: var(--paper-raised);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
}

.modal-card h2 { margin: 0 0 16px; font-size: 17px; }

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 18px;
}

/* ---------- Responsive ---------- */

@media (min-width: 600px) {
  .gauge-card { padding: 32px 32px 24px; }
}
