:root {
  --max-width: 1200px;
  --gutter: 16px;
  --fg: #1a1a1a;
  --fg-muted: #555;
  --bg: #fafafa;
  --surface: #fff;
  --border: #d8d8d8;
  --border-strong: #999;
  --accent: #0066cc;
  --warn-bg: #fff7e0;
  --warn-fg: #6b4f00;
  --error-bg: #ffeaea;
  --error-fg: #8b0000;
  --ok-fg: #1a6b2e;
  --app-brand-color: #444;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win over class-level display rules
   (e.g., .app-selector-section { display: flex } and .angle-grid { display: grid }
   would otherwise silently render empty when their elements are marked hidden). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-header,
.page-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--gutter);
}

.page-header h2 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 4px 0 0; color: var(--fg-muted); font-size: 0.95rem; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--gutter);
  display: grid;
  gap: 20px;
}

.diagnostics {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 1px solid var(--warn-fg);
  border-radius: 6px;
  padding: 12px 16px;
}

.mode-toggle {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0;
  margin: 0;
  background: var(--surface);
  overflow: hidden;
  width: max-content;
  max-width: 100%;
}
.mode-toggle .mode-option {
  position: relative;
  flex: 1;
  cursor: pointer;
}
.mode-toggle .mode-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-toggle .mode-option span {
  display: inline-block;
  padding: 10px 18px;
  font-weight: 600;
  color: var(--fg-muted);
  text-align: center;
  min-width: 140px;
  transition: background-color 0.12s, color 0.12s;
}
.mode-toggle .mode-option input:checked + span {
  background: var(--accent);
  color: #fff;
}
.mode-toggle .mode-option input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.app-selector-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.persona-section {
  display: grid;
  gap: 6px;
}
.persona-section label { font-weight: 600; }
.persona-section select {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.persona-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
  min-height: 1.2em;
}
.app-selector-section label { font-weight: 600; }
.app-selector-section select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--app-brand-color);
  border-radius: 8px;
  padding: 16px 20px;
}
.app-card h3 { margin: 0; font-size: 1.25rem; }
.app-card p { margin: 4px 0; }
.app-card a { color: var(--accent); }
.app-card .audiences { color: var(--fg-muted); font-size: 0.9rem; }

.stale-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 1px solid var(--warn-fg);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.angle-section-title {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--fg-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.shared-header { margin-top: 16px; }

.angle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.angle-card {
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.angle-card.app-angle {
  border-style: solid;
  border-color: var(--app-brand-color);
}
.angle-card.shared-angle {
  border-style: dashed;
}
.angle-card .pill {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--fg-muted);
  color: var(--surface);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.angle-card.selected {
  box-shadow: 0 0 0 3px var(--accent);
}
.angle-card strong { font-size: 0.85rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.angle-card p { margin: 0; font-size: 0.95rem; }

.custom-section {
  display: grid;
  gap: 6px;
}
.custom-section label { font-weight: 600; }
.custom-section textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  resize: vertical;
}
.char-count { font-size: 0.85rem; color: var(--fg-muted); text-align: right; }

.generate-btn {
  font: inherit;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  align-self: start;
}
.generate-btn:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}

.pipeline-status .stage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.stage-list li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
}
.stage-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-strong);
}
.stage-list li[data-status="running"] .stage-icon {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.stage-list li[data-status="done"] .stage-icon { background: var(--ok-fg); }
.stage-list li[data-status="error"] .stage-icon { background: var(--error-fg); }
.stage-list li[data-status="error"] { background: var(--error-bg); color: var(--error-fg); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.stage-name { font-weight: 600; }
.stage-status { font-size: 0.9rem; color: var(--fg-muted); }
.stage-time { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--fg-muted); }

.final-post {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
}
.final-post h3 { margin: 0 0 12px; }
.final-post-text {
  white-space: pre-wrap;
  font: inherit;
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.final-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.final-actions button {
  font: inherit;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
}
.copy-confirmation { color: var(--ok-fg); font-weight: 600; }

.page-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  margin-top: 32px;
  color: var(--fg-muted);
  font-size: 0.9rem;
}
.page-footer a { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .page-footer { flex-direction: column; gap: 8px; align-items: flex-start; }
  .stage-list li { grid-template-columns: auto 1fr; }
  .stage-list li .stage-status,
  .stage-list li .stage-time { grid-column: 2; }
}

@media (max-width: 360px) {
  .container { padding: 12px; }
  .angle-grid { grid-template-columns: 1fr; }
}
