:root {
  --black: #fff;
  --white: #111;
  --line: rgba(0,0,0,.16);
  --soft-line: rgba(0,0,0,.08);
  --muted: rgba(0,0,0,.5);
  --fill: rgba(0,0,0,.045);
  --danger: #9b1c1c;
  --ok: #1f6b3a;
  --font-display: "Syne", sans-serif;
  --font-body: "Space Grotesk", sans-serif;
  --ease: cubic-bezier(.2,.8,.2,1);
  --rail: 240px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --black: #000;
  --white: #fff;
  --line: rgba(255,255,255,.18);
  --soft-line: rgba(255,255,255,.08);
  --muted: rgba(255,255,255,.56);
  --fill: rgba(255,255,255,.06);
  --danger: #ff8a8a;
  --ok: #8fd4a8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app {
  height: 100%;
  height: 100dvh;
  height: 100svh;
  max-height: 100dvh;
  max-height: 100svh;
  background: var(--black);
  color: var(--white);
}
html, body { overflow: hidden; }
html:has(.login), body:has(.login) { overflow: auto; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: -.012em;
}
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input, textarea, .editor { font-size: 16px; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--white); color: var(--black); }
:focus-visible { outline: 1px solid var(--white); outline-offset: 3px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen { min-height: 100%; height: 100%; display: grid; }
.screen.login { overflow: auto; }

.login { place-items: center; padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bot)); animation: in .5s var(--ease); }
.login-card {
  width: min(440px, 100%);
  padding: 44px 32px 36px;
  border: 1px solid var(--line);
  animation: rise .6s var(--ease);
}
.mark {
  width: 36px;
  height: 36px;
  background: var(--white);
  color: var(--black);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -.05em;
}
.login h1 {
  font-family: var(--font-display);
  font-size: clamp(32px, 7vw, 48px);
  margin: 22px 0 8px;
  letter-spacing: -.06em;
  line-height: .92;
}
.login p { margin: 0 0 28px; color: var(--muted); }
label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  margin: 0 0 8px;
  color: var(--muted);
}
.field { margin: 0 0 16px; }
input, textarea {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 10px 0 12px;
  outline: none;
  border-radius: 0;
  transition: border-color .25s var(--ease);
}
input:focus, textarea:focus { border-color: var(--white); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--white);
  background: var(--white);
  color: var(--black);
  transition: transform .22s var(--ease), background .22s var(--ease), color .22s var(--ease);
}
.btn.ghost { background: transparent; color: var(--white); }
.btn.danger { border-color: var(--danger); background: transparent; color: var(--danger); }
@media (hover: hover) {
  .btn:hover { transform: translateY(-1px); }
  .btn.ghost:hover { background: var(--white); color: var(--black); }
  .btn.danger:hover { background: var(--danger); color: var(--black); }
}
.btn[disabled] { opacity: .4; pointer-events: none; }
.full { width: 100%; }
.login .btn { margin-top: 8px; }
.err { margin: 0 0 16px; color: var(--danger); font-size: 14px; min-height: 1.2em; }
.hint { margin: 28px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

.app {
  grid-template-columns: var(--rail) minmax(300px, 380px) 1fr;
  grid-template-rows: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  align-items: stretch;
}
.rail, .list, .pane {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.rail {
  border-right: 1px solid var(--line);
  padding: calc(22px + var(--safe-top)) 14px calc(18px + var(--safe-bot));
  display: flex;
  flex-direction: column;
  animation: in .4s var(--ease);
}
.scrim { display: none; }
.rail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.rail-close { display: none; flex: 0 0 auto; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand b {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: -.04em;
}
.who {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  margin: 0 0 22px;
}
.folders {
  display: grid;
  gap: 2px;
  margin-top: 16px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}
.folder {
  text-align: left;
  padding: 11px 10px;
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  position: relative;
  transition: background .2s var(--ease), transform .2s var(--ease);
}
.folder.on { background: var(--white); color: var(--black); }
@media (hover: hover) {
  .folder:hover { background: var(--fill); transform: translateX(2px); }
  .msg:hover { background: var(--fill); }
}
.folder .count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: var(--fill);
}
.folder.on .count { background: var(--black); color: var(--white); }
.folder .count.zero { opacity: 0; }
.rail-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 18px;
}

.list {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.list-head, .read-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.list-head h2, .read-head h2 {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: -.045em;
}
.search {
  padding: 0 20px 12px;
  border-bottom: 1px solid var(--line);
}
.search input { padding: 10px 0; }
.msgs { overflow: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.msg {
  width: 100%;
  text-align: left;
  padding: 16px 20px 16px 28px;
  border-bottom: 1px solid var(--soft-line);
  position: relative;
  animation: rise .45s var(--ease) both;
  transition: background .2s var(--ease);
}
.msg.on { background: var(--white); color: var(--black); }
.msg.on .meta, .msg.on .preview { color: color-mix(in srgb, var(--black) 55%, transparent); }
.msg.unseen::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 22px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--white);
}
.msg.on.unseen::before { background: var(--black); }
.msg.unseen .from,
.msg.unseen .subject { font-weight: 650; }
.msg.is-read .from, .msg.is-read .subject { font-weight: 450; color: var(--muted); }
.msg.on.is-read .from, .msg.on.is-read .subject { color: inherit; }
.msg-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 4px;
}
.from { letter-spacing: -.02em; }
.meta { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.subject { display: block; margin-bottom: 3px; }
.preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--danger);
}
.empty {
  padding: 64px 24px;
  color: var(--muted);
  text-align: center;
  animation: rise .5s var(--ease);
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane > .empty {
  flex: 1 1 auto;
  height: 100%;
}
.read-body {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding: 32px 36px calc(48px + var(--safe-bot));
  animation: rise .45s var(--ease);
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}
.pane h1 {
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 42px);
  letter-spacing: -.055em;
  margin: 0 0 14px;
  line-height: .95;
}
.headers { color: var(--muted); font-size: 14px; display: grid; gap: 4px; margin-bottom: 28px; }
.mail-html { max-width: 720px; overflow-wrap: anywhere; }
.mail-html pre { white-space: pre-wrap; font-family: inherit; margin: 0; }
.mail-html img { max-width: 100%; height: auto; }
.mail-html a { text-decoration: underline; }
.compose {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  max-width: none;
}
.fmt {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.fmt button {
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  font-size: 13px;
  letter-spacing: -.02em;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.fmt button:hover, .fmt button.on { background: var(--white); color: var(--black); }
.editor {
  flex: 1 1 auto;
  min-height: 280px;
  border: 1px solid var(--line);
  padding: 14px 16px;
  overflow: auto;
  outline: none;
  line-height: 1.55;
}
.editor:focus { border-color: var(--white); }
.editor p { margin: 0 0 .7em; }
.compose .hint { margin-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.status { font-size: 13px; color: var(--ok); }
.refresh {
  position: relative;
  min-width: 108px;
}
.refresh.has-new {
  background: var(--white);
  color: var(--black);
}
.refresh.has-new::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.theme-toggle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--white);
  background: transparent;
  justify-self: start;
}
html[data-theme="light"] .theme-toggle { background: var(--white); }
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--black);
}

@media (max-width: 1080px) {
  .app {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
  }
  .scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 18;
    border: 0;
    background: rgba(0, 0, 0, .4);
    cursor: pointer;
  }
  html[data-theme="light"] .scrim { background: rgba(17, 17, 17, .28); }
  .app.show-nav .scrim { display: block; }
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    height: 100%;
    max-height: 100dvh;
    z-index: 20;
    display: flex;
    transform: translateX(-105%);
    transition: transform .28s var(--ease);
    pointer-events: none;
    background: var(--black);
    border-right: 1px solid var(--line);
    box-shadow: 16px 0 40px rgba(0, 0, 0, .14);
  }
  .app.show-nav .rail {
    transform: none;
    pointer-events: auto;
  }
  .rail-close { display: inline-flex; min-height: 40px; padding: 0 12px; }
  .topbar {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
  }
  .topbar b {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 15px;
  }
  .topbar .btn, .read-head .btn { width: auto; min-height: 40px; padding: 0 12px; flex: 0 0 auto; }
  .list-head { display: none; }
  .read-head {
    padding: 10px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .read-head h2 { display: none; }
  .read-head .row { flex-wrap: nowrap; }
  .list, .pane { flex: 1; height: auto; min-height: 0; width: 100%; }
  .app.show-read .list { display: none; }
  .app:not(.show-read) .pane { display: none; }
  .search { padding: 0 16px 10px; }
  .msg { padding: 14px 16px 14px 26px; }
}

@media (max-width: 720px) {
  .read-body { padding: 18px 16px calc(24px + var(--safe-bot)); }
  .login-card { padding: 32px 20px 24px; }
  .login .btn { width: 100%; }
  .fmt button, .btn { min-height: 44px; }
  .refresh { min-width: 0; padding: 0 10px; }
  .pane h1 { font-size: clamp(22px, 7vw, 32px); }
  .editor { min-height: 160px; }
  .headers { font-size: 13px; margin-bottom: 18px; }
}

@media (display-mode: standalone) {
  .topbar { padding-top: calc(12px + var(--safe-top)); }
}
