:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1b1f27;
  --muted: #667085;
  --line: #dfe3ea;
  --accent: #2f5bd8;
  --accent-text: #ffffff;
  --mine: #eef3ff;
  --error: #b42318;
  --ok: #067647;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1b2029;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --line: #2c3340;
    --accent: #7ea2ff;
    --accent-text: #0e1320;
    --mine: #1f2940;
    --error: #ff8a80;
    --ok: #6fd6a3;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app {
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
h1 { font-size: 1.25rem; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; margin-top: 20vh; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
nav { display: flex; gap: 14px; }
nav a { text-decoration: none; color: var(--muted); padding: 4px 0; }
nav a.current { color: var(--text); border-bottom: 2px solid var(--accent); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 12px; }

button, .button {
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: 0.55; cursor: default; }
button.more { display: block; margin: 12px auto; }

.notice { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; border: 1px solid currentColor; }
.notice.error { color: var(--error); }
.notice.ok { color: var(--ok); }

.threads { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.threads li + li { border-top: 1px solid var(--line); }
.threads a { display: block; padding: 12px 14px; color: inherit; text-decoration: none; }
.threads .subject { display: block; overflow-wrap: anywhere; }
.threads .meta { display: block; font-size: 0.875rem; }
.threads .unread .subject { font-weight: 700; }
.threads .unread .subject::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
}
.threads .empty { padding: 28px 14px; text-align: center; }

.message { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.message.mine { background: var(--mine); }
.message header { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; font-size: 0.9rem; }
.body { overflow-wrap: anywhere; }
.body > :first-child { margin-top: 8px; }
.body > :last-child { margin-bottom: 4px; }
.body pre { overflow-x: auto; padding: 10px; border-radius: 6px; background: var(--bg); }
.body code { font-size: 0.9em; }
.body blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.body table { display: block; overflow-x: auto; border-collapse: collapse; }
.body th, .body td { border: 1px solid var(--line); padding: 4px 8px; }

.attachments { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
button.file { font-size: 0.9rem; padding: 6px 10px; white-space: normal; overflow-wrap: anywhere; text-align: left; }

.composer { display: grid; gap: 10px; margin-top: 16px; }
input[type="text"], textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
textarea { resize: vertical; min-height: 120px; }
input[type="file"] { font: inherit; max-width: 100%; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row input[type="text"] { width: auto; flex: 1; min-width: 140px; }
.status { font-size: 0.875rem; }

section { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
section p { margin: 0 0 10px; }
.secret { display: inline-block; padding: 6px 8px; border-radius: 6px; background: var(--bg); overflow-wrap: anywhere; user-select: all; }

.signin { text-align: center; margin-top: 24vh; display: grid; gap: 16px; justify-items: center; }
.signin h1 { font-size: 1.6rem; }

/* Message editor (CodeMirror). The extra .editor prefix outranks the
   editor's own built-in styles. */
.editor { border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.editor .cm-editor { border-radius: 8px; }
/* The typing area itself fills the box, so a click anywhere in it lands in the text. */
.editor .cm-editor .cm-content { min-height: 300px; }
.editor.reply .cm-editor .cm-content { min-height: 140px; }
.editor .cm-editor.cm-focused { outline: 2px solid var(--accent); outline-offset: -1px; }
.editor .cm-editor .cm-scroller { font-family: inherit; line-height: 1.5; }
.editor .cm-editor .cm-content { padding: 10px 12px; caret-color: var(--text); }
.editor .cm-editor .cm-line { padding: 0; }
.editor .cm-editor .cm-placeholder { color: var(--muted); }
.editor .cm-editor .cm-cursor { border-left-color: var(--text); }
.editor .cm-editor .cm-md-h { font-weight: 700; line-height: 1.3; }
.editor .cm-editor .cm-md-h1 { font-size: 1.6em; }
.editor .cm-editor .cm-md-h2 { font-size: 1.35em; }
.editor .cm-editor .cm-md-h3 { font-size: 1.15em; }
.editor .cm-editor .cm-md-strong { font-weight: 700; }
.editor .cm-editor .cm-md-em { font-style: italic; }
.editor .cm-editor .cm-md-strike { text-decoration: line-through; }
.editor .cm-editor .cm-md-code,
.editor .cm-editor .cm-md-codeblock { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--bg); }
.editor .cm-editor .cm-md-code { padding: 1px 4px; border-radius: 4px; }
.editor .cm-editor .cm-md-codeblock { padding: 0 8px; }
.editor .cm-editor .cm-md-link { color: var(--accent); text-decoration: underline; }
.editor .cm-editor .cm-md-dim,
.editor .cm-editor .cm-md-listmark { color: var(--muted); }
.editor .cm-editor .cm-md-quote { padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.editor .cm-editor .cm-md-hr { color: transparent; border-bottom: 1px solid var(--line); line-height: 0.75; }
.editor .cm-editor .cm-md-hr-raw { color: var(--muted); }

.chip { display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 0.9rem; overflow-wrap: anywhere; }
button.remove { padding: 0 8px; border: 0; background: none; font-size: 1.2rem; line-height: 1.4; color: var(--muted); }
