:root {
  --ink: #18322f;
  --ink-soft: #53706b;
  --paper: #fbf5e9;
  --paper-deep: #efe1c8;
  --panel: rgba(255, 252, 245, 0.9);
  --line: rgba(24, 50, 47, 0.16);
  --teal: #176b65;
  --teal-deep: #0f514d;
  --orange: #d96f32;
  --orange-soft: rgba(217, 111, 50, 0.16);
  --good: #15704f;
  --bad: #a23a2a;
  --shadow: 0 24px 70px rgba(51, 40, 24, 0.15);
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: 10px;
  color: white;
  background: var(--ink);
  transform: translateY(-180%);
}

.skip-link:focus { transform: translateY(0); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(217, 111, 50, 0.24), transparent 26rem),
    radial-gradient(circle at 88% 8%, rgba(23, 107, 101, 0.2), transparent 30rem),
    linear-gradient(135deg, #fbf1df, #d8dfcf);
}

a { color: var(--teal-deep); }

.portal {
  width: min(1060px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 52px;
}

.masthead,
.masthead-actions,
.workflow-heading,
.stage-actions,
.entry-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.masthead {
  justify-content: space-between;
  margin-bottom: 34px;
}

.wordmark {
  color: var(--teal-deep);
  font: 800 0.83rem/1 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.22em;
  text-decoration: none;
}

.quiet-link {
  color: var(--ink-soft);
  font-size: 0.88rem;
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(250px, 0.75fr);
  gap: 18px;
}

.layout.single {
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.entry,
.workflow-main { padding: clamp(24px, 5vw, 52px); }
.side-note,
.stage-card,
.feedback-card,
.error-card { padding: 20px; }

.eyebrow {
  margin: 0 0 14px;
  color: var(--orange);
  font: 800 0.74rem/1.15 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 760px;
  margin-bottom: 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 7vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: -0.075em;
}

h2 {
  margin-bottom: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  letter-spacing: -0.055em;
}

h3 { margin-bottom: 8px; font-size: 1.02rem; }

.lead,
.muted,
.side-note p,
.feedback-card p {
  color: var(--ink-soft);
  line-height: 1.58;
}

.code-field {
  display: grid;
  gap: 9px;
  margin-top: 28px;
}

label,
.field-label {
  color: var(--teal-deep);
  font: 800 0.77rem/1.2 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  font: 1rem/1.45 "SFMono-Regular", Consolas, monospace;
}

textarea { min-height: 210px; resize: vertical; }

button,
.button-link {
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  color: #fffaf0;
  background: linear-gradient(135deg, var(--orange), #a94f28);
  box-shadow: 0 10px 28px rgba(169, 79, 40, 0.2);
  cursor: pointer;
  font: 800 0.82rem/1.1 "SFMono-Regular", Consolas, monospace;
  text-decoration: none;
}

button.secondary,
.button-link.secondary {
  color: var(--teal-deep);
  background: rgba(23, 107, 101, 0.1);
  box-shadow: none;
}

button:disabled { cursor: wait; opacity: 0.55; }

.entry-actions,
.stage-actions { margin-top: 16px; flex-wrap: wrap; }

.status-line {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.status-line[data-tone="error"] { color: var(--bad); }
.status-line[data-tone="good"] { color: var(--good); }

.side-note {
  align-self: start;
  overflow: hidden;
  position: relative;
}

.side-note:after {
  content: "";
  position: absolute;
  right: -66px;
  bottom: -66px;
  width: 170px;
  height: 170px;
  border: 28px solid rgba(23, 107, 101, 0.09);
  border-radius: 50%;
}

.mini-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.mini-list li {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.4;
}

.workflow-stack,
.feedback-stack {
  display: grid;
  gap: 16px;
}

.workflow-heading { justify-content: space-between; align-items: flex-start; }

.badge {
  display: inline-flex;
  border: 1px solid rgba(23, 107, 101, 0.2);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--teal-deep);
  background: rgba(23, 107, 101, 0.08);
  font: 800 0.72rem/1 "SFMono-Regular", Consolas, monospace;
}

.steps {
  display: grid;
  grid-template-columns: repeat(var(--step-count), minmax(0, 1fr));
  gap: 8px;
  margin: 24px 0;
}

.step {
  border-top: 4px solid rgba(24, 50, 47, 0.14);
  padding-top: 9px;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.step[data-state="done"] { border-color: var(--good); }
.step[data-state="current"] { border-color: var(--orange); color: var(--ink); font-weight: 800; }

.stage-card,
.feedback-card,
.error-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.48);
}

.file-row {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.audio-boundary {
  margin-top: 14px;
  border-left: 4px solid var(--orange);
  padding: 10px 12px;
  color: var(--ink-soft);
  background: var(--orange-soft);
  font-size: 0.9rem;
  line-height: 1.45;
}

.audio-upload {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.exercise-chat,
.transcript-review {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.message-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.34);
}

.message {
  width: min(92%, 720px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.68);
}

.message[data-role="assistant"] {
  margin-left: auto;
  background: rgba(23, 107, 101, 0.09);
}

.message-role {
  margin-bottom: 6px;
  color: var(--orange);
  font: 800 0.7rem/1 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.message-text {
  margin-bottom: 0;
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
}

.turn-guidance {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.turn-guidance-card {
  border-left: 3px solid var(--orange);
  padding: 10px 12px;
  background: rgba(177, 82, 34, 0.08);
}

.turn-guidance-card h4,
.turn-guidance-card p {
  margin: 0;
}

.turn-guidance-card h4 {
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.chat-form textarea { min-height: 120px; }
.feedback-target { display: grid; gap: 12px; }

.realtime-voice {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.realtime-transcript {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
  margin-top: 14px;
  border-left: 3px solid var(--teal);
  padding: 8px 12px;
  background: rgba(23, 107, 101, 0.06);
}

.realtime-transcript p { margin: 0; }

.realtime-transcript-line {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.realtime-transcript-line[data-role="assistant"] { color: var(--teal-deep); }

.realtime-voice.unavailable {
  border: 1px solid rgba(177, 82, 34, 0.25);
  border-radius: 18px;
  padding: 18px;
  background: rgba(177, 82, 34, 0.08);
}

.realtime-audio {
  display: none;
}

.audio-progress {
  width: 100%;
  height: 10px;
  margin-top: 16px;
  accent-color: var(--teal);
}

.feedback-card ul { margin-bottom: 0; padding-left: 20px; color: var(--ink-soft); }
.feedback-card li { margin: 5px 0; line-height: 1.45; }
.feedback-card pre { overflow: auto; color: var(--ink-soft); white-space: pre-wrap; }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 760px) {
  .portal { padding-top: 16px; }
  .layout { grid-template-columns: 1fr; }
  .masthead { margin-bottom: 20px; }
  .workflow-heading { display: grid; }
  .steps { overflow-x: auto; grid-template-columns: repeat(var(--step-count), minmax(120px, 1fr)); }
}
