:root {
  --navy: #16223b;
  --navy-2: #22324f;
  --yellow: #ffc928;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7486;
  --line: #e2e6ee;
  --soft: #f7f8fb;
  --accent: #0b6bff;
  --danger: #d33a3a;
  --ok: #138a4a;
  --top: #fff5d1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1522; --card: #182133; --text: #e7ebf3; --muted: #9aa4b8; --line: #2a3550;
    --soft: #1d2840; --accent: #5aa0ff; --danger: #ff7a7a; --ok: #5fd394; --top: #3a3217;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1522; --card: #182133; --text: #e7ebf3; --muted: #9aa4b8; --line: #2a3550;
  --soft: #1d2840; --accent: #5aa0ff; --danger: #ff7a7a; --ok: #5fd394; --top: #3a3217;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left)); padding-top: max(12px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.logo { width: 24px; height: 24px; border-radius: 6px; display: block; }
.top-btns { display: flex; gap: 6px; }
.top .ghost { color: #fff; border-color: rgba(255,255,255,.25); background: transparent; }
body:not([data-view="app"]) .only-app { display: none; }

main { max-width: 1040px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 13px; }

label { display: block; font-weight: 600; font-size: 14px; margin: 0 0 12px; }
label .muted { font-weight: 400; }
input[type=text], input[type=password], input:not([type]), input[inputmode], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--soft); font-weight: 400;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--card); }

button { cursor: pointer; border-radius: 10px; padding: 9px 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }
button:disabled { opacity: .6; cursor: wait; }
.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.primary:hover { background: var(--navy-2); }
.ghost:hover { border-color: var(--muted); }
.danger { color: var(--danger); }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-weight: 600; }
.msg { margin: 10px 0 0; font-size: 14px; color: var(--danger); min-height: 0; }
.msg:empty { display: none; }
.msg.ok { color: var(--ok); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.auth { max-width: 420px; margin: 40px auto; }
.auth .primary { width: 100%; padding: 12px; }

.notice { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.notice.warn { background: var(--top); border: 1px solid #f0d27a; }

.opts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--soft); }
.seg label { margin: 0; font-weight: 600; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 12px; font-size: 14px; cursor: pointer; }
.seg input:checked + span { background: var(--navy); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.inline select { width: auto; margin: 0; padding: 7px 10px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--navy); }
.go { margin-left: auto; min-width: 110px; padding: 10px 20px; }

.result-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.result-head h2 { display: inline; margin-right: 8px; }
.result-btns { display: flex; gap: 6px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { background: var(--soft); font-size: 13px; color: var(--muted); font-weight: 600; text-align: right; }
thead th.kw, thead th:nth-child(2) { text-align: left; }
tbody th.kw { text-align: left; font-weight: 700; background: var(--card); position: sticky; left: 0; z-index: 1; border-right: 1px solid var(--line); max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
thead th.kw { position: sticky; left: 0; z-index: 2; }
td.dev { color: var(--muted); font-size: 13px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.pos1 { background: var(--top); font-weight: 700; }
td.min { color: var(--muted); }
td.vol { color: var(--muted); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.foot { margin: 10px 2px 0; }

dialog.sheet { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(10, 16, 30, .5); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.x { border: 0; font-size: 24px; line-height: 1; padding: 2px 8px; background: none; }
.sheet .block { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sheet .block:last-child { border-bottom: 0; }
.sheet-foot { padding: 12px 18px; }
#token-box { display: block; margin: 8px 0 10px; padding: 10px; border-radius: 8px; background: var(--soft); word-break: break-all; font-size: 13px; user-select: all; }

.history { list-style: none; margin: 0; padding: 8px; }
.history li.muted { padding: 12px 10px; }
.history button { display: block; width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 10px; background: none; font-weight: 400; }
.history button:hover { background: var(--soft); }
.h-time { display: block; font-size: 12px; color: var(--muted); }
.h-kw { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .card { padding: 14px; }
  .seg { width: 100%; }
  .seg label { flex: 1; text-align: center; }
  .go { width: 100%; margin-left: 0; }
  th, td { padding: 8px 7px; font-size: 13px; }
  tbody th.kw { max-width: 110px; }
  dialog.sheet { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}
