:root {
  --bg: #f2efe8;
  --bg-warm: #e6ded0;
  --paper: #fffdf8;
  --paper-soft: #f8f4eb;
  --border: #d9cfbf;
  --border-strong: #c4b7a3;
  --ink: #1f2a33;
  --muted: #5b6a72;
  --accent: #0d6b58;
  --accent-dark: #084e40;
  --accent-soft: #e6f2ef;
  --danger: #b42318;
  --warn-bg: #fff6db;
  --warn-border: #f0d78c;
  --warn-text: #7c5800;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(31, 42, 51, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-warm), var(--bg));
  line-height: 1.5;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 32px;
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  margin: 0;
}

h1 {
  font-size: 1.9rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.08rem;
  color: var(--ink);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.badges {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--muted);
}

.badge.local {
  background: var(--accent-soft);
  border-color: #b7dcd3;
  color: var(--accent-dark);
}

.badge.runtime.gpu {
  background: #eaf4ff;
  border-color: #b8d8ff;
  color: #154d8c;
}

/* Main two-column workspace */
.workspace {
  display: grid;
  grid-template-columns: 440px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

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

.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.muted-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

/* Buttons */
button,
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.btn-lg {
  padding: 11px 18px;
  font-size: 0.95rem;
}

.btn-secondary,
.file-btn {
  background: #edf2f0;
  color: var(--accent-dark);
  border: 1px solid #c9dcd7;
}

.btn-secondary:hover:not(:disabled),
.file-btn:hover {
  background: #dfeae6;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--paper-soft);
  color: var(--ink);
}

.file-btn input {
  display: none;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: underline;
}

.link-btn:hover {
  color: var(--ink);
}

/* Handwriting profiles */
.profile-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--paper-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.profile-item:hover {
  border-color: var(--border-strong);
}

.profile-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.profile-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.profile-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-meta {
  font-size: 0.76rem;
  color: var(--muted);
}

.profile-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.profile-thumb {
  height: 26px;
  max-width: 110px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #fff;
  object-fit: contain;
}

.delete-profile-btn {
  background: transparent;
  color: var(--muted);
  padding: 4px 7px;
  font-size: 0.82rem;
  border-radius: 6px;
}

.delete-profile-btn:hover {
  background: #fde8e8;
  color: var(--danger);
}

/* Upload panel */
.upload-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-strong);
}

.hint {
  margin: 0 0 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.hint.small {
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.field {
  display: block;
  margin-bottom: 10px;
}

.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 10px;
}

.field-row .field {
  flex: 1;
  margin-bottom: 0;
}

input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: #fff;
}

textarea {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.98rem;
  line-height: 1.55;
  resize: vertical;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(13, 107, 88, 0.25);
  border-color: var(--accent);
}

.crop-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.inline-slider {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.inline-slider input {
  width: 90px;
}

.crops-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 155px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper-soft);
  margin-bottom: 10px;
}

.crop-chip {
  padding: 2px;
  border: 2px solid var(--accent);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  line-height: 0;
  transition: opacity 0.12s ease, border-color 0.12s ease;
}

.crop-chip canvas {
  height: 24px;
  width: auto;
  display: block;
}

.crop-chip.excluded {
  opacity: 0.28;
  border-color: var(--border);
  border-style: dashed;
}

.inline-status {
  margin-top: 8px;
  font-size: 0.84rem;
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 8px 10px;
  border-radius: 6px;
}

/* Dictation */
.dictation-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.mic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.recording .mic-dot {
  background: #e11d48;
  animation: pulse 1.1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.55; }
  100% { transform: scale(1); opacity: 1; }
}

.interim-pill {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--muted);
  background: var(--paper-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  color: var(--warn-text);
  font-size: 0.84rem;
}

.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

/* Progress */
.progress-wrap {
  margin-top: 12px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #e7e1d6;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.18s ease;
}

.progress-label {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-line {
  margin: 10px 0 0;
  font-size: 0.83rem;
  color: var(--muted);
}

/* Right column: Preview & appearance controls */
.preview-card {
  padding: 14px 16px 18px;
}

.appearance-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.control-item select {
  padding: 5px 8px;
  font-size: 0.85rem;
  width: auto;
}

.control-item input[type="range"] {
  width: 96px;
  accent-color: var(--accent);
}

.ink-swatches {
  display: flex;
  gap: 7px;
  align-items: center;
  height: 30px;
}

.ink-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.ink-swatch.active {
  border-color: var(--ink);
  transform: scale(1.1);
}

.pages-stage {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 460px;
}

.empty-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--paper-soft);
  flex: 1;
}

.empty-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  margin: 0 0 6px;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.page-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  background: #fff;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}
