/* ============================================================
   Wizzle — Tom Riddle's Diary aesthetic
   Mobile-first: designed for 390×844 (iPhone 14 Pro)
   Desktop is secondary.
   ============================================================ */

/* ---------- Reset / base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --ink:          #1a120b;       /* dark sepia ink */
  --ink-faint:    #6b5344;       /* faded ink */
  --page:         #f5f0e8;       /* aged paper */
  --page-tinted:  #ede8df;       /* slightly deeper paper (header, cards) */
  --agent-stripe: #2c1a0e;       /* deep walnut — agent left gutter */
  --agent-bg:     #faf7f2;       /* cream — agent blocks */
  --agent-accent: #7a3e1d;       /* burnt sienna — agent text/icon */
  --op-stripe:    #1a2c1e;       /* dark forest — operator gutter */
  --op-bg:        #f2f8f2;       /* pale sage — operator blocks */
  --op-accent:    #275c2f;       /* deep green — operator text/icon */
  --border:       #d4c8b8;       /* parchment border */
  --shadow:       rgba(58,32,10,0.08);
  --pill-primary-bg:   #7a3e1d;
  --pill-primary-txt:  #faf7f2;
  --pill-default-bg:   #e8e0d2;
  --pill-default-txt:  #1a120b;
  --pill-danger-bg:    #8b1c1c;
  --pill-danger-txt:   #fdf8f8;
  --input-border: #b8a898;
  --focus-ring:   rgba(122,62,29,0.35);
  --radius:       10px;
  --radius-sm:    6px;
  --font-serif:   'Georgia', 'Times New Roman', serif;
  --font-mono:    'Menlo', 'Consolas', monospace;
  --transition:   0.2s ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-serif);
  line-height: 1.6;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
}

/* ---------- Layout shell ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--page-tinted);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header .logo {
  font-size: 1.25rem;
  font-weight: bold;
  letter-spacing: -0.02em;
  color: var(--agent-accent);
  font-style: italic;
}

.app-header .logo::before {
  content: "✒ ";
  font-style: normal;
}

.app-header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ab894;
  margin-left: auto;
  transition: background 0.5s;
}

.app-header .status-dot.offline { background: #c9a86a; }
.app-header .status-dot.error   { background: #c0524a; }

.app-header .last-sync {
  font-size: 0.7rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 0 48px;
}

/* ---------- Section headers ---------- */
.section-head {
  padding: 20px 18px 8px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.section-head h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-weight: normal;
}

.section-head .block-count {
  font-size: 0.7rem;
  color: var(--border);
  font-family: var(--font-mono);
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 0 18px 4px;
}

/* ---------- Block list ---------- */
.block-list {
  list-style: none;
  padding: 4px 0;
}

/* ---------- Individual block ---------- */
.block {
  margin: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--agent-bg);
  overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
  transition: opacity 0.6s ease, box-shadow var(--transition);
}

.block:focus-within {
  box-shadow: 0 0 0 2px var(--focus-ring), 0 1px 3px var(--shadow);
}

/* Operator-authored blocks */
.block.author-operator {
  background: var(--op-bg);
  border-color: #b8d4ba;
}

/* Left stripe — the visual author signal */
.block::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--agent-stripe);
  border-radius: var(--radius) 0 0 var(--radius);
}

.block {
  position: relative;
}

.block.author-operator::before {
  background: var(--op-stripe);
}

/* Pin badge */
.block.is-pinned {
  border-color: var(--agent-accent);
  box-shadow: 0 0 0 1px var(--agent-accent), 0 1px 3px var(--shadow);
}

/* Awaiting-operator: highlight border */
.block.awaiting-operator {
  border-color: #c8933a;
  box-shadow: 0 0 0 1.5px rgba(200,147,58,0.4), 0 1px 3px var(--shadow);
}

/* ---------- Block header (always visible) ---------- */
.block-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px 10px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.block-head:focus {
  outline: none;
}

.author-tag {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  margin-top: 3px;
  color: var(--agent-accent);
  min-width: 52px;
}

.block.author-operator .author-tag {
  color: var(--op-accent);
}

.block-summary {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--ink);
  word-break: break-word;
}

.block-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  margin-left: 6px;
  flex-shrink: 0;
}

.block-time {
  font-size: 0.62rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.expand-chevron {
  font-size: 0.6rem;
  color: var(--ink-faint);
  transition: transform var(--transition);
  line-height: 1;
}

.block.expanded .expand-chevron {
  transform: rotate(180deg);
}

/* Block type badge */
.type-badge {
  font-size: 0.55rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--pill-default-bg);
  color: var(--ink-faint);
  white-space: nowrap;
}

.type-badge.type-email   { background: #e8ddf5; color: #4a2878; }
.type-badge.type-buttons { background: #ddeaf5; color: #1d4a78; }
.type-badge.type-file    { background: #ddf5e8; color: #1d6040; }

/* ---------- Block body (expanded) ---------- */
.block-body {
  display: none;
  padding: 0 14px 12px 16px;
  border-top: 1px solid var(--border);
}

.block.expanded .block-body {
  display: block;
}

.body-text {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 10px;
}

.block.author-operator .body-text {
  color: var(--ink);
}

/* ---------- Buttons block ---------- */
.button-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.option-btn {
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity var(--transition), transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.option-btn:active { transform: scale(0.97); }

.option-btn.style-primary {
  background: var(--pill-primary-bg);
  color: var(--pill-primary-txt);
}

.option-btn.style-danger {
  background: var(--pill-danger-bg);
  color: var(--pill-danger-txt);
}

.option-btn.style-default,
.option-btn {
  background: var(--pill-default-bg);
  color: var(--pill-default-txt);
}

.option-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.option-btn.pressed {
  opacity: 0.6;
  text-decoration: line-through;
}

/* ---------- Email block ---------- */
.email-preview {
  margin-top: 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.email-field {
  display: grid;
  grid-template-columns: 3em 1fr;
  gap: 4px 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.email-field:last-of-type { border-bottom: none; }

.email-field label {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 1px;
}

.email-field input,
.email-field textarea {
  background: transparent;
  border: none;
  font-family: var(--font-serif);
  font-size: 0.82rem;
  color: var(--ink);
  width: 100%;
  resize: vertical;
}

.email-field input:focus,
.email-field textarea:focus {
  outline: none;
}

.email-body-field {
  display: block;
  padding: 8px 10px;
}

.email-body-field textarea {
  width: 100%;
  min-height: 80px;
  border: none;
  background: transparent;
  font-family: var(--font-serif);
  font-size: 0.82rem;
  color: var(--ink);
  resize: vertical;
}

.email-body-field textarea:focus { outline: none; }

.email-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.btn-approve {
  flex: 1;
  background: var(--op-accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 9px 16px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity var(--transition);
}

.btn-reject {
  background: transparent;
  border: 1px solid var(--pill-danger-bg);
  color: var(--pill-danger-bg);
  border-radius: 20px;
  padding: 9px 16px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity var(--transition);
}

.btn-approve:disabled,
.btn-reject:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.email-handled-notice {
  margin-top: 10px;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--ink-faint);
}

/* ---------- File block ---------- */
.file-block-content {
  margin-top: 10px;
}

.file-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 8px;
}

.file-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-link {
  font-size: 0.82rem;
  color: var(--agent-accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.file-link:hover { text-decoration: underline; }

/* ---------- Reply box ---------- */
.reply-area {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.reply-area label {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 6px;
}

.reply-area textarea {
  width: 100%;
  min-height: 62px;
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--ink);
  resize: vertical;
  transition: border-color var(--transition);
}

.reply-area textarea:focus {
  outline: none;
  border-color: var(--agent-accent);
}

.reply-area .reply-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.btn-reply-send {
  background: var(--agent-accent);
  color: var(--pill-primary-txt);
  border: none;
  border-radius: 20px;
  padding: 7px 18px;
  font-family: var(--font-serif);
  font-size: 0.82rem;
  cursor: pointer;
  transition: opacity var(--transition);
}

.btn-reply-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Replies (sub-blocks) ---------- */
.replies-list {
  list-style: none;
  padding: 6px 0 0 12px;
  border-left: 2px solid var(--border);
  margin-top: 10px;
}

.reply-block {
  margin-bottom: 8px;
}

.reply-block .reply-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.reply-block .reply-author {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--agent-accent);
}

.reply-block.author-operator .reply-author {
  color: var(--op-accent);
}

.reply-block .reply-time {
  font-size: 0.6rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}

.reply-block .reply-text {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink);
  margin-top: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Status toasts ---------- */
.toast-area {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--page);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  opacity: 0;
  transform: translateY(8px);
  animation: toastIn 0.25s ease forwards, toastOut 0.4s ease 2.2s forwards;
  pointer-events: none;
}

.toast.error {
  background: #8b1c1c;
}

@keyframes toastIn {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-4px); }
}

/* ---------- Empty / auth states ---------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-faint);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.92rem;
  font-style: italic;
  line-height: 1.6;
}

.auth-wall {
  min-height: 60dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  gap: 16px;
}

.auth-wall .auth-icon {
  font-size: 3rem;
}

.auth-wall h1 {
  font-size: 1.2rem;
  color: var(--ink);
}

.auth-wall p {
  font-size: 0.88rem;
  color: var(--ink-faint);
  max-width: 280px;
}

/* ---------- Typewriter animation (fresh agent blocks) ---------- */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.typewriter-cursor::after {
  content: "|";
  animation: blink 0.85s step-end infinite;
  color: var(--agent-accent);
  margin-left: 1px;
}

.typewriter-char {
  /* fade-in per character */
  opacity: 0;
  animation: charAppear 0.04s ease forwards;
}

@keyframes charAppear {
  to { opacity: 1; }
}

/* ---------- Decay animation ---------- */
.block {
  transition: opacity 1.2s ease;
}

/* ---------- Login page ---------- */
.login-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 20px;
}

.login-shell .login-logo {
  font-size: 2rem;
  font-style: italic;
  color: var(--agent-accent);
}

.login-shell .login-logo::before {
  content: "✒ ";
  font-style: normal;
  font-size: 1.6rem;
}

.login-shell .login-message {
  font-size: 0.95rem;
  color: var(--ink-faint);
  max-width: 300px;
  line-height: 1.6;
}

.login-shell .login-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--agent-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Responsive: wider screens ---------- */
@media (min-width: 600px) {
  main {
    padding: 0 0 64px;
  }

  .block {
    margin: 8px 20px;
  }

  .block-head {
    padding: 12px 16px 12px 20px;
  }

  .block-body {
    padding: 0 16px 14px 20px;
  }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .block,
  .expand-chevron,
  .option-btn {
    transition: none;
  }

  .typewriter-char {
    animation: none;
    opacity: 1;
  }

  .typewriter-cursor::after {
    animation: none;
  }

  .login-shell .login-spinner {
    animation: none;
    border-top-color: var(--agent-accent);
  }
}

/* ------------------------------------------------------------------ */
/*  Static (read-only flat-file) mode                                   */
/*  Shown when the build sets window.WIZZLE_STATIC (data/blocks.json,    */
/*  browser-side decay, no backend). Operator write-back is disabled     */
/*  until the D1 tier is live (wizzle/DEPLOY.md); feedback stays on the   */
/*  Doc. The banner is hidden by default and revealed only in this mode. */
/* ------------------------------------------------------------------ */
.static-banner {
  display: none;
}
body.static-mode .static-banner {
  display: block;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.5rem 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  text-align: center;
  color: #5a4a34;
  background: #efe4cf;
  border-bottom: 1px solid #d8c7a8;
}
/* No credentials web-side: write-back controls are inert in static mode. */
body.static-mode .button-options,
body.static-mode .email-actions,
body.static-mode .reply-area {
  display: none !important;
}
