:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --raise: #141416;
  --hover: #121214;
  --sel: #19191c;
  --line: #1e1e21;
  --fg: #ececee;
  --fg2: #a0a0a6;
  --fg3: #636369;
  --accent: #e5484d;
  --ok: #5bb98b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --bar: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--fg); overscroll-behavior: none; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; background: none; border: 0; outline: 0; border-radius: 0; -webkit-appearance: none; appearance: none; }
button { cursor: pointer; color: var(--fg2); white-space: nowrap; }
button:disabled { opacity: .4; cursor: default; }
input::placeholder, textarea::placeholder { color: var(--fg3); }
a { color: inherit; text-decoration: underline; text-decoration-color: var(--fg3); text-underline-offset: 2px; }
ul { list-style: none; }
[hidden] { display: none !important; }
svg { display: block; }

.mono { font-family: var(--mono); font-size: .9em; }
.dim { color: var(--fg3); }
.err { color: var(--accent); font-size: 13px; }
.ok { color: var(--ok); font-size: 13px; }

#login { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding-bottom: 12vh; }
#login input { width: 220px; padding: 10px 0; text-align: center; font-size: 17px; letter-spacing: 4px; border-bottom: 1px solid var(--line); transition: border-color .2s; }
#login input:focus { border-color: var(--fg3); }
#err { color: var(--accent); font-size: 13px; min-height: 19px; }

#app { display: grid; grid-template-columns: 248px 380px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--line); }
.pane:last-child { border-right: 0; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.bar { flex: none; display: flex; align-items: center; gap: 6px; height: calc(var(--bar) + var(--top)); padding: var(--top) 14px 0; }
.bar .title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; font-weight: 600; font-size: 16px; }
.bar .title .sub { font-weight: 400; font-size: 13px; color: var(--fg3); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .spacer { flex: 1; }
.brand { flex: 1; font-weight: 600; font-size: 16px; padding-left: 6px; }
.back { display: none; align-items: center; gap: 2px; color: var(--fg2); padding: 8px 8px 8px 0; font-size: 15px; }
.back::before { content: ""; width: 9px; height: 9px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin: 0 6px 0 4px; border-radius: 1px; }
.icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--fg2); }
.icon:hover, .text:hover { color: var(--fg); }
.icon svg { width: 20px; height: 20px; }
.text { padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.primary { background: var(--fg); color: var(--bg); padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.primary:hover { background: #fff; }
.danger { color: var(--accent); }

/* nav */
.menu { padding: 4px 8px; }
.menu li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--fg2); font-size: 14px; min-height: 36px; }
.menu li:hover { background: var(--hover); color: var(--fg); }
.menu li.on { background: var(--sel); color: var(--fg); }
.menu li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu li .n, #folders .n { margin-left: auto; font-size: 12px; color: var(--fg3); font-variant-numeric: tabular-nums; }
.menu li.on .n { color: var(--fg2); }
#boxes li .name { font-family: var(--mono); font-size: 13px; }
#boxes li.all .name { font-family: inherit; font-size: 14px; }
#boxes li.add { color: var(--fg3); }
#boxes li.add:hover { color: var(--fg2); }
#boxes .label, #folders::before { display: block; padding: 14px 10px 4px; font-size: 11px; letter-spacing: .06em; color: var(--fg3); cursor: default; min-height: 0; }
#boxes .label:hover { background: none; color: var(--fg3); }
#folders { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
#folders::before { content: none; }
#newbox { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 2px 16px 6px; padding: 8px 10px; background: var(--raise); border-radius: 10px; }
#newbox input { flex: 1; min-width: 60px; font-family: var(--mono); font-size: 13px; padding: 4px 0; }
#newbox select { font-family: var(--mono); font-size: 13px; color: var(--fg2); max-width: 130px; padding: 4px 0; }
#newbox .at { color: var(--fg3); font-family: var(--mono); font-size: 13px; }
#newbox button { padding: 5px 10px; font-size: 13px; }
#newbox .err { width: 100%; }
#newbox .err:empty { display: none; }
.foot { flex: none; display: flex; gap: 4px; padding: 8px 12px calc(8px + var(--bottom)); border-top: 1px solid var(--line); }
.foot button { padding: 8px 10px; font-size: 13px; border-radius: 8px; color: var(--fg3); }
.foot button:hover { color: var(--fg); }

/* list */
.search { flex: none; padding: 0 14px 10px; }
.search input { width: 100%; background: var(--raise); border-radius: 9px; padding: 7px 11px; font-size: 14px; }
#messages { border-top: 1px solid var(--line); padding-bottom: var(--bottom); }
#messages li.msg { position: relative; padding: 11px 16px 12px 22px; border-bottom: 1px solid var(--line); cursor: pointer; }
#messages li.msg:hover { background: var(--hover); }
#messages li.msg.on { background: var(--sel); }
#messages li.msg.unread::before { content: ""; position: absolute; left: 8px; top: 18px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.l1 { display: flex; align-items: baseline; gap: 10px; }
.who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; color: var(--fg); }
.unread .who { font-weight: 600; }
.when { flex: none; font-size: 12px; color: var(--fg3); font-variant-numeric: tabular-nums; }
.l2 { display: flex; align-items: baseline; gap: 8px; margin-top: 1px; }
.subj { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--fg2); }
.unread .subj { color: var(--fg); }
.owner { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 11px; color: var(--fg3); }
.heart { flex: none; color: var(--accent); font-size: 12px; }
.snip { margin-top: 2px; font-size: 13px; color: var(--fg3); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.4; }
#messages .empty { padding: 48px 16px; text-align: center; color: var(--fg3); font-size: 14px; border: 0; }

/* view */
#view .bar { border-bottom: 1px solid var(--line); }
#view .bar .acts { margin-left: auto; display: flex; gap: 2px; }
#view .scroll { padding: 0 0 calc(24px + var(--bottom)); }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--fg3); font-size: 14px; }
.read { max-width: 820px; margin: 0 auto; padding: 22px 24px 0; }
.read h1 { font-size: 21px; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; margin-bottom: 14px; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 13px; padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.meta dt { color: var(--fg3); }
.meta dd { color: var(--fg2); min-width: 0; overflow-wrap: anywhere; }
.meta dd b { color: var(--fg); font-weight: 600; margin-right: 6px; }
.meta .good { color: var(--ok); }
.meta .warn { color: var(--accent); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.6; color: var(--fg); }
.body .q { color: var(--fg3); }
.htmlbar { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--fg3); }
.htmlbar button { font-size: 13px; padding: 4px 9px; border-radius: 7px; background: var(--raise); }
.htmlbar button.on { color: var(--fg); }
iframe.mail { display: block; width: 100%; height: 120px; min-height: 60px; border: 0; border-radius: 10px; background: #fff; color-scheme: light; }
.files { margin-top: 18px; font-size: 13px; color: var(--fg3); }

/* compose */
.compose { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.compose .row { display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid var(--line); min-height: 46px; }
.compose .row label { flex: none; width: 58px; color: var(--fg3); font-size: 14px; }
.compose .row input, .compose .row select { flex: 1; min-width: 0; padding: 12px 0; font-size: 15px; }
.compose .row select { font-family: var(--mono); font-size: 14px; color: var(--fg2); }
.compose textarea { flex: 1; resize: none; padding: 16px 18px calc(16px + var(--bottom)); font-size: 15px; line-height: 1.55; min-height: 200px; }
.compose .status { font-size: 12px; color: var(--fg3); margin-right: 6px; }

/* settings */
.settings { max-width: 640px; margin: 0 auto; padding: 8px 20px 0; }
.settings section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.settings section:last-child { border-bottom: 0; }
.settings h2 { font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--fg3); margin-bottom: 10px; }
.rows li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
.rows li:last-child { border-bottom: 0; }
.rows li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.rows li .meta-n { font-size: 12px; color: var(--fg3); }
.rows li button { font-size: 13px; padding: 4px 8px; border-radius: 7px; color: var(--fg3); }
.rows li button:hover { color: var(--fg); background: var(--raise); }
.rows li button.on { color: var(--fg); background: var(--raise); }
.tag { font-size: 11px; color: var(--fg3); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.inline { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.inline input, .inline select { flex: 1; min-width: 100px; background: var(--raise); border-radius: 9px; padding: 8px 11px; font-size: 14px; }
.inline select { flex: 0 1 auto; font-family: var(--mono); font-size: 13px; }
.inline .at { color: var(--fg3); font-family: var(--mono); }
.note { font-size: 13px; color: var(--fg3); margin-top: 10px; line-height: 1.5; }
.dns { width: 100%; padding: 4px 0 6px; }
.dnsrow { display: grid; grid-template-columns: 14px 56px minmax(0, 1fr); gap: 2px 10px; padding: 7px 0; font-size: 12px; border-top: 1px dashed var(--line); }
.dnsrow .mark { color: var(--accent); }
.dnsrow .mark.yes { color: var(--ok); }
.dnsrow .t { color: var(--fg3); }
.dnsrow .h, .dnsrow .v { font-family: var(--mono); grid-column: 3; overflow-wrap: anywhere; }
.dnsrow .h { grid-row: 1; color: var(--fg2); }
.dnsrow .v { color: var(--fg3); user-select: all; }

#toast { position: fixed; left: 50%; bottom: calc(22px + var(--bottom)); transform: translateX(-50%); background: var(--raise); border: 1px solid var(--line); color: var(--fg); font-size: 14px; padding: 9px 16px; border-radius: 10px; z-index: 10; }

.only-narrow { display: none; }

@media (hover: none) {
  .menu li:hover, #messages li.msg:hover { background: none; }
  .menu li.on { background: var(--sel); }
  #messages li.msg.on { background: none; }
}

@media (max-width: 1100px) and (min-width: 900px) {
  #app { grid-template-columns: 220px 320px minmax(0, 1fr); }
}

@media (max-width: 899px) {
  body { font-size: 16px; }
  #app { display: block; position: relative; overflow: hidden; }
  .pane { position: absolute; inset: 0; border: 0; background: var(--bg); visibility: hidden; transform: translateX(24px); opacity: 0; transition: transform .22s ease, opacity .22s ease, visibility 0s .22s; }
  #app[data-view="nav"] #nav, #app[data-view="list"] #list, #app[data-view="view"] #view { visibility: visible; transform: none; opacity: 1; transition: transform .22s ease, opacity .22s ease; }
  .back { display: inline-flex; }
  .only-narrow { display: grid; }
  #write { display: grid; }
  .bar { padding-left: 10px; padding-right: 10px; }
  .bar .title { justify-content: center; position: absolute; left: 90px; right: 90px; bottom: 0; height: var(--bar); align-items: center; flex-direction: column; gap: 0; font-size: 16px; line-height: 1.15; }
  .bar { position: relative; }
  #list .bar .title .sub { font-size: 11px; max-width: 100%; }
  #list .bar #empty-trash, #list .bar #write2 { margin-left: auto; }
  #list .bar #empty-trash:not([hidden]) + #write2 { margin-left: 0; }
  .menu { padding: 4px 10px; }
  .menu li { font-size: 16px; min-height: 46px; padding: 10px 12px; }
  #boxes li .name { font-size: 14px; }
  #boxes li.all .name { font-size: 16px; }
  #newbox input, #newbox select { font-size: 16px; }
  .search input { font-size: 16px; padding: 8px 12px; }
  .who { font-size: 16px; }
  .subj { font-size: 15px; }
  .snip { font-size: 14px; }
  .read { padding: 18px 18px 0; }
  iframe.mail { width: calc(100% + 36px); margin: 0 -18px; border-radius: 0; }
  .read h1 { font-size: 22px; }
  .meta { font-size: 13px; }
  .body { font-size: 16px; }
  .compose .row input, .compose .row select, .compose textarea, .inline input, .inline select { font-size: 16px; }
  .compose .row select { font-size: 15px; }
  .settings { padding: 4px 18px 0; }
  .rows li { font-size: 15px; }
  .rows li .name { font-size: 14px; }
  .rows li button { font-size: 14px; padding: 6px 9px; }
}

.ctx { position: fixed; z-index: 20; min-width: 196px; max-width: min(300px, calc(100vw - 16px)); padding: 5px; background: #161618; border: 1px solid #26262a; border-radius: 11px; box-shadow: 0 10px 30px rgba(0, 0, 0, .55); animation: ctx-in .09s ease-out; }
.ctx button { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 7px; font-size: 13.5px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
.ctx button:hover, .ctx button:focus-visible { background: #222226; }
.ctx button.danger { color: var(--accent); }
.ctx hr { border: 0; border-top: 1px solid #26262a; margin: 4px 6px; }
@keyframes ctx-in { from { opacity: 0; transform: scale(.97); } }
#messages li.msg, .menu li, .pick { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.pick { cursor: context-menu; }
.pressed { background: var(--sel) !important; }

@media (max-width: 899px) {
  .ctx { min-width: 220px; padding: 6px; border-radius: 13px; }
  .ctx button { font-size: 16px; padding: 11px 12px; }
}
.body a.jump { text-decoration: none; color: var(--fg3); font-size: .85em; padding: 0 2px; }
.body a.jump:hover { color: var(--fg); }
