:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f3f9, #0d0d12);
  --panel: light-dark(#ffffff, #16161d);
  --raised: light-dark(#f7f7fc, #1d1d27);
  --hover: light-dark(#f0effa, #20202c);
  --text: light-dark(#17171f, #ececf4);
  --muted: light-dark(#6b6b80, #9494aa);
  --line: light-dark(#e6e6f0, #272733);
  --accent: light-dark(#5b4bf5, #8f82ff);
  --accent-ink: light-dark(#fff, #0d0d12);
  --accent-soft: light-dark(#eceaff, #25223f);
  --danger: light-dark(#d83a52, #ff6b81);
  --ok: light-dark(#17915c, #4fd39a);
  --star: #f5b301;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 8px 30px rgb(20 16 60 / .08);
  --r: 16px;
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.center { height: 100dvh; display: grid; place-items: center; padding: 24px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* buttons & fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .15s, transform .05s; }
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 0; background: none; border-radius: 9px; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--star); }
.icon-btn.on svg { fill: var(--star); }
.field { width: 100%; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); outline: none; }
textarea.field { height: auto; padding: 10px 12px; resize: vertical; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: light-dark(#fff3d6, #3a2f10); color: light-dark(#946200, #f5c451); }
.badge.bad { background: light-dark(#ffe3e8, #3b1620); color: var(--danger); }
.badge.good { background: light-dark(#dcf5e9, #12301f); color: var(--ok); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; object-fit: cover; }

/* landing / gate screens */
.gate { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 36px 32px; box-shadow: var(--shadow); text-align: center; }
.gate img.logo { width: 64px; height: 64px; border-radius: 18px; }
.gate h1 { font-size: 24px; margin: 18px 0 6px; letter-spacing: -.02em; }
.gate p { color: var(--muted); margin: 0 0 22px; }
.gate .btn { width: 100%; height: 44px; }
.gate .claim { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding-right: 12px; margin-bottom: 12px; background: var(--panel); }
.gate .claim:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.gate .claim input { border: 0; background: none; outline: none; height: 44px; padding: 0 12px; flex: 1; min-width: 0; }

/* app shell */
.shell { height: 100dvh; display: grid; grid-template: 60px 1fr / 248px minmax(300px, 400px) 1fr; gap: 0 10px; padding: 0 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 16px; letter-spacing: -.02em; width: 236px; flex: none; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.search { flex: 1; max-width: 640px; position: relative; }
.search svg { position: absolute; left: 12px; top: 10px; color: var(--muted); }
.search input { width: 100%; height: 38px; border-radius: 12px; border: 1px solid transparent; background: var(--panel); padding: 0 12px 0 38px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.top .spacer { flex: 1; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.side { background: none; border: 0; overflow-y: auto; padding: 2px; }
.side .compose { width: 100%; height: 44px; border-radius: 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.nav-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 12px 6px; }
.nav { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 12px; border: 0; background: none; border-radius: 10px; cursor: pointer; text-align: left; color: var(--text); }
.nav:hover { background: var(--hover); }
.nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav .count { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent); }
.nav svg { color: var(--muted); }
.nav.active svg { color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

/* list */
.bar { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); min-height: 51px; }
.bar h2 { font-size: 15px; margin: 0 6px; font-weight: 700; }
.list { overflow-y: auto; flex: 1; }
.item { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 8px; padding: 11px 14px 11px 10px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.item:hover { background: var(--hover); }
.item.open { background: var(--accent-soft); }
.item input { margin: 3px 0 0; accent-color: var(--accent); }
.item .from { font-weight: 500; }
.item.unread .from, .item.unread .subj { font-weight: 750; }
.item.unread::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.item .date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.item .subj, .item .snip { grid-column: 2 / -1; }
.item .snip { color: var(--muted); font-size: 13px; }
.item .meta { display: flex; align-items: center; gap: 6px; }
.item .meta svg { width: 14px; height: 14px; color: var(--muted); }
.item .meta svg.star { fill: var(--star); stroke: var(--star); }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 30px; }
.empty svg { width: 44px; height: 44px; stroke-width: 1.2; margin-bottom: 8px; }

/* reader */
.reader { overflow-y: auto; flex: 1; padding: 6px 22px 30px; }
.reader h1 { font-size: 21px; letter-spacing: -.01em; margin: 16px 0 14px; }
.msg { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; }
.msg-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; }
.msg-head .who { font-weight: 650; }
.msg-head .to { font-size: 12.5px; color: var(--muted); }
.msg.collapsed .msg-body, .msg.collapsed .msg-actions, .msg.collapsed .atts, .msg.collapsed .imgbar { display: none; }
.msg-body { padding: 0 14px 14px; }
.msg-body iframe { width: 100%; border: 0; border-radius: 10px; background: #fff; display: block; min-height: 60px; }
.msg-body pre { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; }
.imgbar { margin: 0 14px 10px; padding: 8px 12px; border-radius: 10px; background: var(--raised); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.att { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--text); font-size: 13px; background: var(--raised); }
.att:hover { border-color: var(--accent); }
.att small { color: var(--muted); }
.att button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; display: grid; }
.msg-actions { display: flex; gap: 8px; padding: 0 14px 14px; flex-wrap: wrap; }
.err { color: var(--danger); font-size: 13px; }

/* compose */
.compose-win { position: fixed; right: 20px; bottom: 0; width: min(620px, calc(100vw - 40px)); height: min(680px, calc(100dvh - 30px)); background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; box-shadow: 0 20px 60px rgb(0 0 0 / .3); display: flex; flex-direction: column; z-index: 20; }
.compose-win header { display: flex; align-items: center; padding: 10px 10px 10px 16px; font-weight: 700; border-bottom: 1px solid var(--line); }
.crow { display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--line); min-height: 40px; }
.crow > span { color: var(--muted); font-size: 13px; width: 52px; flex: none; }
.crow input, .crow select { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 38px; }
.crow button.link { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.tools { display: flex; gap: 2px; padding: 4px 10px; border-bottom: 1px solid var(--line); }
.tools button { min-width: 30px; height: 28px; border: 0; background: none; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 700; }
.tools button:hover { background: var(--hover); color: var(--text); }
.editor { flex: 1; overflow-y: auto; padding: 14px 16px; outline: none; word-break: break-word; }
.editor blockquote { margin: 8px 0 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.editor img { max-width: 100%; }
.compose-win .atts { padding: 8px 16px 0; }
.compose-win footer { display: flex; align-items: center; gap: 8px; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); position: relative; }
.split { display: inline-flex; }
.split .btn:first-child { border-radius: 10px 0 0 10px; }
.split .btn:last-child { border-radius: 0 10px 10px 0; padding: 0 9px; border-left: 1px solid rgb(255 255 255 / .25); }
.pop { position: absolute; bottom: 58px; left: 16px; width: 290px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; z-index: 5; }
.menu { position: absolute; right: 12px; top: 54px; min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.menu .who { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--text); padding: 0; width: min(720px, calc(100vw - 24px)); max-height: min(760px, calc(100dvh - 24px)); box-shadow: 0 30px 80px rgb(0 0 0 / .35); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(10 10 20 / .5); backdrop-filter: blur(3px); }
dialog header { display: flex; align-items: center; padding: 16px 16px 12px 22px; font-size: 17px; font-weight: 750; }
dialog .body { overflow-y: auto; padding: 0 22px 22px; }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 10px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0; font-size: 15px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border: 0; }

/* toasts */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: light-dark(#1b1b26, #f1f1f8); color: light-dark(#fff, #111); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; animation: up .2s ease; max-width: calc(100vw - 32px); }
.toast button { border: 0; background: none; color: light-dark(#a99eff, #5b4bf5); font-weight: 700; cursor: pointer; }
@keyframes up { from { opacity: 0; transform: translateY(8px); } }
.only-mobile { display: none; }

@media (max-width: 1000px) { .shell { grid-template-columns: 220px minmax(260px, 340px) 1fr; } .brand { width: 208px; } }
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .shell { grid-template: 56px 1fr / 1fr; padding: 0 6px 6px; }
  .brand { width: auto; } .brand span { display: none; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; background: var(--panel); z-index: 40; padding: 16px 12px; transform: translateX(-110%); visibility: hidden; transition: transform .2s, visibility .2s; border-right: 1px solid var(--line); padding-top: max(16px, env(safe-area-inset-top)); }
  body.drawer .side { transform: none; visibility: visible; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .4); }
  .pane.read { display: none; }
  body.reading .pane.read { display: flex; }
  body.reading .pane.listp { display: none; }
  .reader { padding: 4px 12px 24px; }
  .compose-win { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
