@import url('https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@500;700&family=Noto+Sans+JP:wght@400;500&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --ink: #0d0d0f;
  --panel: #17171a;
  --panel-raised: #1e1e22;
  --hairline: #2c2c30;
  --washi: #ede6d6;
  --washi-dim: #a8a296;
  --shu: #b7282e;
  --shu-bright: #e2431e;
  --gold: #c9a961;
  --jade: #4a7c59;
  --jade-bright: #6fae82;
  --font-display: 'Shippori Mincho', serif;
  --font-body: 'Noto Sans JP', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--washi);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------- Auth pages ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 40px 32px;
  text-align: center;
}
.brand {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--shu-bright);
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.brand-sub {
  display: block;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--washi-dim);
  margin-bottom: 28px;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.auth-form label { font-size: 13px; color: var(--washi-dim); display: flex; flex-direction: column; gap: 6px; }
.auth-form input, .auth-form select {
  background: var(--ink);
  border: 1px solid var(--hairline);
  color: var(--washi);
  padding: 11px 12px;
  border-radius: 3px;
  font-size: 15px;
  font-family: var(--font-body);
}
.auth-form input:focus, .auth-form select:focus { outline: none; border-color: var(--shu); }
.auth-form button, .btn-primary {
  background: var(--shu);
  color: var(--washi);
  border: none;
  padding: 12px;
  border-radius: 3px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
}
.auth-form button:hover, .btn-primary:hover { background: var(--shu-bright); }
.auth-switch { margin-top: 20px; font-size: 13px; color: var(--washi-dim); }
.auth-switch a { color: var(--gold); text-decoration: none; }
.alert {
  background: rgba(183, 40, 46, 0.15);
  border: 1px solid var(--shu);
  color: var(--washi);
  padding: 10px 12px;
  border-radius: 3px;
  font-size: 13px;
  margin-bottom: 20px;
}

/* ---------- App shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}
.brand-block { display: flex; flex-direction: column; }
.topbar .brand { font-size: 22px; margin: 0; }
.topbar .brand-sub { margin: 0; font-size: 10px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.last-updated { font-size: 11px; color: var(--washi-dim); font-family: var(--font-mono); }
.icon-btn {
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--washi);
  width: 34px; height: 34px;
  border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px;
  text-decoration: none;
}
.icon-btn:hover { border-color: var(--shu); color: var(--shu-bright); }

.totals-strip {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 20px;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.totals-block { display: flex; flex-direction: column; gap: 4px; }
.totals-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--washi-dim); }
.totals-figure { font-family: var(--font-mono); font-size: 24px; font-weight: 500; }
.currency-toggle {
  margin-left: auto;
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--gold);
  padding: 6px 14px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}

.search-section { padding: 20px; border-bottom: 1px solid var(--hairline); }
.search-wrap { position: relative; max-width: 480px; }
.search-wrap input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--washi);
  padding: 12px 14px;
  border-radius: 3px;
  font-size: 15px;
  font-family: var(--font-body);
}
.search-wrap input:focus { outline: none; border-color: var(--shu); }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}
.search-results.hidden { display: none; }
.search-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--hairline);
}
.search-row:last-child { border-bottom: none; }
.search-row:hover { background: rgba(183, 40, 46, 0.12); }
.type-badge {
  font-size: 10px; font-family: var(--font-mono);
  padding: 2px 6px; border-radius: 2px;
  text-transform: uppercase;
}
.type-badge.crypto { background: rgba(201, 169, 97, 0.2); color: var(--gold); }
.type-badge.stock { background: rgba(74, 124, 89, 0.2); color: var(--jade-bright); }
.search-symbol { font-family: var(--font-mono); font-weight: 700; }
.search-name { color: var(--washi-dim); font-size: 13px; }

.ledger-section { padding: 0 20px 20px; overflow-x: auto; }
.ledger { width: 100%; border-collapse: collapse; margin-top: 16px; min-width: 560px; }
.ledger th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--washi-dim); padding: 8px 10px; border-bottom: 1px solid var(--hairline);
}
.ledger td { padding: 12px 10px; border-bottom: 1px solid var(--hairline); font-size: 14px; vertical-align: middle; }
.ledger td.num { font-family: var(--font-mono); text-align: right; }
.empty-row td { color: var(--washi-dim); text-align: center; padding: 30px 10px; font-style: italic; }
.asset-cell { display: flex; flex-direction: column; gap: 2px; }
.asset-cell-link { cursor: pointer; }
.asset-cell-link:hover .asset-symbol { color: var(--shu-bright); text-decoration: underline; }
.asset-symbol { font-family: var(--font-mono); font-weight: 700; }
.asset-cat { font-size: 11px; color: var(--gold); }
.lev-badge {
  font-family: var(--font-mono); font-size: 10px;
  background: rgba(226, 67, 30, 0.15); color: var(--shu-bright);
  padding: 1px 5px; border-radius: 2px; margin-left: 6px;
}
.pnl-positive { color: var(--jade-bright); }
.pnl-negative { color: var(--shu-bright); }
.remove-btn {
  background: none; border: none; color: var(--washi-dim);
  cursor: pointer; font-size: 16px;
}
.remove-btn:hover { color: var(--shu-bright); }

.ai-section { padding: 0 20px 40px; }
.seal-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--gold);
  color: var(--gold); padding: 12px 20px; border-radius: 3px;
  cursor: pointer; font-size: 14px; font-family: var(--font-body);
}
.seal-btn:hover { background: rgba(201, 169, 97, 0.1); }
.seal {
  font-family: var(--font-display);
  background: var(--shu); color: var(--washi);
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.ai-panel {
  margin-top: 16px; background: var(--panel); border: 1px solid var(--hairline);
  border-left: 3px solid var(--shu); border-radius: 3px; padding: 20px;
  white-space: pre-wrap; line-height: 1.7; font-size: 14px; max-width: 640px;
}
.ai-panel.hidden { display: none; }
.ai-panel.loading { color: var(--washi-dim); font-style: italic; }
.ai-ask-row { display: flex; gap: 10px; margin-top: 20px; max-width: 640px; }
.ai-ask-row input {
  flex: 1; background: var(--panel); border: 1px solid var(--hairline); color: var(--washi);
  padding: 11px 14px; border-radius: 3px; font-size: 14px; font-family: var(--font-body);
}
.ai-ask-row input:focus { outline: none; border-color: var(--shu); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel-raised); border: 1px solid var(--hairline);
  border-radius: 4px; padding: 28px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 16px;
}
.modal-card h2 { margin: 0; font-family: var(--font-display); font-size: 20px; color: var(--shu-bright); }
.modal-card label { font-size: 13px; color: var(--washi-dim); display: flex; flex-direction: column; gap: 6px; }
.modal-card input, .modal-card select {
  background: var(--ink); border: 1px solid var(--hairline); color: var(--washi);
  padding: 10px 12px; border-radius: 3px; font-size: 15px;
}
.checkbox-row { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-row input { width: auto; }
.leverage-fields { display: flex; gap: 12px; }
.leverage-fields.hidden { display: none; }
.leverage-fields label { flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.btn-ghost {
  background: none; border: 1px solid var(--hairline); color: var(--washi-dim);
  padding: 10px 16px; border-radius: 3px; cursor: pointer; font-size: 14px;
}
.btn-primary { padding: 10px 18px; font-size: 14px; margin-top: 0; }
.hint { font-size: 12px; color: var(--washi-dim); margin: -8px 0 0; }
.hint a { color: var(--gold); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .topbar .brand { font-size: 18px; }
  .last-updated { display: none; }
  .totals-strip { padding: 16px; gap: 20px; }
  .totals-figure { font-size: 20px; }
  .search-section, .ledger-section, .ai-section { padding-left: 16px; padding-right: 16px; }
  .ledger th:nth-child(3), .ledger td:nth-child(3) { display: none; } /* hide Avg column on small screens */
}
