:root {
  --paper: #faf7f2;
  --paper-2: #f2ece0;
  --ink: #1a1a1a;
  --ink-soft: #4a4a48;
  --ink-faint: #8a8680;
  --line: #d8d1c0;
  --accent: #a83c2a;        /* rust — record */
  --accent-soft: #c4756a;
  --go: #3a5a40;            /* forest — generate */
  --go-soft: #6b8a6f;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", "Georgia", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------- header */
.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 26px 32px 12px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  letter-spacing: 0.02em;
  font-weight: 500;
}
.brand .mark { color: var(--accent); }
.meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------- main */
main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 32px 80px;
}

.stage {
  margin-bottom: 48px;
  animation: fade 260ms ease-out;
}
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.label.spaced { margin-top: 32px; }
.label.row { display: flex; justify-content: space-between; align-items: baseline; }

/* --------------------------------------------------------------- record stage */
.stage-record {
  text-align: center;
  padding: 64px 0 32px;
}
.rec {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 160ms ease, transform 120ms ease, border-color 160ms;
  position: relative;
}
.rec:hover { border-color: var(--accent-soft); }
.rec:active { transform: scale(0.98); }
.rec-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  transition: all 180ms ease;
}
.rec.is-recording { border-color: var(--accent); }
.rec.is-recording .rec-dot {
  border-radius: 6px;
  width: 32px;
  height: 32px;
  background: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.9); opacity: 0.75; }
}

.hint {
  margin-top: 24px;
  color: var(--ink-soft);
  font-size: 14px;
}
.timer {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 18px;
  color: var(--accent);
  letter-spacing: 0.06em;
}
#scope {
  display: block;
  margin: 24px auto 0;
  max-width: 480px;
  width: 100%;
  height: 64px;
}

/* --------------------------------------------------------------- transcript */
.transcript {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink);
  padding: 18px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 3px;
  min-height: 120px;
  white-space: pre-wrap;
}
.transcript-meta {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}

.templates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.tpl {
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 140ms, background 140ms;
  font-size: 14px;
}
.tpl:hover { border-color: var(--ink-soft); }
.tpl.is-active {
  border-color: var(--go);
  background: var(--paper-2);
}
.tpl .tpl-name {
  font-weight: 600;
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
}
.tpl .tpl-desc {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.4;
}

/* --------------------------------------------------------------- document */
.document {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  padding: 28px 32px;
  background: #fffcf4;
  border: 1px solid var(--line);
  border-radius: 3px;
  min-height: 240px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.document h1, .document h2, .document h3 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 1em 0 0.4em;
}
.document h1 { font-size: 1.3em; }
.document h2 { font-size: 1.15em; }
.document h3 { font-size: 1em; }
.document p { margin: 0.6em 0; }
.document ul, .document ol { padding-left: 1.4em; }
.document hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }
.document .caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  vertical-align: -2px;
  background: var(--go);
  animation: blink 1s step-end infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }
.doc-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--go-soft);
}

/* --------------------------------------------------------------- buttons */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}
button.primary,
button.ghost {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 140ms, border-color 140ms, color 140ms;
}
button.primary {
  background: var(--go);
  color: var(--paper);
  border-color: var(--go);
}
button.primary:hover { background: #2f4a34; }
button.primary:disabled {
  background: var(--go-soft);
  border-color: var(--go-soft);
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
button.ghost:hover {
  border-color: var(--ink-soft);
  color: var(--ink);
}

/* --------------------------------------------------------------- error */
.error-body {
  padding: 14px 18px;
  background: #fdf0ed;
  border: 1px solid var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  font-size: 14px;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------- history */
.history {
  margin-top: 80px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}
.history h2 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 14px;
  font-weight: 500;
}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 2px;
  border-bottom: 1px dotted var(--line);
  cursor: pointer;
  font-size: 14px;
  gap: 16px;
}
.history-item:hover { background: var(--paper-2); }
.history-item .hi-preview {
  color: var(--ink-soft);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .hi-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  flex-shrink: 0;
}
.history-empty {
  font-size: 13px;
  color: var(--ink-faint);
  font-style: italic;
}

/* --------------------------------------------------------------- footer */
.bottom {
  border-top: 1px solid var(--line);
  padding: 12px 32px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 520px) {
  main { padding: 32px 20px 80px; }
  .top { padding: 20px 20px 10px; }
  .rec { width: 112px; height: 112px; }
  .document { padding: 20px; }
}

/* --------------------------------------------------------------- progress card */
.progress {
  margin-top: 28px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper-2);
  position: relative;
  overflow: hidden;
}
.progress[hidden] { display: none; }
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.progress-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
}
.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--go);
  box-shadow: 0 0 0 0 rgba(58, 90, 64, 0.55);
  animation: progPulse 1.6s ease-out infinite;
}
@keyframes progPulse {
  0%   { box-shadow: 0 0 0 0 rgba(58, 90, 64, 0.55); }
  70%  { box-shadow: 0 0 0 10px rgba(58, 90, 64, 0); }
  100% { box-shadow: 0 0 0 0 rgba(58, 90, 64, 0); }
}
.progress-eta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.progress-bar {
  position: relative;
  height: 8px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--go), var(--go-soft));
  transition: width 320ms ease-out;
}
.progress-bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0) 100%);
  animation: progShimmer 2.0s linear infinite;
}
@keyframes progShimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
.progress-meta {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.progress.is-done .progress-bar-fill {
  background: linear-gradient(90deg, var(--go), var(--go));
}
.progress.is-done .progress-dot {
  background: var(--go);
  animation: none;
}
.progress.is-error {
  border-color: var(--accent);
  background: rgba(168, 60, 42, 0.06);
}
.progress.is-error .progress-bar-fill {
  background: var(--accent);
}
.progress.is-error .progress-dot {
  background: var(--accent);
  animation: none;
}
