:root {
  --bg: #f2f4f6;
  --card: #ffffff;
  --fill: #f2f4f6;
  --fill-strong: #e5e8eb;
  --text: #191f28;
  --sub: #4e5968;
  --muted: #8b95a1;
  --line: #e5e8eb;
  --accent: #3182f6;
  --accent-soft: #e8f3ff;
  --on-accent: #ffffff;
  --red: #f04452;
  --blue: #3182f6;
  --green: #03a94d;
  --green-soft: #e5f8ed;
  --amber: #c26a00;
  --amber-soft: #fff4e0;
  --error-soft: #ffeeee;
  --switch-off: #d1d6db;
  --bar: rgba(242, 244, 246, 0.86);
  --shadow: 0 1px 2px rgba(0, 27, 55, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171c;
    --card: #202027;
    --fill: #2c2c35;
    --fill-strong: #3c3c47;
    --text: #e4e4e5;
    --sub: #c3c3c6;
    --muted: #9e9ea4;
    --line: #2c2c35;
    --accent: #4593fc;
    --accent-soft: rgba(69, 147, 252, 0.16);
    --red: #f66570;
    --blue: #4593fc;
    --green: #2fca73;
    --green-soft: rgba(47, 202, 115, 0.14);
    --amber: #ffb03a;
    --amber-soft: rgba(255, 176, 58, 0.14);
    --error-soft: rgba(246, 101, 112, 0.14);
    --switch-off: #4d4d59;
    --bar: rgba(23, 23, 28, 0.86);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body.app { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.public { background: var(--card); }

a { color: var(--accent); text-decoration: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* 머리글 */

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}

body.public header { position: static; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
}

body.public .bar { max-width: 440px; padding-top: calc(40px + env(safe-area-inset-top)); }

.brand { margin: 0; color: var(--muted); font-size: 0.8rem; font-weight: 600; }

h1 { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
body.public h1 { font-size: 1.75rem; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 4px 16px 24px;
}

body.public main { max-width: 440px; padding: 0 20px 40px; }

p { margin: 0 0 8px; }

.lead { margin: 4px 0 24px; color: var(--sub); font-size: 0.95rem; }

.note { color: var(--muted); font-size: 0.88rem; }

/* 카드 */

main > section:not(.group) {
  background: var(--card);
  border-radius: 20px;
  padding: 20px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}

body.public main > section:not(.group) { background: var(--fill); }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }

h2 { margin: 0; font-size: 1.06rem; font-weight: 700; color: var(--text); }

.count { color: var(--muted); font-size: 0.88rem; font-weight: 600; }

main > section.warn { background: var(--amber-soft); }
section.warn h2 { color: var(--amber); }

/* 묶음 목록 */

section.group { margin: 0 0 24px; }
section.group > h2 { margin: 0 0 8px 6px; color: var(--muted); font-size: 0.86rem; font-weight: 600; }

.acct {
  background: var(--card);
  border-radius: 20px;
  padding: 16px 20px 8px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}
.acct-head { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; }
.acct-head .avatar { flex: none; }
.acct-head .tag { flex: none; }
.secret {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.secret span { color: var(--sub); font-size: 0.92rem; font-weight: 600; }
.secret b {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: right;
  overflow-wrap: anywhere;
}
.fold-title { margin: 12px 0 0; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.list.flat { box-shadow: none; padding: 0 0 0 2px; background: transparent; }
details.fold {
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
details.fold > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 52px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}
details.fold > summary::after { content: "열기"; color: var(--accent); font-size: 0.82rem; font-weight: 700; }
details.fold[open] > summary::after { content: "닫기"; }
details.fold.add {
  background: var(--card);
  border: 0;
  border-radius: 20px;
  padding: 4px 20px 12px;
  box-shadow: var(--shadow);
}
.tag.idle { background: var(--fill); color: var(--sub); }
.list { background: var(--card); border-radius: 20px; padding: 4px 20px; box-shadow: var(--shadow); }
.foot { margin: 8px 6px 0; color: var(--muted); font-size: 0.8rem; }

.row, .list > .kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list > :last-child { border-bottom: 0; }

label.row { cursor: pointer; }
.row-text { flex: 1 1 auto; min-width: max-content; }
label.row input {
  flex: 1 1 160px;
  width: auto;
  min-width: 0;
  margin: 0;
}
label.row input[type="radio"],
label.row input[type="checkbox"] {
  flex: none;
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  accent-color: var(--accent);
}
label.row input.switch {
  flex: none;
  width: 52px;
  height: 32px;
  min-height: 32px;
  padding: 0;
}
label.row input.mini { flex: none; width: 128px; }
.row-text b { display: block; color: var(--text); font-size: 1rem; font-weight: 600; }
.row-text small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.82rem; }
.row form.inline { margin: 0; flex: none; }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
}
.kv span { color: var(--muted); font-size: 0.94rem; }
.kv b { text-align: right; font-weight: 700; overflow-wrap: anywhere; }
.kv b.warn { color: var(--amber); }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.warn { background: var(--amber-soft); color: var(--amber); }

.buy { color: var(--red); }
.sell { color: var(--blue); }

/* 홈 */

.hero .eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 0.88rem; font-weight: 600; }
.big { margin: 0 0 14px; font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.hero .note { margin: 12px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--fill); color: var(--sub); }

progress {
  display: block;
  width: 100%;
  height: 8px;
  margin: 0 0 8px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}
progress::-webkit-progress-bar { background: var(--fill); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

ul.orders { margin: 0; padding: 0; list-style: none; }
ul.orders li {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
ul.orders li:last-child { border-bottom: 0; padding-bottom: 0; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--sub);
  font-weight: 800;
}

.row-end { text-align: right; font-variant-numeric: tabular-nums; }
.row-end b { display: block; font-weight: 700; }
.row-end small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.82rem; }

ul.plain { margin: 0; padding-left: 1.1rem; color: var(--text); }
ul.plain li { margin: 4px 0; }

.empty { padding: 28px 12px 20px; text-align: center; }
.empty svg {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.empty b { display: block; font-size: 1rem; }
.empty p { margin: 4px auto 0; max-width: 320px; color: var(--muted); font-size: 0.88rem; }

/* 입력 */

label { display: block; margin: 0 0 20px; color: var(--sub); font-size: 0.88rem; font-weight: 600; }
label small { display: block; margin-top: 6px; color: var(--muted); font-size: 0.8rem; font-weight: 400; }

input, select {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--fill);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

body.public section input, body.public section select { background: var(--card); }

input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--card); }
input::placeholder { color: var(--muted); opacity: 0.7; }
input:disabled { opacity: 0.5; cursor: not-allowed; }

input.otp {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.4em;
  text-align: center;
  padding-left: calc(16px + 0.4em);
}

input.mini {
  flex: none;
  width: 128px;
  min-height: 44px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input.switch {
  flex: none;
  width: 52px;
  min-height: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: radial-gradient(circle at 16px 50%, #fff 12px, transparent 12.5px) var(--switch-off);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background 0.2s;
}
input.switch:checked { background: radial-gradient(circle at 36px 50%, #fff 12px, transparent 12.5px) var(--accent); }
input.switch:focus { background-color: var(--switch-off); }
input.switch:checked:focus { background-color: var(--accent); }

fieldset { margin: 8px 0 20px; padding: 20px 20px 0; border: 0; border-radius: 20px; background: var(--fill); }
fieldset input, fieldset select { background: var(--card); }
legend { float: left; width: 100%; margin: 0 0 16px; padding: 0; color: var(--text); font-size: 1rem; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 0 10px; }

details { margin: -4px 0 20px; }
summary { color: var(--accent); font-size: 0.9rem; font-weight: 600; cursor: pointer; padding: 6px 0; list-style: none; }
summary::-webkit-details-marker { display: none; }
details[open] summary { margin-bottom: 12px; }

/* 버튼 */

button, a.button {
  display: block;
  width: 100%;
  min-height: 56px;
  margin: 8px 0 0;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
button:hover, a.button:hover { filter: brightness(1.06); }
button:active, a.button:active { transform: scale(0.985); }

button.switch {
  flex: none;
  width: 52px;
  min-height: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: radial-gradient(circle at 16px 50%, #fff 12px, transparent 12.5px) var(--switch-off);
  color: transparent;
  font-size: 0;
  box-shadow: none;
}
button.switch[aria-pressed="true"] {
  background: radial-gradient(circle at 36px 50%, #fff 12px, transparent 12.5px) var(--accent);
}
button.switch:hover { filter: none; }
button.switch:active { transform: none; }
button.switch:disabled { opacity: 0.45; cursor: default; }
form.row { margin: 0; }

button.ghost {
  display: inline-block;
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--fill);
  color: var(--sub);
  font-size: 0.92rem;
  font-weight: 600;
}
header button.ghost { background: var(--card); }
button.ghost.wide { display: block; width: 100%; min-height: 48px; margin-top: 4px; }

button.text {
  display: inline-block;
  width: auto;
  min-height: 44px;
  margin: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
}

form.inline { margin: 0; }
form.inline.center { margin-top: 12px; text-align: center; }
form.inline.center small { display: block; color: var(--muted); font-size: 0.8rem; }

form.join { display: flex; gap: 8px; width: 100%; }
form.join input { flex: 1; margin: 0; }
form.join button { width: auto; min-height: 52px; margin: 0; padding: 0 20px; border-radius: 14px; font-size: 1rem; }

.cta {
  position: sticky;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 4;
  margin: -8px -16px 24px;
  padding: 16px 16px 4px;
  background: linear-gradient(to bottom, transparent, var(--bg) 16px);
}
.cta button { margin: 0; }

/* 알림 */

p.error, p.notice, p.banner, a.banner {
  margin: 0 0 12px;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 0.92rem;
  font-weight: 600;
}
p.error { background: var(--error-soft); color: var(--red); }
p.notice { background: var(--green-soft); color: var(--green); }
p.banner, a.banner { background: var(--amber-soft); color: var(--amber); }
a.banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
a.banner svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 단계 */

.steps { display: flex; gap: 6px; margin: 0 0 10px; }
.steps span { flex: 1; height: 4px; border-radius: 999px; background: var(--fill-strong); }
.steps span.on { background: var(--accent); }
.step { margin: 0 0 8px; color: var(--accent); font-size: 0.86rem; font-weight: 700; }

/* 인증 앱 등록 */

.qr { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr > div { flex: 1; min-width: 180px; }
.qr p:last-child { margin: 0; }

main img {
  display: block;
  width: 164px;
  max-width: 100%;
  padding: 8px;
  background: #fff;
  border-radius: 12px;
}

code {
  display: inline-block;
  padding: 8px 12px;
  background: var(--card);
  border-radius: 10px;
  word-break: break-all;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  user-select: all;
}

ol.codes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 16px;
  margin: 0 0 16px;
  padding: 16px 20px;
  border-radius: 20px;
  background: var(--fill);
  list-style: none;
  counter-reset: code;
}
ol.codes li { display: flex; align-items: center; gap: 8px; margin: 0; counter-increment: code; }
ol.codes li::before {
  content: counter(code);
  min-width: 1.4em;
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
ol.codes code { flex: 1; padding: 6px 0; background: transparent; font-size: 1rem; }

/* 탭 */

nav.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px max(8px, calc((100% - 760px) / 2)) calc(6px + env(safe-area-inset-bottom));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}

nav.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  padding: 8px 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

nav.tabs svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

nav.tabs a.on { color: var(--text); }
nav.tabs a.on svg { stroke-width: 2.3; }

@media (max-width: 300px) {
  ol.codes { grid-template-columns: 1fr; }
  input.mini { width: 96px; }
}

.chart-frame {
  position: relative;
  width: 100%;
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-sizing: border-box;
  margin-bottom: 16px;
}

.chart-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 760 / 320;
  display: block;
}

.chart-table-wrap { overflow-x: auto; }

.chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.chart-table th,
.chart-table td { padding: 8px; text-align: left; }

.chart-table thead tr { border-bottom: 1px solid var(--line); }

dialog { width: min(92vw, 460px); padding: 24px; border: 0; border-radius: 20px; background: var(--card); color: inherit; box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 8px; }
dialog ol { margin: 12px 0; padding-left: 20px; line-height: 1.6; }
dialog .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.preset-note[hidden], #mail-guide-open[hidden], #mail-guide-link[hidden] { display: none; }
.grid2 > * { min-width: 0; }
.grid2 input, .grid2 select { width: 100%; min-width: 0; box-sizing: border-box; }

/* 비밀번호 보기 버튼 */
.pw-wrap { display: flex; align-items: center; gap: 6px; }
.pw-wrap input { flex: 1; min-width: 0; }
.pw-toggle { flex: none; width: auto; margin: 0; padding: 6px 10px; }
