/* Bento 便当格布局：大小不一的圆角卡片拼成网格；浅色 / 深色跟随系统。 */
:root {
  --bg: #f6f4f1;
  --tile: #ffffff;
  --tile-2: #f1eeea;
  --line: #e7e2dc;
  --text: #1b1a19;
  --muted: #6f6a64;
  --accent: #f76b15;
  --accent-ink: #ffffff;
  --accent-soft: #fff0e6;
  --ok: #2f9e66;
  --ok-soft: #e6f6ee;
  --wait: #a26b00;
  --wait-soft: #fff4d6;
  --danger: #d93d42;
  --shadow: 0 1px 2px rgb(30 20 10 / 0.04), 0 8px 24px rgb(30 20 10 / 0.05);
  --r-tile: 24px;
  --r-ctl: 14px;
  --gap: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --tile: #1b1b1e;
    --tile-2: #242428;
    --line: #2e2e33;
    --text: #f0eeeb;
    --muted: #9a958f;
    --accent: #ff7a2a;
    --accent-soft: #3a2214;
    --ok: #4cc38a;
    --ok-soft: #15301f;
    --wait: #f1b23d;
    --wait-soft: #35290f;
    --danger: #ff6369;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.lock { overflow: hidden; }

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(30px, 4.4vw, 46px); line-height: 1.15; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 20px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); }
.hint.warn { color: var(--wait); }

/* ---- 顶栏 ---- */
.topbar {
  max-width: 1180px; margin: 0 auto; padding: 18px 20px 4px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 9px; }
.topbar-me { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 6px 14px; background: var(--tile); border-radius: 999px; box-shadow: var(--shadow); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot-ok { background: var(--ok); }

/* ---- 网格 ---- */
.bento {
  max-width: 1180px; margin: 0 auto; padding: 16px 20px 40px;
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-flow: row dense;
}
.tile {
  grid-column: span 12;
  background: var(--tile);
  border-radius: var(--r-tile);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0;
}
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

@media (min-width: 860px) {
  .bento-onboard { padding-top: 48px; }
  .tile-hero { grid-column: span 7; grid-row: span 2; justify-content: space-between; padding: 34px; min-height: 380px; }
  .tile-form { grid-column: span 5; grid-row: span 2; padding: 28px; }
  .tile-feature { grid-column: span 4; }

  .tile-compose { grid-column: span 7; grid-row: span 2; }
  .tile-inbox { grid-column: span 5; }
  .tile-me { grid-column: span 5; }
  .tile-outbox { grid-column: span 7; }
  .tile-contacts { grid-column: span 5; }
}

.tile-hero {
  background:
    radial-gradient(120% 90% at 100% 0%, var(--accent-soft), transparent 60%),
    var(--tile);
}
.tile-hero p { max-width: 34em; font-size: 16px; }
.tile-feature h3 { margin-top: 4px; }
.tile-inbox { border: 1px solid transparent; }

/* ---- 表单 ---- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.row-2 { display: flex; flex-wrap: wrap; gap: 14px 28px; }
.pills { flex-wrap: nowrap; }

input, textarea {
  font: inherit; color: var(--text);
  background: var(--tile-2);
  border: 1px solid transparent;
  border-radius: var(--r-ctl);
  padding: 11px 14px;
  width: 100%;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 140px; line-height: 1.6; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--tile); box-shadow: 0 0 0 4px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }

/* ---- 按钮与胶囊 ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 999px; padding: 11px 20px;
  background: var(--tile-2); color: var(--text);
  transition: transform .12s ease, background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .pill-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--text); color: var(--bg); padding: 13px 22px; }
.btn-burn { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border: 1px solid var(--line); padding: 7px 14px; font-size: 13px; }
.btn-danger { color: var(--danger); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--tile-2); color: var(--muted); white-space: nowrap; align-self: flex-start;
}
.tile-head .pill { align-self: center; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-wait { background: var(--wait-soft); color: var(--wait); }

.pills { display: flex; flex-wrap: wrap; gap: 6px; background: var(--tile-2); padding: 4px; border-radius: 999px; align-self: flex-start; }
.pill-btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; transition: background .15s, color .15s;
}
.pill-btn.on { background: var(--tile); color: var(--text); box-shadow: var(--shadow); }

.count { font-weight: 700; font-size: 13px; min-width: 28px; text-align: center; padding: 3px 9px; border-radius: 999px; background: var(--tile-2); color: var(--muted); }
.count.hot { background: var(--accent); color: var(--accent-ink); }

/* ---- 列表 ---- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--tile-2); border-radius: 16px; }
.item-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.item-main strong, .item-row strong { overflow: hidden; text-overflow: ellipsis; }
.item-col { flex-direction: column; align-items: stretch; gap: 6px; }
.item-row { display: flex; align-items: center; gap: 10px; }
.item-row > :first-child { flex: 1; min-width: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 18px; text-align: center; background: var(--tile-2); border-radius: 16px; }

.fp { font-family: var(--mono); font-size: 15px; letter-spacing: .04em; word-spacing: .2em; background: var(--tile-2); border-radius: 12px; padding: 10px 12px; line-height: 1.7; }
.fp.small { font-size: 12px; padding: 0; background: none; color: var(--muted); }
.notify { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; border-top: 1px solid var(--line); padding-top: 14px; }
.me-actions { display: flex; justify-content: flex-end; }

/* ---- 阅读器 ---- */
.viewer {
  position: fixed; inset: 0; z-index: 20;
  background: rgb(10 8 6 / 0.55);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  display: grid; place-items: center; padding: 20px;
  animation: fade .18s ease;
}
.viewer-card {
  width: min(640px, 100%); max-height: 86dvh;
  background: var(--tile); border-radius: 28px; padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 30px 80px rgb(0 0 0 / .3);
  animation: pop .26s cubic-bezier(.2, .9, .3, 1.2);
}
.viewer-text {
  font-size: 17px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere;
  overflow: auto; background: var(--tile-2); border-radius: 18px; padding: 18px;
  user-select: text; -webkit-user-select: text;
}
.viewer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.ring {
  --p: 1;
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), var(--tile-2) 0);
  display: grid; place-items: center;
}
.ring-num {
  width: 42px; height: 42px; border-radius: 50%; background: var(--tile);
  display: grid; place-items: center; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---- 提示 ---- */
#toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 16px; font-size: 14px; box-shadow: 0 10px 30px rgb(0 0 0 / .2); animation: pop .22s ease; transition: opacity .3s, transform .3s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }
.toast-warn { background: var(--wait); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* 手机上收件箱放最前 */
@media (max-width: 859px) {
  .tile-inbox { order: -1; }
}
