:root {
  --panel: #1c1b19;
  --on-panel: #f2ece0;
  --on-panel-muted: rgb(242 236 224 / .7);
  --on-panel-line: rgb(242 236 224 / .25);
  --bg: #f2ece0;
  --fg: #151515;
  --muted: #55534d;
  --faint: #6b6860;
  --line: #d9d0bf;
  --accent: #b84518;
  --green: #17693a;
  --font: "Schibsted Grotesk", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --panel: #22211e;
    --bg: #121211;
    --fg: #ece8de;
    --muted: #a9a59b;
    --faint: #8b877e;
    --line: #2e2d2a;
    --accent: #ec7a45;
    --green: #52c584;
  }
  .side { border-right: 1px solid var(--line); }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
ul { list-style: none; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.skip {
  position: fixed; top: 12px; left: 12px; z-index: 100;
  padding: 8px 14px;
  background: var(--on-panel); color: var(--panel);
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

.wrap {
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

/* side panel */
.side {
  position: sticky; top: 0;
  height: 100vh;
  padding: 32px 28px 24px;
  display: flex; flex-direction: column; gap: 24px;
  background: var(--panel);
  color: var(--on-panel);
}
.side-top { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.side-tools { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 14px; }
.back { color: var(--on-panel-muted); text-decoration: none; padding: 4px 0; }
.back:hover { color: var(--on-panel); }
.lang { display: flex; align-items: center; gap: 6px; }
.lang button { min-height: 32px; padding: 4px 2px; color: var(--on-panel-muted); }
.lang button:hover { color: var(--on-panel); }
.lang button[aria-pressed="true"] { color: var(--on-panel); text-decoration: underline; text-underline-offset: 4px; }
.lang span { color: var(--on-panel-line); }

.name {
  margin-top: 28px;
  font-weight: 800;
  font-size: 58px;
  line-height: .9;
  letter-spacing: -.05em;
}
.lead { margin-top: 16px; font-size: 15px; color: var(--on-panel-muted); }

.ledger-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 28px; padding-bottom: 10px;
  border-bottom: 1px solid var(--on-panel-line);
}
.ledger-title { font-size: 15px; font-weight: 700; }

.ledger { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -8px; padding-top: 6px; }
.ledger button {
  display: block; width: 100%; min-height: 48px;
  padding: 7px 8px;
  text-align: left;
  color: var(--on-panel-muted);
  transition: background .15s, color .15s;
}
.ledger button:hover { background: rgb(242 236 224 / .08); color: var(--on-panel); }
.ledger button[aria-current="true"] { background: var(--on-panel); color: var(--panel); }
.ledger-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-addr { display: block; font-family: var(--mono); font-size: 12px; opacity: .8; }
.ledger-empty { padding: 10px 8px; font-size: 14px; color: var(--on-panel-muted); }

.side-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; font-size: 14px; }
.link {
  min-height: 36px;
  color: var(--on-panel-muted);
  text-decoration: underline; text-underline-offset: 4px;
  text-decoration-color: var(--on-panel-line);
}
.link:hover { color: var(--on-panel); }

/* buttons */
.btn {
  min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--fg);
  font-size: 14px; font-weight: 600;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.btn:hover:not(:disabled) { background: var(--fg); color: var(--bg); }
.btn-solid { background: var(--fg); color: var(--bg); }
.btn-panel { min-height: 36px; padding: 4px 12px; border-color: var(--on-panel); }
.btn-panel:hover:not(:disabled) { background: var(--on-panel); color: var(--panel); }

/* content */
.content { width: 100%; max-width: 1120px; padding: 40px clamp(20px, 4vw, 56px) 48px; }

.empty { max-width: 56ch; padding-top: 12vh; }
.empty h2 { font-size: clamp(30px, 3.4vw, 42px); font-weight: 800; line-height: 1.08; letter-spacing: -.035em; text-wrap: balance; }
.empty p { margin-top: 14px; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.wallet-head h2 {
  font-size: clamp(30px, 3.6vw, 46px); font-weight: 800;
  line-height: 1.05; letter-spacing: -.04em;
  overflow-wrap: anywhere;
}
.address-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 8px; }
.address { font-family: var(--mono); font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.inline-btn {
  min-height: 32px; padding: 2px 0;
  font-size: 14px; font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--accent);
}
.inline-btn:hover { color: var(--accent); }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.updated { margin-left: auto; font-size: 13px; color: var(--faint); }

.message { margin-top: 24px; padding: 14px 16px; border: 1px solid var(--line); color: var(--muted); }
.message.error { border-color: var(--accent); color: var(--fg); }
.message .inline-btn { margin-left: 8px; }

.block { margin-top: 40px; }
.block-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.block-head h3 { font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.total { font-size: 15px; font-weight: 600; color: var(--muted); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.segment { display: flex; border: 1px solid var(--line); }
.segment button { min-height: 36px; padding: 3px 12px; font-size: 14px; font-weight: 500; }
.segment button + button { border-left: 1px solid var(--line); }
.segment button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.check { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th {
  padding: 8px 12px 8px 0;
  border-bottom: 2px solid var(--fg);
  font-size: 13px; font-weight: 600; text-align: left; color: var(--muted);
}
td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th:last-child, td:last-child { padding-right: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.token-name { font-weight: 600; }
.token-full { display: block; font-size: 13px; color: var(--faint); }
.unverified { display: inline-block; margin-left: 6px; padding: 0 5px; border: 1px solid var(--faint); font-size: 11px; font-weight: 600; color: var(--muted); }

.when { display: block; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ago { display: block; font-size: 13px; color: var(--faint); }
.dir { font-weight: 600; white-space: nowrap; }
.dir.in { color: var(--green); }
.dir.out { color: var(--accent); }
.dir.self { color: var(--muted); }
.party {
  padding: 2px 0;
  font-family: var(--mono); font-size: 13px; text-align: left;
  text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px;
}
.party.named { font-family: var(--font); font-size: 14px; font-weight: 600; }
.party:hover { color: var(--accent); }
.amount { font-weight: 600; white-space: nowrap; }
.tx-link { display: inline-block; padding: 0 4px; text-decoration: none; font-weight: 700; }
.tx-link:hover { color: var(--accent); }

.note { margin-top: 10px; font-size: 13px; color: var(--faint); }

/* dialog */
.modal {
  margin: 14vh auto auto;
  width: min(460px, calc(100% - 32px));
  padding: 24px;
  border: 2px solid var(--fg);
  background: var(--bg); color: var(--fg);
  box-shadow: 8px 8px 0 var(--panel);
}
.modal::backdrop { background: rgb(0 0 0 / .4); }
.modal h2 { font-size: 24px; font-weight: 800; letter-spacing: -.03em; margin-bottom: 14px; }
.modal label { display: block; margin-top: 12px; font-size: 14px; font-weight: 600; }
.modal label b { font-weight: 600; }
.modal label span { font-weight: 400; color: var(--faint); }
.modal input {
  width: 100%; min-height: 44px; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--faint); border-radius: 0;
  background: transparent; color: inherit;
  font: inherit; font-size: 15px;
}
.modal input[readonly] { color: var(--muted); border-style: dashed; }
#wallet-address { font-family: var(--mono); font-size: 14px; }
.form-error { min-height: 22px; margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  padding: 10px 16px;
  background: var(--panel); color: var(--on-panel);
  font-size: 14px; font-weight: 600;
  opacity: 0; transform: translate(-50%, 8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* responsive */
@media (max-width: 860px) {
  .wrap { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; padding: 20px 20px 16px; }
  .name { margin-top: 16px; font-size: 48px; }
  .ledger { max-height: 240px; }
  .content { padding: 28px 20px 40px; }
  .updated { margin-left: 0; width: 100%; }
}

@media (max-width: 720px) {
  .token-table thead, .tx-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .token-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 0 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
  }
  .token-table td { display: block; padding: 0; border: 0; }
  .token-table .c-token { grid-column: 1; grid-row: 1 / span 2; }
  .token-table .c-balance { grid-column: 2; grid-row: 1; overflow-wrap: anywhere; }
  .token-table .c-usd { grid-column: 2; grid-row: 2; font-size: 13px; color: var(--faint); overflow-wrap: anywhere; }
  .token-table .c-usd.none { display: none; }
  .amount { white-space: normal; overflow-wrap: anywhere; }
  .tx-table tr {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }
  .tx-table td { display: block; padding: 0; border: 0; }
  .tx-table .c-time { grid-column: 1; grid-row: 1; }
  .tx-table .c-dir { grid-column: 2; grid-row: 1; text-align: right; }
  .tx-table .c-amount { grid-column: 1; grid-row: 2; text-align: left; margin-top: 4px; }
  .tx-table .c-link { grid-column: 2; grid-row: 2; text-align: right; margin-top: 4px; }
  .tx-table .c-from, .tx-table .c-to { grid-column: 1 / -1; font-size: 14px; }
  .tx-table .c-from::before, .tx-table .c-to::before {
    content: attr(data-label) " ";
    color: var(--faint); font-size: 13px;
  }
  .tx-link { padding: 4px 8px; }
  .party { padding: 5px 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
