/* Onion City — warm, paper-like, quiet. */

:root {
  --paper: #f5eee3;
  --paper-2: #fbf7f0;
  --paper-3: #ece2d2;
  --line: #dccfbb;
  --line-2: #cbbba3;
  --ink: #2a2019;
  --ink-2: #5d5046;
  --ink-3: #8a7b6e;
  --accent: #c2603d;
  --accent-ink: #fff7f1;
  --accent-soft: #f3d9cc;
  --up: #3f7d4e;
  --up-soft: #d9e8d6;
  --down: #b3402f;
  --down-soft: #f1d4cc;
  --warn: #b98a1d;
  --warn-soft: #f4e6bf;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px -12px rgba(60, 40, 20, .18);
  --radius: 14px;
  --radius-s: 9px;
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #171310;
    --paper-2: #211b17;
    --paper-3: #2b231e;
    --line: #3a2f27;
    --line-2: #4b3d33;
    --ink: #f0e6d9;
    --ink-2: #c4b6a5;
    --ink-3: #8f8071;
    --accent: #e07a52;
    --accent-ink: #1d120c;
    --accent-soft: #46281d;
    --up: #7fbf8c;
    --up-soft: #23372a;
    --down: #e6796a;
    --down-soft: #46251f;
    --warn: #e0b34e;
    --warn-soft: #3f321a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --paper: #171310;
  --paper-2: #211b17;
  --paper-3: #2b231e;
  --line: #3a2f27;
  --line-2: #4b3d33;
  --ink: #f0e6d9;
  --ink-2: #c4b6a5;
  --ink-3: #8f8071;
  --accent: #e07a52;
  --accent-ink: #1d120c;
  --accent-soft: #46281d;
  --up: #7fbf8c;
  --up-soft: #23372a;
  --down: #e6796a;
  --down-soft: #46251f;
  --warn: #e0b34e;
  --warn-soft: #3f321a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.45;
  font-feature-settings: "tnum" 1, "cv11" 1;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 21px; }
h3 { font-size: 16.5px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.hidden { display: none !important; }
.signed-out .nav, .signed-out .tabs { display: none !important; }

.app { display: flex; flex-direction: column; min-height: 100dvh; }

/* top bar */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 50% 50% 48% 48% / 42% 42% 58% 58%;
  background: radial-gradient(circle at 35% 30%, #e8946f, var(--accent) 60%, #8d3f25);
  position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; left: 50%; top: -6px; width: 6px; height: 10px; margin-left: -3px;
  background: var(--up); border-radius: 60% 60% 20% 20%;
}
.brand-name { font-family: var(--display); font-weight: 700; font-size: 19px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a, .tabs a {
  color: var(--ink-2); padding: 7px 11px; border-radius: 999px; font-weight: 500;
}
.nav a.active, .tabs a.active { color: var(--ink); background: var(--paper-3); }
.nav a:hover { text-decoration: none; color: var(--ink); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.near-price { font-size: 13.5px; color: var(--ink-2); }
.near-price b { color: var(--ink); font-weight: 600; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--paper-2);
  font-size: 15px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--ink-3); }

/* bottom tabs on phones */
.tabs {
  display: none; position: sticky; bottom: 0; z-index: 20;
  border-top: 1px solid var(--line); background: var(--paper-2);
  padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  justify-content: space-around;
}
.tabs a { font-size: 12.5px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 8px; }
.tabs a span.ic { font-size: 18px; }
@media (max-width: 760px) {
  .nav { display: none; }
  .tabs { display: flex; }
  .near-price { display: none; }
}

/* main */
.main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 22px 16px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-2); margin-top: 4px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1.2fr .8fr; } }

.card {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin-bottom: 10px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.stat .value { font-family: var(--display); font-size: 26px; font-weight: 600; line-height: 1.15; }
.stat .value.small { font-size: 19px; }
.stat .hint { font-size: 13px; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px 18px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; padding-top: 4px; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; font-variant-numeric: tabular-nums; }
.list { margin: 0; padding: 0; list-style: none; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; background: var(--paper-3); color: var(--ink-2);
}
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--paper-2); color: var(--ink);
  padding: 9px 14px; border-radius: var(--radius-s); font-weight: 600; line-height: 1.2;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.buy { background: var(--up); border-color: var(--up); color: #fff; }
.btn.sell { background: var(--down); border-color: var(--down); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13.5px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, var(--line-2)); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }

/* inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-s); border: 1px solid var(--line-2);
  background: var(--paper); color: var(--ink); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { font-size: 20px; padding: 14px 16px; font-family: var(--display); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.help { font-size: 13px; color: var(--ink-3); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--line-2); position: relative; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--up); }
.switch input:checked::after { left: 19px; }

/* paste box */
.paste {
  display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 16px;
  background: var(--paper-2); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.paste .input { border: 0; background: transparent; font-size: 17px; padding: 10px 8px; }
.paste .input:focus { box-shadow: none; }

/* notices */
.notice { padding: 12px 14px; border-radius: var(--radius-s); background: var(--paper-3); border: 1px solid var(--line); font-size: 14px; }
.notice.warn { background: var(--warn-soft); border-color: transparent; }
.notice.down { background: var(--down-soft); border-color: transparent; }
.notice.up { background: var(--up-soft); border-color: transparent; }
.empty { text-align: center; padding: 34px 12px; color: var(--ink-2); }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* trades */
.trade-panel { display: grid; gap: 14px; align-content: start; }
.side-tabs { display: inline-flex; align-items: center; justify-self: start; align-self: start; padding: 3px; border-radius: 999px; background: var(--paper-3); }
.side-tabs button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; font-weight: 600; color: var(--ink-2); }
.side-tabs button.active.buy { background: var(--up); color: #fff; }
.side-tabs button.active.sell { background: var(--down); color: #fff; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14.5px; }
.kv dt { color: var(--ink-2); margin: 0; }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.progress { display: flex; align-items: center; gap: 10px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.line-ok::before { content: "✓ "; color: var(--up); }
.line-bad::before { content: "✕ "; color: var(--down); }
.line-wait::before { content: "… "; color: var(--warn); }

/* chart */
.chart-wrap { position: relative; }
.chart-wrap canvas { width: 100%; height: 240px; display: block; }
.chart-tip { display: none; position: absolute; top: 8px; left: 0; pointer-events: none; background: var(--paper-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 9px; font-size: 12px; line-height: 1.45; box-shadow: var(--shadow); min-width: 150px; }
.side-tabs.small button { padding: 4px 8px; font-size: 12.5px; }
.chart-card .card-head { flex-wrap: wrap; }
.side-tabs.small button.active { background: var(--ink); color: var(--paper); }

/* table */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.r, .table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* login */
.login { max-width: 440px; margin: 8vh auto 0; }
.login .steps { margin: 14px 0 0; padding-left: 20px; color: var(--ink-2); }
.login .steps li { margin: 6px 0; }
.code-input { letter-spacing: .5em; text-align: center; font-family: var(--mono); font-size: 26px; padding: 14px; }

/* modal */
.modal-root:empty { display: none; }
.modal-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(20, 12, 6, .45); padding: 12px; }
@media (min-width: 640px) { .modal-root { align-items: center; } }
.modal { width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto; background: var(--paper-2); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.modal h2 { margin-bottom: 8px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.secret { font-family: var(--mono); font-size: 14px; padding: 12px; border-radius: var(--radius-s); background: var(--paper); border: 1px dashed var(--line-2); word-break: break-all; user-select: all; }
.words { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.words span { padding: 6px 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 13px; }
.words span i { color: var(--ink-3); font-style: normal; margin-right: 6px; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 420px); }
@media (min-width: 761px) { .toasts { bottom: 24px; } }
.toast { padding: 11px 14px; border-radius: 12px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: 14px; animation: rise .18s ease; }
.toast.bad { background: var(--down); color: #fff; }
.toast.good { background: var(--up); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--paper-3), var(--line), var(--paper-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--paper-3); font-size: 13.5px; }
.tag button { border: 0; background: transparent; color: var(--ink-3); padding: 0 2px; font-size: 15px; }
.tag button:hover { color: var(--down); }
.section-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 18px 0 8px; font-weight: 600; }
