/* ===== ARTICO — EDITORIAL OLIVE DESIGN SYSTEM ===== */

:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --line-strong: #94a3b8;
  --primary: #4f46e5;
  --primary-soft: #e0e7ff;
  --green: #10b981;
  --green-soft: #d1fae5;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --rose: #ef4444;
  --rose-soft: #fee2e2;
  --accent: #6366f1;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.05), 0 8px 32px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 8px 40px rgba(15, 23, 42, 0.08), 0 2px 8px rgba(15, 23, 42, 0.02);
  --radius: 6px;
  --radius-lg: 10px;
  --font-ui: "Work Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-copy: "Merriweather", Georgia, serif;
  --transition-fast: 120ms ease;
  --transition: 200ms ease;
  --transition-slow: 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-soft: #334155;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --line-strong: #475569;
  --primary: #818cf8;
  --primary-soft: #2e384e;
  --green: #34d399;
  --green-soft: #064e3b;
  --amber: #fbbf24;
  --amber-soft: #78350f;
  --rose: #f87171;
  --rose-soft: #7f1d1d;
  --accent: #818cf8;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.25), 0 8px 32px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ===== RESET & BASE ===== */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle editorial paper texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      color-mix(in srgb, var(--line) 18%, transparent) 39px,
      color-mix(in srgb, var(--line) 18%, transparent) 40px
    );
  opacity: 0.4;
}

body.focus-mode .source-panel,
body.focus-mode .studio-panel,
body.focus-mode .mode-tabs {
  display: none;
}

body.focus-mode .workspace {
  grid-template-columns: minmax(0, 920px);
  justify-content: center;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin-top: 0;
}

/* ===== SCROLLBAR ===== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--line) 60%, transparent);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--line-strong);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--line) 60%, transparent) transparent;
}

/* ===== FOCUS RINGS ===== */

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===== APP SHELL ===== */

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
}

/* ===== TOPBAR ===== */

.topbar {
  position: sticky;
  top: 14px;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(420px, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 74px;
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: var(--shadow-lg);
  transition: box-shadow var(--transition);
}

.brand,
.mode-tabs,
.mode-tab,
.topbar-actions,
.status-pill,
.panel-head,
.panel-heading,
.search-field,
.tool-button,
.wide-button,
.icon-button,
.primary-action,
.publish-action,
.square-button,
.toggle-row,
.split-actions,
.image-item,
.source-item-head {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-soft);
  transition: transform var(--transition), box-shadow var(--transition);
}

.brand-mark:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 20%, transparent);
}

.brand h1 {
  margin-bottom: 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mode-tabs {
  justify-content: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.mode-tab {
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  transition: all var(--transition-fast);
}

.mode-tab:hover {
  color: var(--ink);
}

.mode-tab.active {
  background: var(--panel);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.topbar-actions {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== STATUS & CHIPS ===== */

.status-pill,
.count-chip {
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--green) 30%, var(--line));
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.status-pill.recording {
  border-color: var(--rose);
  background: var(--rose-soft);
  color: var(--rose);
  animation: pulse-recording 1.6s ease-in-out infinite;
}

@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.save-state {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ===== BUTTONS ===== */

.icon-button,
.tool-button,
.wide-button,
.square-button,
.primary-action,
.publish-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 500;
  transition:
    transform var(--transition-fast),
    border-color var(--transition-fast),
    background var(--transition-fast),
    box-shadow var(--transition-fast);
}

.icon-button:hover,
.tool-button:hover,
.wide-button:hover,
.square-button:hover,
.image-tool:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--primary) 10%, transparent);
}

.icon-button:active,
.tool-button:active,
.wide-button:active,
.square-button:active,
.primary-action:active,
.publish-action:active,
.image-tool:active {
  transform: translateY(0);
  transition-duration: 60ms;
}

.icon-button,
.tool-button,
.wide-button,
.primary-action,
.publish-action {
  gap: 7px;
  padding: 0 12px;
}

.square-button {
  justify-content: center;
  width: 38px;
  padding: 0;
}

.primary-action {
  border-color: var(--primary);
  background: var(--primary);
  color: #fafaf0;
  font-weight: 700;
}

.primary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 28%, transparent);
  border-color: var(--primary);
}

.primary-action.recording {
  border-color: var(--rose);
  background: var(--rose);
  color: #ffffff;
  animation: pulse-recording 1.6s ease-in-out infinite;
}

.publish-action {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
  font-weight: 700;
}

.publish-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--green) 28%, transparent);
  border-color: var(--green);
}

/* ===== WORKSPACE GRID ===== */

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr) minmax(300px, 380px);
  gap: 14px;
  margin-top: 14px;
}

.source-panel,
.studio-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 12px;
}

.writer-pane,
.panel-section,
.metric-grid {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.panel-section {
  padding: 16px;
}

.source-panel,
.writer-pane,
.studio-panel {
  min-height: calc(100vh - 116px);
}

.panel-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head h2,
.panel-heading h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.panel-heading {
  gap: 8px;
  margin-bottom: 12px;
}

.panel-heading svg {
  color: var(--primary);
}

/* ===== SEARCH ===== */

.search-field {
  gap: 8px;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.search-field input,
.writer-meta input,
.writer-meta select,
.source-composer input,
.source-composer textarea,
.voice-card select,
.stack input,
.title-input,
.dek-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

/* ===== PIECE LIST ===== */

.piece-list,
.source-list,
.image-list,
.outline-list {
  display: grid;
  gap: 6px;
}

.piece-list {
  max-height: 34vh;
  overflow: auto;
  padding-right: 2px;
}

.source-item,
.outline-item,
.empty-state {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  transition: all var(--transition-fast);
}

.piece-item {
  position: relative;
  display: flex;
  align-items: stretch;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  animation: fadeSlideIn 0.2s ease both;
  overflow: hidden;
  transition: all var(--transition-fast);
}

.piece-item:hover {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--line));
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 6%, transparent);
  transform: translateX(2px);
}

.piece-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.piece-item-main {
  flex: 1;
  display: grid;
  gap: 6px;
  padding: 12px;
  cursor: pointer;
  min-width: 0;
}

.piece-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  border: 0;
  border-left: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.piece-item:hover .piece-delete-btn,
.piece-delete-btn:focus-visible,
.piece-delete-btn.confirming {
  opacity: 1;
  border-left-color: color-mix(in srgb, var(--line) 50%, transparent);
}

.piece-delete-btn:hover {
  color: var(--rose);
  background: var(--rose-soft);
}

.piece-delete-btn.confirming {
  color: var(--green);
  background: var(--green-soft);
}

.piece-title,
.source-title {
  overflow: hidden;
  font-weight: 700;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.piece-meta,
.source-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.piece-kind {
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.70rem;
  letter-spacing: 0.04em;
}

/* ===== SOURCE COMPOSER ===== */

.source-composer input,
.source-composer textarea,
.voice-card select,
.writer-meta input,
.writer-meta select,
.stack input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.source-composer input:focus,
.source-composer textarea:focus,
.voice-card select:focus,
.writer-meta input:focus,
.writer-meta select:focus,
.stack input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
  outline: none;
}

.source-composer textarea {
  min-height: 112px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.source-composer .wide-button {
  margin: 10px 0;
}

.source-item-head {
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.source-item:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--line));
  transform: translateY(-1px);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 6%, transparent);
}

.source-item p,
.empty-state,
.panel-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.mini-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mini-button:hover {
  border-color: var(--rose);
  color: var(--rose);
  background: var(--rose-soft);
}

/* ===== WRITER PANE ===== */

.writer-pane {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.writer-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px 110px minmax(0, 1fr);
  gap: 10px;
}

.writer-meta span,
.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.70rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.title-input {
  min-height: 72px;
  resize: none;
  overflow: hidden;
  padding: 4px 2px 8px;
  font-size: clamp(1.8rem, 1.3rem + 1.4vw, 3.2rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.dek-input {
  min-height: 56px;
  resize: vertical;
  padding: 0 2px 10px;
  color: var(--muted);
  font-family: var(--font-copy);
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.55;
}

/* ===== WRITER TOOLBAR ===== */

.writer-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 0 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.toolbar-spacer {
  flex: 1;
}

.image-tool {
  cursor: pointer;
}

/* ===== EDITOR ===== */

#editor {
  flex: 1;
  width: 100%;
  min-height: 540px;
  resize: none;
  padding: 16px 2px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-copy);
  font-size: 1.08rem;
  font-weight: 300;
  line-height: 1.78;
}

#editor::placeholder,
.title-input::placeholder,
.dek-input::placeholder,
input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 55%, transparent);
}

#editor:focus,
.title-input:focus,
.dek-input:focus {
  outline: none;
}

/* ===== METRICS ===== */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  padding: 0;
  background: var(--line);
}

.metric {
  min-width: 0;
  padding: 16px;
  background: var(--panel);
  transition: background var(--transition-fast);
}

.metric:hover {
  background: var(--panel-soft);
}

.metric span {
  display: block;
  overflow: hidden;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
  text-overflow: ellipsis;
}

.metric p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ===== PROGRESS ===== */

.progress-track {
  overflow: hidden;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-soft);
}

#progressFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===== VOICE / DICTATION ===== */

.voice-card .live-buffer {
  min-height: 88px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.live-buffer span {
  display: block;
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.live-buffer p {
  display: -webkit-box;
  overflow: hidden;
  min-height: 3.4em;
  margin: 0;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-height: 1.35;
  font-size: 0.90rem;
}

.toggle-row {
  gap: 9px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ===== VOICE COMMANDS REFERENCE ===== */

.voice-commands-ref {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.voice-commands-ref summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
  padding: 4px 0;
}

.voice-commands-ref summary:hover {
  color: var(--ink);
}

.voice-commands-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 8px;
}

.voice-cmd {
  padding: 5px 8px;
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 4px;
  text-align: center;
}

.voice-cmd kbd {
  display: block;
  font-weight: 700;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.74rem;
}

/* ===== OUTLINE ===== */

.outline-item {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.outline-item:hover {
  border-color: var(--primary);
  color: var(--ink);
  transform: translateX(2px);
}

.outline-item.level-3 {
  padding-left: 24px;
  font-size: 0.84rem;
}

/* ===== IMAGES ===== */

.image-item {
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: all var(--transition-fast);
}

.image-item:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--line));
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 6%, transparent);
}

.image-item img {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.image-item strong {
  display: block;
  overflow: hidden;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-item span {
  color: var(--muted);
  font-size: 0.74rem;
}

/* ===== FIND / REPLACE ===== */

.stack {
  display: grid;
  gap: 8px;
}

.split-actions {
  gap: 8px;
}

.split-actions > * {
  flex: 1;
  justify-content: center;
}

/* ===== WIDE BUTTON ===== */

.wide-button {
  justify-content: center;
  width: 100%;
  text-align: center;
}

.file-input-label {
  cursor: pointer;
}

.danger {
  color: var(--rose);
  border-color: color-mix(in srgb, var(--rose) 30%, var(--line));
}

.danger:hover {
  background: var(--rose-soft);
  border-color: var(--rose);
}

/* ===== PREVIEW ===== */

.preview-section {
  padding-bottom: 8px;
}

.piece-preview {
  display: grid;
  gap: 10px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.piece-preview h1,
.piece-preview h2,
.piece-preview h3 {
  margin-bottom: 0;
  font-family: var(--font-copy);
  line-height: 1.18;
}

.piece-preview h1 {
  font-size: 1.7rem;
}

.piece-preview h2 {
  margin-top: 8px;
  font-size: 1.15rem;
}

.piece-preview h3 {
  font-size: 1rem;
}

.piece-preview p,
.piece-preview li {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-copy);
  font-size: 0.92rem;
  font-weight: 300;
  line-height: 1.65;
}

.piece-preview .poem-stanza {
  color: var(--ink);
  line-height: 1.9;
}

.piece-preview blockquote {
  margin: 4px 0;
  padding: 8px 0 8px 14px;
  border-left: 4px solid var(--primary);
  color: var(--ink);
  font-family: var(--font-copy);
  font-style: italic;
}

.piece-preview ul {
  margin: 0;
  padding-left: 20px;
}

.piece-preview hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
}

.piece-preview figure {
  margin: 2px 0 8px;
}

.piece-preview img {
  display: block;
  width: 100%;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
}

.piece-preview figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

/* ===== EMPTY STATES ===== */

.empty-state {
  text-align: center;
  padding: 20px 12px;
  font-style: italic;
}

.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 120px;
  color: var(--muted);
  text-align: center;
}

.preview-empty svg {
  width: 32px;
  height: 32px;
  opacity: 0.4;
}

.preview-empty p {
  margin: 0;
  font-size: 0.88rem;
}

/* ===== TOAST ===== */

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
  z-index: 100;
}

.toast {
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--primary);
  color: #fafaf0;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.toast.toast-exit {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }
}

/* ===== KEYBOARD SHORTCUTS MODAL ===== */

.shortcuts-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: backdropIn 0.2s ease both;
}

.shortcuts-backdrop[hidden] {
  display: none;
}

@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.shortcuts-modal {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.shortcuts-modal h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}

.shortcuts-modal .eyebrow {
  margin-bottom: 16px;
}

.shortcut-group {
  margin-bottom: 16px;
}

.shortcut-group h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  font-size: 0.88rem;
  color: var(--muted);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-row kbd {
  display: inline-flex;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-soft);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.shortcuts-close {
  margin-top: 16px;
  width: 100%;
}

/* ===== DELETE CONFIRMATION BAR ===== */

.delete-confirm-bar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--rose);
  border-radius: var(--radius);
  background: var(--rose-soft);
  animation: fadeSlideIn 0.2s ease both;
}

.delete-confirm-bar p {
  flex: 1;
  margin: 0;
  font-size: 0.84rem;
  color: var(--rose);
  font-weight: 600;
  display: flex;
  align-items: center;
}

.delete-confirm-bar button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--rose);
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 700;
}

.delete-confirm-yes {
  background: var(--rose);
  color: #fff;
}

.delete-confirm-no {
  background: transparent;
  color: var(--rose);
}

/* ===== ANIMATIONS ===== */

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger animation delay for piece list items */
.piece-item:nth-child(1) { animation-delay: 0ms; }
.piece-item:nth-child(2) { animation-delay: 30ms; }
.piece-item:nth-child(3) { animation-delay: 60ms; }
.piece-item:nth-child(4) { animation-delay: 90ms; }
.piece-item:nth-child(5) { animation-delay: 120ms; }
.piece-item:nth-child(n+6) { animation-delay: 150ms; }

/* ===== PRINT ===== */

body.printing .topbar,
body.printing .source-panel,
body.printing .studio-panel,
body.printing .writer-toolbar,
body.printing .writer-meta {
  display: none;
}

/* ===== NOSCRIPT ===== */

.noscript-banner {
  padding: 20px;
  text-align: center;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 600;
  border-bottom: 2px solid var(--amber);
}

/* ===== RESPONSIVE ===== */

@media (max-width: 1280px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .mode-tabs,
  .topbar-actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: minmax(230px, 310px) minmax(0, 1fr);
  }

  .studio-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 940px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    position: relative;
    top: 0;
  }

  .workspace,
  .studio-panel,
  .writer-meta {
    grid-template-columns: 1fr;
  }

  .source-panel,
  .writer-pane,
  .studio-panel {
    min-height: auto;
  }

  .piece-list {
    max-height: 260px;
  }

  .topbar-actions > *,
  .mode-tab {
    flex: 1;
    justify-content: center;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar,
  .topbar-actions,
  .mode-tabs,
  .writer-toolbar,
  .split-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .brand,
  .status-pill,
  .save-state,
  .primary-action,
  .publish-action,
  .toolbar-spacer {
    grid-column: 1 / -1;
  }

  .toolbar-spacer {
    display: none;
  }

  .title-input {
    font-size: 1.6rem;
  }

  #editor {
    min-height: 400px;
    font-size: 1rem;
  }

  .writer-pane {
    padding: 14px;
  }

  .shortcuts-modal {
    padding: 18px;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  body::before {
    display: none;
  }

  .topbar,
  .source-panel,
  .studio-panel,
  .writer-toolbar,
  .writer-meta,
  .shortcuts-backdrop {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .writer-pane {
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }
}
