:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --line: #e7e7ea;
  --ink: #1a1a1e;
  --mute: #8a8a92;
  --accent: #b48a5a;      /* eonju warm tone */
  --accent-ink: #fff;
  --unread: #faf6f0;
  /* iPhone safe areas (notch · home indicator); app.js raises --sab if iOS reports 0 in the home-screen app */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
.link { background: none; border: 0; color: var(--mute); text-decoration: underline; }
.link:hover { color: var(--ink); }
.err { color: #c0392b; min-height: 18px; font-size: 13px; margin-top: 8px; }

/* ---- login ---- */
.login { height: 100%; display: grid; place-items: center; }
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 36px 28px; text-align: center;
}
.brand { font-size: 22px; letter-spacing: .04em; margin: 0; }
.sub { color: var(--mute); margin: 2px 0 24px; letter-spacing: .3em; text-transform: uppercase; font-size: 11px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 8px; margin-bottom: 12px; font-size: 14px;
}
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}

/* ---- app shell ---- */
/* fixed to the viewport so the iPhone home-screen app never rubber-bands the whole page */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; letter-spacing: .02em; }
.logo span { color: var(--mute); font-weight: 400; margin-left: 4px; }
.acct { display: flex; align-items: center; gap: 14px; color: var(--mute); font-size: 13px; }

.body { flex: 1; display: grid; grid-template-columns: 220px 340px 1fr; min-height: 0; }

.sidebar { border-right: 1px solid var(--line); padding: 16px 12px; background: var(--panel); }
/* search box: sidebar on desktop, under the top bar on mobile (.msearch) */
.search {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.search:focus-within { border-color: var(--accent); background: var(--panel); }
.search animate-icons { flex: 0 0 auto; display: inline-flex; color: var(--mute); pointer-events: none; }
.search input {
  flex: 1; min-width: 0; padding: 9px 0; border: 0; background: transparent;
  color: var(--ink); font: inherit; outline: none; -webkit-appearance: none; appearance: none;
}
.msearch { display: none; }
.search-head { padding: 10px 16px; font-size: 12px; color: var(--mute); border-bottom: 1px solid var(--line); background: var(--bg); }
.row-folder { display: inline-block; font-size: 11px; font-weight: 500; color: var(--accent); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-right: 6px; vertical-align: 1px; }
/* new-mail notification toggle in the top bar */
.pushbtn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--mute); font-size: 12px; line-height: 1;
}
/* the icon element sets its own display, so the off/on swap needs !important */
.pushbtn .i-on { display: none !important; }
.pushbtn.on { color: var(--accent); border-color: var(--accent); }
.pushbtn.on .i-on { display: inline-flex !important; }
.pushbtn.on .i-off { display: none !important; }
.compose {
  width: 100%; padding: 10px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; margin-bottom: 16px;
}
.folders { list-style: none; margin: 0; padding: 0; }
.folders li {
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.folders li:hover { background: var(--bg); }
.folders li.active { background: var(--unread); color: var(--accent); font-weight: 600; }
.count { font-size: 12px; color: var(--mute); }

.list { border-right: 1px solid var(--line); overflow-y: auto; background: var(--panel); }
.row {
  padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:hover { background: var(--bg); }
.row.active { background: var(--unread); }
.row.unread .row-from, .row.unread .row-subj { font-weight: 700; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-from { font-size: 13px; }
.row-date { font-size: 12px; color: var(--mute); white-space: nowrap; }
.row-subj { font-size: 13px; margin-top: 2px; }
.row-snip { font-size: 12px; color: var(--mute); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reader { overflow-y: auto; display: flex; flex-direction: column; min-height: 0; padding: 0; }

/* reader header toolbar (Gmail/Superhuman-style) */
.r-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.r-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px;
  background: none; color: var(--ink); cursor: pointer; transition: background .18s, border-color .18s;
}
.r-back:hover { background: var(--bg); }
.r-tools { display: flex; gap: 6px; }
.r-tool {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: none; color: var(--ink); font-size: 13px; font-weight: 500; line-height: 1; cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
.r-tool animate-icons { opacity: .8; }
.r-tool:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.r-tool:hover animate-icons { opacity: 1; }
.r-tool-del:hover { background: #c0392b; border-color: #c0392b; }

.r-scroll { padding: 26px 32px 40px; }
.r-subj { font-size: 22px; font-weight: 700; margin: 0 0 20px; line-height: 1.3; }
.r-from-row { display: flex; align-items: center; gap: 12px; padding-bottom: 20px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.r-avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
}
.r-from-name { font-size: 14px; font-weight: 600; }
.r-from-addr { font-weight: 400; color: var(--mute); font-size: 13px; }
.r-sub { color: var(--mute); font-size: 12px; margin-top: 3px; }
.r-body { font-size: 14px; line-height: 1.75; }
.r-body img { max-width: 100%; height: auto; }
.empty { color: var(--mute); padding: 40px; text-align: center; }

/* reader-mode mobile back button in header is the one above; hide legacy */
.mback { display: none; }

/* ---- compose modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: grid; place-items: center; z-index: 10; }
.modal-card { width: 560px; max-width: 92vw; background: var(--panel); border-radius: 12px; padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-weight: 600; }
.modal-card input, .modal-card textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; font: inherit;
}
.modal-card textarea { min-height: 220px; resize: vertical; }
.modal-foot { display: flex; align-items: center; gap: 12px; }
.modal-foot .compose { width: auto; padding: 10px 22px; margin: 0; }
.status { color: var(--mute); font-size: 13px; }

/* hamburger, tab bar, drawer backdrop are desktop-hidden */
.hamburger { display: none; }
.tabbar { display: none; }
.scrim { display: none; }
.mback { display: none; }

/* ---- mobile ---- */
/* safe areas (notch · home indicator) need viewport-fit=cover in mail/index.html */
@media (max-width: 860px) {
  .body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); position: relative; }
  .list, .reader { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .list { display: block; }
  .reader { display: none; }
  .app.reading .list { display: none; }
  .app.reading .reader { display: flex; }
  .row { padding: 14px max(16px, var(--sar)) 14px max(16px, var(--sal)); }
  .row-from, .row-subj { font-size: 15px; }
  .row-snip { font-size: 13px; }

  /* top bar sits under the status bar */
  .topbar {
    height: calc(52px + var(--sat)); padding-top: var(--sat);
    padding-left: max(16px, var(--sal)); padding-right: max(16px, var(--sar));
    gap: 10px; flex: 0 0 auto;
  }
  .logo { font-size: 16px; flex: 1; }
  .acct #acct-addr { display: none; }
  .acct { font-size: 14px; }
  .acct .link { padding: 10px 0; }
  .pushbtn { width: 34px; height: 34px; padding: 0; justify-content: center; }
  .pushbtn span { display: none; }

  /* search bar right under the top bar; 16px stops iOS zoom-on-focus */
  .msearch {
    display: block; flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--line);
    padding: 8px max(12px, var(--sar)) 8px max(12px, var(--sal));
  }
  .msearch .search { margin: 0; }
  .msearch input { font-size: 16px; padding: 10px 0; }
  .search-head { font-size: 13px; padding: 10px max(16px, var(--sar)) 10px max(16px, var(--sal)); }

  /* bottom tab bar: part of the column (not overlaid), clears the home indicator */
  .tabbar {
    display: flex; flex: 0 0 auto;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 4px max(4px, var(--sar)) var(--sab) max(4px, var(--sal));
    user-select: none; -webkit-user-select: none;
  }
  .tabbar button {
    flex: 1; min-width: 0; height: 52px; background: none; border: 0; color: var(--mute);
    font-size: 11px; font-weight: 500; line-height: 1.2; padding: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  }
  .tabbar .ic { width: 24px; height: 24px; }
  .tabbar button.active { color: var(--accent); }

  /* slide-in drawer opened by the tab-bar menu (reuses the web sidebar markup) */
  .sidebar {
    display: block; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    width: 280px; max-width: 82vw; background: var(--panel); border-right: 0;
    box-shadow: none; visibility: hidden;
    transform: translateX(-100%); transition: transform .28s cubic-bezier(.16,1,.3,1), visibility 0s .28s;
    padding: calc(20px + var(--sat)) 14px calc(20px + var(--sab)) max(14px, var(--sal));
    overflow-y: auto; overscroll-behavior: contain;
  }
  .app.drawer-open .sidebar { transform: translateX(0); visibility: visible; box-shadow: 2px 0 20px rgba(0,0,0,.15); transition: transform .28s cubic-bezier(.16,1,.3,1); }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(0,0,0,.35); opacity: 0; pointer-events: none;
    transition: opacity .28s ease;
  }
  .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .list { border-right: 0; }
  .sidebar .compose { padding: 14px; font-size: 15px; }
  .folders li { padding: 0 14px; min-height: 48px; font-size: 15px; }

  /* reader: header pinned, body scrolls; icons only so it stays one row */
  .reader { flex-direction: column; }
  .r-header { padding: 8px max(12px, var(--sar)) 8px max(12px, var(--sal)); }
  .r-back { width: 44px; height: 44px; }
  .r-tool { padding: 0; width: 44px; height: 44px; justify-content: center; gap: 0; }
  .r-tool span { display: none; }
  .r-scroll { padding: 20px max(18px, var(--sar)) 32px max(18px, var(--sal)); }
  .r-body { font-size: 15px; overflow-wrap: anywhere; }
  .r-body table { max-width: 100%; }

  /* compose modal full-screen on phone; 16px inputs stop iOS zoom-on-focus */
  .modal { place-items: stretch; }
  .modal-card {
    width: 100%; max-width: 100%; height: 100%; border-radius: 0; display: flex; flex-direction: column;
    padding: calc(12px + var(--sat)) max(16px, var(--sar)) calc(12px + var(--sab)) max(16px, var(--sal));
  }
  .modal-head .link { padding: 10px 0; font-size: 15px; }
  .modal-card input, .modal-card textarea, .login-card input { font-size: 16px; }
  .modal-card textarea { flex: 1; min-height: 0; resize: none; }
  .modal-foot .compose { padding: 13px 26px; font-size: 15px; }
}
