:root {
  color-scheme: light;
  --bg: #f4f5f4; --card: #ffffff; --card2: #f0f2f1; --line: #dfe3e1; --strong: #c4cbc8;
  --text: #17201d; --muted: #5d6965; --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e0f1ee;
  --ok: #0f7a3d; --ok-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fbf0dc; --bad: #b42318; --bad-soft: #fdeceb;
  --chunk: #e9edeb; --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1312; --card: #171c1b; --card2: #1e2423; --line: #29302e; --strong: #3a4341;
    --text: #e6ece9; --muted: #96a29e; --accent: #3fb8a8; --accent-ink: #06201c; --accent-soft: #15302c;
    --ok: #5cc98a; --ok-soft: #13291d; --warn: #e3a948; --warn-soft: #2d2412; --bad: #f2827a; --bad-soft: #321716;
    --chunk: #232a29; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); min-height: 100vh;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, calc((100% - 860px) / 2)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.tabs { display: flex; gap: 4px; margin-left: auto; padding: 3px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 8px 10px; border-radius: 10px; color: var(--muted); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--card2); }
.menu .pop {
  position: absolute; right: 0; top: calc(100% + 6px); display: grid; min-width: 210px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu .pop button { text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.menu .pop button:hover { background: var(--card2); }

main { max-width: 860px; margin: 0 auto; padding: 18px 16px 60px; display: grid; gap: 14px; }
.panel { display: grid; gap: 14px; }

/* ---- controls */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.btn, button.primary, button.ghost, button.danger, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--strong); background: var(--card); font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.ghost:hover, .btn:hover, a.btn:hover { background: var(--card2); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
.small { min-height: 32px !important; padding: 0 10px !important; font-size: 14px !important; }
input[type=text], input[type=search], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--strong); background: var(--card2);
}
textarea { resize: vertical; }
label.field { display: grid; gap: 5px; font-size: 14px; color: var(--muted); font-weight: 600; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

/* ---- composer */
.composer { padding: 14px; display: grid; gap: 10px; }
.composer textarea { min-height: 96px; font-family: var(--mono); font-size: 14px; background: var(--card); border-color: var(--line); }
.composer .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.composer .row #title { flex: 1 1 180px; width: auto; }
.composer .row select { width: auto; }
.composer .row .spacer { flex: 1; }
.composer.drag { outline: 2px dashed var(--accent); outline-offset: 4px; }
.progress { height: 6px; border-radius: 3px; background: var(--card2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---- lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item { padding: 12px 14px; display: grid; gap: 8px; }
.item .head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.item .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item .meta { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.item .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.item pre {
  margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--card2); font: 13.5px/1.5 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 7.5em; overflow: hidden; position: relative;
}
.item pre.open { max-height: none; }
.item .thumb { max-width: 100%; max-height: 220px; border-radius: 10px; border: 1px solid var(--line); justify-self: start; }
.pin { color: var(--accent); font-size: 13px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.usage { text-align: center; color: var(--muted); font-size: 13px; margin: 0; }

/* ---- addresses */
.bar { display: flex; gap: 8px; flex-wrap: wrap; }
.bar input { flex: 1 1 200px; width: auto; }
.net { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.addr {
  font: 15px/1.9 var(--mono); padding: 8px 10px; border-radius: 10px; background: var(--card2);
  display: flex; flex-wrap: wrap; column-gap: 0; overflow-wrap: anywhere; cursor: copy; user-select: all;
}
.addr span { padding: 0 3px; margin-right: 4px; border-radius: 4px; }
.addr span:nth-child(odd) { background: var(--chunk); }
.addr span.end { font-weight: 800; color: var(--accent); }
.note { color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.verified { background: var(--ok-soft); color: var(--ok); }
.badge.unchecked { background: var(--card2); color: var(--muted); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* ---- dialogs */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(8, 12, 11, .45); }
dialog form, dialog .body { display: grid; gap: 12px; padding: 20px; }
dialog h2 { margin: 0; font-size: 19px; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog textarea { font-family: var(--mono); font-size: 14px; }
.check { font-size: 14px; margin: 0; min-height: 1.4em; }
.check.verified { color: var(--ok); } .check.bad { color: var(--bad); } .check.unchecked { color: var(--muted); }
.err { color: var(--bad); font-size: 14px; margin: 0; min-height: 1.2em; }
#qr-dialog img { width: 100%; max-width: 320px; justify-self: center; border-radius: 10px; background: #fff; }
#qr-dialog .mono { font: 13px/1.5 var(--mono); text-align: center; overflow-wrap: anywhere; margin: 0; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.log li { padding: 9px 11px; border-radius: 10px; background: var(--card2); font-size: 14px; display: grid; gap: 2px; }
.log .mono { font: 12.5px/1.4 var(--mono); overflow-wrap: anywhere; color: var(--muted); }
.log b.changed { color: var(--warn); } .log b.deleted { color: var(--bad); } .log b.added { color: var(--ok); }

#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login { width: min(380px, 100%); padding: 26px; display: grid; gap: 16px; }
.login h1 { margin: 0; font-size: 24px; }
.login form { display: grid; gap: 14px; }
.login button { min-height: 44px; }

@media (max-width: 560px) {
  .top { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .tabs button { flex: 1; }
  .menu { margin-left: auto; }
  .item .head { flex-wrap: wrap; }
  .item .meta { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.spacer { flex: 1; }
.offscreen { position: fixed; left: -9999px; opacity: 0; }

/* ---- share links */
.composer > #title { width: 100%; }
.opt { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.opt select { width: auto; }
.result { padding: 16px; display: grid; gap: 12px; justify-items: start; border-color: var(--accent); }
.result .hint { margin: 0; }
.link { font: 600 26px/1.2 var(--mono); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.link .host { color: var(--muted); font-weight: 500; }
.link b { color: var(--accent); letter-spacing: .06em; }
.small-link { font-size: 17px; }
.result img.qr { width: 180px; height: 180px; border-radius: 10px; background: #fff; }
h2.section { margin: 10px 2px 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.share .what { overflow-wrap: anywhere; }
.share form { display: grid; }
.shared {
  margin: 0; padding: 12px; border-radius: 10px; background: var(--card2); font: 14px/1.5 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow: auto;
}
.share { width: min(560px, 100%); }
