:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --fg-muted: #6a6a6a;
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #dfe1e4;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --card-bg: #ffffff;
  --chip-bg: #eef2f7;
  --chip-fg: #334155;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.25);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e7e7ea;
    --fg-muted: #8a8d92;
    --bg: #121316;
    --surface: #1c1e22;
    --card-bg: #1c1e22;
    --border: #2c3038;
    --accent: #3b82f6;
    --chip-bg: #272c35;
    --chip-fg: #bfd1ec;
    --shadow: 0 2px 10px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
input, textarea, button, select {
  font: inherit;
  font-size: 16px;
  color: inherit;
}
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.view { display: none; height: 100vh; height: 100dvh; }
.view.active { display: flex; }
html.snb-resuming #view-login.active { visibility: hidden; }

/* ========== Login ========== */
#view-login {
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.login-card .subtitle { margin: 0 0 24px; text-align: center; color: var(--fg-muted); font-size: 13px; }
#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--fg-muted); }
#login-form input {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
#login-form input:focus { border-color: var(--accent); }
.remember-row { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--fg) !important; font-size: 13px !important; cursor: pointer; }
.remember-row input { width: auto; margin: 0; }
#btn-login {
  margin-top: 4px;
  padding: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 8px;
  font-weight: 600;
}
#btn-login:disabled { opacity: 0.6; cursor: not-allowed; }
#login-error { color: var(--danger); font-size: 13px; margin: 0; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--fg-muted); line-height: 1.4; }

/* ========== Main (single column feed) ========== */
#view-main {
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}
.appbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.appbar-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  max-width: 100%;
}
.app-name { font-weight: 700; font-size: 20px; letter-spacing: 0.02em; }
.app-sep { color: var(--fg-muted); font-size: 16px; }
.bucket-alias {
  font-size: 16px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60vw;
}
.appbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.action-btn {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s;
}
.action-btn:hover { border-color: var(--accent); }
.action-btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.action-btn.primary:hover { filter: brightness(1.08); }
.action-btn.secondary { color: var(--fg-muted); }
.action-btn.secondary:hover { color: var(--fg); border-color: var(--fg-muted); }

.appfoot {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  font-size: 12px;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}
#entries {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.feed-empty {
  max-width: 720px;
  margin: 60px auto;
  text-align: center;
  color: var(--fg-muted);
  font-size: 14px;
}

/* ---------- Entry card ---------- */
.entry-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.entry-card.new-entry { border-color: var(--accent); }
.entry-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 15px;
  margin: 0;
}
.entry-text-truncated { position: relative; max-height: 8em; overflow: hidden; }
.entry-text-truncated::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 2em;
  background: linear-gradient(to bottom, transparent, var(--card-bg));
  pointer-events: none;
}
.entry-toggle {
  align-self: flex-start;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
}
.entry-toggle:hover { text-decoration: underline; }

.att-section-title {
  font-size: 12px;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.att-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.att-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.att-item:hover { background: color-mix(in oklab, var(--chip-bg) 85%, var(--accent) 15%); }
.att-icon { flex-shrink: 0; width: 22px; text-align: center; }
.att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { flex-shrink: 0; font-size: 12px; color: var(--fg-muted); }
.att-remove {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 16px;
  padding: 0 6px;
  line-height: 1;
}

.entry-meta {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}
.entry-actions { margin-left: auto; display: flex; gap: 6px; }
.entry-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.entry-actions .danger { color: var(--danger); border-color: var(--danger); }
.entry-actions .primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.entry-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Edit mode ---------- */
.entry-edit-textarea {
  width: 100%;
  min-height: 6em;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  resize: vertical;
  line-height: 1.55;
  font-family: inherit;
  font-size: 15px;
}
.entry-edit-textarea:focus { outline: none; border-color: var(--accent); }
.add-attachment-btn {
  align-self: flex-start;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--fg-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
}
.add-attachment-btn:hover { color: var(--accent); border-color: var(--accent); }
.att-pending { opacity: 0.6; }
.att-pending::after { content: " · 上传中"; color: var(--fg-muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: relative;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 16px 20px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--fg-muted);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--fg); }
.preview-title { font-weight: 600; padding-right: 30px; word-break: break-all; }
.preview-body { display: flex; align-items: center; justify-content: center; min-height: 60px; color: var(--fg-muted); font-size: 14px; }
.preview-body img { max-width: 100%; max-height: 60vh; border-radius: 6px; display: block; }
.preview-body video, .preview-body audio { max-width: 100%; max-height: 60vh; }
.preview-actions { display: flex; justify-content: flex-end; gap: 8px; }
.preview-actions button {
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}
.preview-actions button:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: fade-in 0.18s ease-out;
  max-width: calc(100vw - 40px);
  text-align: center;
}
@keyframes fade-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .appbar { padding: 12px 14px 10px; gap: 8px; }
  .app-name { font-size: 18px; }
  .app-sep, .bucket-alias { font-size: 15px; }
  .appbar-actions { gap: 8px; width: 100%; }
  .action-btn { min-height: 44px; padding: 10px 14px; flex: 1; justify-content: center; }
  .feed { padding: 12px; }
  #entries { gap: 12px; }
  .entry-card { padding: 12px; border-radius: 10px; }
  .entry-text { font-size: 15px; }
  .modal-card { padding: 14px 16px; max-width: 96vw; }
  .entry-actions button { padding: 6px 12px; }
}
