@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

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

/* ── Light mode (default) ── */
:root {
  --bg-deep: #f4f5f7;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f0f1f3;
  --border: #d8dce3;
  --border-focus: #0066CC;
  --text-primary: #1a1a2e;
  --text-secondary: #5a6270;
  --text-muted: #9ca3af;
  --blue: #0066CC;
  --blue-glow: rgba(0, 102, 204, 0.1);
  --blue-hover: #0055aa;
  --blue-dim: #3388dd;
  --red: #cc3333;
  --green: #22863a;
  --orange: #d97706;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  --radius: 6px;
  --transition: 150ms ease;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --toolbar-height: 48px;
  --sub-toolbar-height: 42px;
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --bg-deep: #080b10;
  --bg-surface: #0d1117;
  --bg-card: #131921;
  --bg-elevated: #1a2029;
  --border: #1e2a3a;
  --text-primary: #c9d1d9;
  --text-secondary: #6e7a8a;
  --text-muted: #3d4a5c;
  --blue-glow: rgba(0, 102, 204, 0.15);
  --blue-hover: #0077EE;
  --blue-dim: #004488;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ── Scanline (dark only) ── */
[data-theme="dark"] body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 102, 204, 0.008) 2px,
    rgba(0, 102, 204, 0.008) 4px
  );
  pointer-events: none;
  z-index: 0;
}

/* ======================================================
   TOOLBAR LAYOUT (create page)
   ====================================================== */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: var(--toolbar-height);
  padding: 0 0.75rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
}

.toolbar-logo {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.toolbar-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.toolbar-title strong {
  color: var(--blue);
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
  overflow: hidden;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Toolbar controls */
.toolbar-select {
  padding: 0.3rem 1.6rem 0.3rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236e7a8a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.toolbar-select:focus {
  border-color: var(--border-focus);
}

.toolbar-check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.toolbar-check input[type="checkbox"] {
  accent-color: var(--blue);
}

.toolbar-input {
  padding: 0.3rem 0.5rem;
  width: 100px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.toolbar-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--blue-glow);
}

.toolbar-input::placeholder {
  color: var(--text-muted);
}

.toolbar-btn {
  padding: 0.3rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.toolbar-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--bg-elevated);
}

.toolbar-btn.has-file {
  color: var(--blue);
  border-color: var(--blue);
}

/* ── Sub-toolbar ── */
.sub-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--sub-toolbar-height);
  padding: 0 0.75rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.sub-toolbar-left {
  display: flex;
  align-items: center;
  gap: 0;
}

.sub-toolbar-right {
  display: flex;
  align-items: center;
}

.sub-tab {
  padding: 0.4rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  transition: color var(--transition);
}

.sub-tab:hover {
  color: var(--text-primary);
}

.sub-tab.active {
  color: var(--blue);
}

.sub-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--blue);
}

/* ── Editor area ── */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--toolbar-height) - var(--sub-toolbar-height));
  position: relative;
}

.create-page {
  display: flex;
  flex-direction: column;
}

.editor-area textarea {
  flex: 1;
  width: 100%;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: none;
  resize: none;
  outline: none;
  transition: background var(--transition), color var(--transition);
}

.editor-area textarea::placeholder {
  color: var(--text-muted);
}

/* ── Preview pane ── */
.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--bg-surface);
}

.preview-pane pre {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-pane pre code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Result overlay ── */
.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.result-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 0.75rem;
}

.result-link-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.result-link-row input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
}

/* ── Theme toggle ── */
.theme-toggle {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  padding: 0.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
}

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

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--text-secondary);
}

/* ── Hidden utility ── */
.hidden {
  display: none !important;
}

/* ======================================================
   VIEW PAGE STYLES (shared)
   ====================================================== */

/* View page uses centered layout */
body.view-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1rem;
}

/* ── Header (view page) ── */
.header {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0 0.75rem;
  transition: background var(--transition), border-color var(--transition);
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
}

a.header-brand {
  text-decoration: none;
  color: var(--text-primary);
}

.header-logo {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.header h1 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header h1 span {
  color: var(--blue);
}

.header-sub {
  display: none;
}

/* ── View container ── */
.view-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  margin-top: 1rem;
}

.card {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--blue-dim), transparent);
  opacity: 0.5;
}

/* View page states */
.state-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.state-loading p {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.state-error {
  padding: 2rem;
  text-align: center;
}

.error-icon {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  color: var(--red);
  margin-bottom: 0.75rem;
}

.state-error p {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.state-content {
  padding: 1.25rem;
}

.meta-info {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.text-block pre {
  width: 100%;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.file-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-info-name {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  word-break: break-all;
}

.file-info-size {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* ── Burn banner ── */
.burn-banner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  background: var(--orange);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

/* ── Action bar ── */
.action-bar {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.action-btn {
  padding: 0.4rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.action-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--bg-elevated);
}

.action-btn.active {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-glow);
}

/* ── Password modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.modal p {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.modal input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  margin-bottom: 0.5rem;
}

.modal input[type="password"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--blue-glow);
}

.modal-error {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--red);
  min-height: 1.2em;
  margin-bottom: 0.75rem;
}

.modal .btn {
  width: 100%;
}

/* ── QR container ── */
.qr-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
  box-shadow: var(--shadow);
}

/* ── Markdown rendered content ── */
.md-block {
  padding: 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.md-block h1, .md-block h2, .md-block h3 {
  margin: 1rem 0 0.5rem;
  color: var(--text-primary);
}

.md-block p {
  margin-bottom: 0.75rem;
}

.md-block code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--bg-elevated);
  border-radius: 3px;
}

.md-block pre code {
  display: block;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow-x: auto;
}

.md-block a {
  color: var(--blue);
}

/* Preview pane md-block inherits but no extra border */
.preview-pane .md-block {
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

/* ── Comments ── */
.comments-section {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  margin-top: 1rem;
}

.comments-section h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.comment {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
}

.comment-meta {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.comment-body {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.comment-form textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.comment-form textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--blue-glow);
}

.comment-form textarea::placeholder {
  color: var(--text-muted);
}

.comment-form .btn {
  align-self: flex-end;
  flex: none;
  padding: 0.5rem 1.25rem;
}

/* ── Footer ── */
.footer {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  padding: 1.5rem 0 2rem;
  text-align: center;
}

.footer p {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.footer a {
  color: var(--blue-dim);
  text-decoration: none;
}

.footer a:hover {
  color: var(--blue);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .toolbar-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
  }

  .toolbar-right {
    margin-left: auto;
  }

  .editor-area {
    height: calc(100vh - 120px);
  }

  .result-card {
    padding: 1.5rem;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-actions .btn {
    width: 100%;
  }
}
