:root {
  --paper: #f4efe8;
  --paper-2: #ebe4da;
  --card: #fffdf9;
  --ink: #2a2624;
  --muted: #5c554e;
  --faint: #7c746c;
  --line: #e3dbd1;
  --navy: #2f3e68;
  --navy-ink: #f7f4ef;
  --navy-soft: #e6e9f2;
  --ribbon: #b94e4e;
  --shadow: 0 22px 50px rgba(47, 42, 38, 0.08);
  --sans: "Noto Sans CJK SC", "Noto Sans CJK TC", "Noto Sans CJK JP", sans-serif;
  --serif: "Noto Serif CJK SC", "Noto Serif CJK TC", "Noto Serif CJK JP", serif;
  color-scheme: light;
}
html[data-mode="dark"] {
  --paper: #1c191c;
  --paper-2: #141214;
  --card: #262226;
  --ink: #e8e0d8;
  --muted: #b7ada4;
  --faint: #8f857d;
  --line: #3c3539;
  --navy: #a8b4d4;
  --navy-ink: #1a171c;
  --navy-soft: #2c3144;
  --ribbon: #e08a8a;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.38);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 8% -10%, color-mix(in srgb, var(--navy) 12%, transparent), transparent 42%),
    radial-gradient(ellipse at 110% 110%, color-mix(in srgb, var(--ribbon) 10%, transparent), transparent 38%),
    var(--paper);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.screen { display: none; }
html[data-view="login"] .screen-login { display: grid; }
html[data-view="inbox"] .screen-inbox { display: flex; }

.screen-login {
  min-height: 100%;
  place-items: center;
  padding: 32px 20px 88px;
}
.login-wrap { width: min(420px, 100%); }
.letterhead { text-align: center; margin-bottom: 22px; }
.mark {
  width: 64px; height: 64px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--navy);
  color: var(--navy-ink);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--navy) 28%, transparent);
}
.mark svg { width: 30px; height: 30px; display: block; }
.letterhead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 0.12em;
}
.domain { margin: 6px 0 0; color: var(--muted); letter-spacing: 0.08em; font-size: 13px; }
.stripes { display: flex; gap: 5px; justify-content: center; margin-top: 12px; }
.stripes i { display: block; height: 3px; border-radius: 99px; background: var(--navy); }
.stripes i:nth-child(1) { width: 22px; }
.stripes i:nth-child(2) { width: 10px; background: var(--ribbon); }
.stripes i:nth-child(3) { width: 22px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 26px 26px 22px;
}
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 12px 14px;
  outline: none;
  width: 100%;
}
.field input { height: 48px; padding: 0 14px; }
.field textarea { min-height: 180px; resize: vertical; line-height: 1.7; }
.field input:focus, .field textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy) 25%, transparent); }
.primary {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--navy);
  color: var(--navy-ink);
  font-weight: 650;
  letter-spacing: 0.12em;
}
.primary.slim { width: auto; padding: 0 22px; letter-spacing: 0.08em; }
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.55; cursor: default; filter: none; }
.ghost {
  height: 42px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: transparent; color: var(--ink);
}
.fineprint { margin: 14px 0 0; text-align: center; color: var(--faint); font-size: 12px; }
.fineprint a { color: var(--navy); }

.screen-inbox { height: 100vh; flex-direction: column; }
.topbar {
  height: 64px; flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--card) 82%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand-row { display: flex; align-items: center; gap: 10px; width: auto; flex: none; }
.mark.small { width: 34px; height: 34px; margin: 0; border-radius: 10px; box-shadow: none; }
.mark.small svg { width: 16px; height: 16px; }
.brand-row strong { font-family: var(--serif); font-size: 22px; letter-spacing: 0.14em; font-weight: 600; }
.search {
  flex: 1; max-width: 460px; margin: 0 auto;
  height: 40px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 0 16px;
  display: flex; align-items: center;
}
.search input {
  width: 100%; border: 0; background: transparent; outline: none; height: 100%;
}
.who { margin-left: auto; display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--navy-soft); color: var(--navy);
  font-family: var(--serif);
}
.who .avatar { padding: 0; overflow: hidden; }
.who .avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.quiet-btn, .mode-corner {
  border: 0; background: transparent; color: var(--faint);
  padding: 0; font-size: 13px; text-decoration: none;
}
.quiet-btn:hover, .mode-corner:hover { color: var(--navy); }
.mode-corner { position: fixed; right: 18px; bottom: 16px; }
.body { flex: 1; min-height: 0; display: flex; }
.side {
  width: 232px; flex: none;
  position: relative;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 70%, var(--card));
  overflow: auto;
}
.folder-indicator {
  position: absolute;
  left: 12px; right: 12px; top: 0;
  border-radius: 10px;
  background: var(--navy-soft);
  pointer-events: none;
  z-index: 0;
}
.write {
  width: 100%; height: 42px; margin-bottom: 16px;
  border-radius: 12px; border: 1px solid var(--navy);
  background: transparent; color: var(--navy); letter-spacing: 0.08em;
}
.side h2 { margin: 8px 10px; font-size: 12px; font-weight: 500; color: var(--faint); letter-spacing: 0.14em; }
.folder {
  position: relative; z-index: 1;
  width: 100%; text-align: left;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin: 2px 0;
  border: 0; border-radius: 10px; background: transparent;
  transition: color 340ms cubic-bezier(0.4, 0, 0.2, 1);
}
.folder .count { margin-left: auto; color: var(--muted); font-size: 12px; transition: color 340ms cubic-bezier(0.4, 0, 0.2, 1); }
.folder.active { color: var(--navy); font-weight: 650; }
.folder.active .count { color: var(--navy); }
.list {
  width: 380px; flex: none;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line); overflow: auto; background: var(--paper);
}
.list header {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 16px 18px 12px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
}
.list header h2 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.list header span, .quiet { color: var(--muted); font-size: 13px; }
.mail {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 14px 18px 13px; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 10px;
}
.mail .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: transparent; }
.mail.unread .dot { background: var(--ribbon); }
.mail .from { font-size: 14px; }
.mail.unread .from, .mail.unread .subject { font-weight: 700; }
.mail .subject { grid-column: 2; font-size: 14px; }
.mail .preview { grid-column: 2; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail time { grid-column: 3; grid-row: 1; color: var(--faint); font-size: 12px; }
.mail.selected { background: var(--card); box-shadow: inset 3px 0 0 var(--navy); }
.star-mark { color: var(--navy); font-size: 12px; margin-left: 6px; }
.read { flex: 1; min-width: 0; overflow: auto; background: var(--paper-2); }
.letter { max-width: 740px; margin: 8px auto 40px; padding: 8px 36px 0; }
.letter .who-line { display: flex; align-items: center; gap: 12px; }
.letter h2 { font-family: var(--serif); font-weight: 600; font-size: 32px; margin: 18px 0 8px; letter-spacing: 0.04em; text-align: left; }
.meta { color: var(--muted); font-size: 14px; line-height: 1.6; }
.letter article { font-size: 16.5px; line-height: 1.9; overflow-wrap: anywhere; }
.letter article p { margin: 0 0 1em; }
.letter article img, .letter article video { max-width: 100%; height: auto; }
.letter article table { max-width: 100% !important; }
.letter article a { color: var(--navy); }
.letter article pre {
  white-space: pre-wrap;
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.9;
}
.letter article blockquote {
  margin: 0 0 1em;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.atts { margin: 0 0 16px; }
.atts a { display: inline-block; margin: 0 12px 8px 0; color: var(--navy); }
.sign { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; }
.back { display: none; height: 36px; margin-bottom: 8px; }
.empty-note { color: var(--muted); padding: 28px 8px; line-height: 1.7; }
.list .empty-note {
  flex: 1;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px 28px;
  text-align: center;
}
.more-wrap { display: flex; justify-content: center; padding: 8px 18px 24px; }
.compose-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  background: var(--navy); color: var(--navy-ink);
  border-radius: 999px; padding: 8px 16px; z-index: 6;
  box-shadow: var(--shadow);
}
#messagestack { margin-top: 12px; text-align: center; color: var(--ribbon); font-size: 13px; }
#messagestack:empty { display: none; }
#xz-rc { display: none !important; }

/* --- icon-only left rail --- */
.side .label {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.side { width: 72px; padding: 16px 10px; overflow-x: hidden; }
.side .folder-indicator { left: 10px; right: 10px; }
.side .ico {
  width: 20px; height: 20px; flex: none; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.side .write {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 44px; padding: 0; margin-bottom: 14px;
}
.side .write:hover { background: var(--navy-soft); }
.side .folder {
  justify-content: center;
  height: 44px; padding: 0; margin: 2px 0;
  color: var(--muted);
}
.side .folder:hover { color: var(--navy); }
.side .folder.active { color: var(--navy); }
.side .folder[hidden] { display: none; }
.side .folder .count,
.side .folder.active .count {
  position: absolute; top: 4px; right: 4px; margin: 0;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px;
  background: var(--ribbon); color: #fff;
  font-size: 10px; font-weight: 600; line-height: 16px; text-align: center;
}

/* --- compose attachments --- */
.attach-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.attach-btn { height: 38px; }
.attach-btn:disabled { opacity: 0.55; cursor: default; }
.attach-hint { color: var(--faint); font-size: 12px; }
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attach-list:empty { display: none; }
.attach-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper);
  font-size: 14px;
}
.attach-list .att-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-list .att-size { color: var(--faint); font-size: 12px; flex: none; }
.attach-list li.uploading .att-size { color: var(--navy); }
.attach-list .att-del {
  flex: none; border: 0; background: transparent; color: var(--faint);
  font-size: 16px; line-height: 1; padding: 2px 4px;
}
.attach-list .att-del:hover { color: var(--ribbon); }
.field .attach-hint { color: var(--faint); font-size: 12px; }
.field .attach-list .att-name { color: var(--ink); font-size: 14px; }
.field .attach-list .att-size { color: var(--faint); font-size: 12px; }
.field .attach-list li.uploading .att-size { color: var(--navy); }

@media (max-width: 980px) {
  .read { display: none; }
  .list { width: auto; flex: 1; }
  .side { width: 64px; padding: 16px 8px; }
  .side .folder-indicator { left: 8px; right: 8px; }
  .brand-row { width: auto; }
  .who span { display: none; }
  html[data-pane="read"] .side,
  html[data-pane="read"] .list { display: none; }
  html[data-pane="read"] .read { display: block; }
  html[data-pane="read"] .back { display: inline-flex; align-items: center; }
}
