:root {
  --ink: #16201f;
  --muted: #65706d;
  --paper: #f5f1e8;
  --surface: #fffcf4;
  --line: rgba(22, 32, 31, 0.16);
  --brand: #146c6c;
  --brand-dark: #0d4b4d;
  --accent: #b8463a;
  --warm: #d59b3d;
  --good: #147452;
  --bad: #a13c32;
  --shadow: 0 20px 60px rgba(22, 32, 31, 0.14);
  color: var(--ink);
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(135deg, #f7f2e7 0%, #dbe5e2 48%, #f1d7c8 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fffdf7;
  background: var(--brand);
  cursor: pointer;
  font-weight: 850;
}

button.secondary {
  color: var(--brand-dark);
  background: rgba(20, 108, 108, 0.12);
}

button.danger {
  background: var(--accent);
}

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

a {
  color: inherit;
}

.avatar-app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.avatar-masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 14px clamp(16px, 3vw, 28px);
  background: rgba(255, 252, 244, 0.88);
  backdrop-filter: blur(16px);
}

.avatar-wordmark {
  color: var(--brand-dark);
  text-decoration: none;
  font-weight: 950;
  letter-spacing: 0;
}

.avatar-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--brand-dark);
  font-size: 0.92rem;
  font-weight: 760;
}

.avatar-nav a {
  text-decoration: none;
}

.avatar-badge {
  border: 1px solid rgba(20, 108, 108, 0.22);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 252, 244, 0.72);
  font: 760 0.76rem/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

#avatar-root {
  min-height: 0;
}

.avatar-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  min-height: calc(100vh - 68px);
}

.avatar-stage {
  position: relative;
  min-width: 0;
  min-height: 540px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #e9f0ec 0%, #f7eedf 64%, #cfd8d4 100%);
}

.avatar-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
}

.liveavatar-frame-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #17211f;
}

.liveavatar-frame-wrap iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
  border: 0;
}

.liveavatar-frame-status {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: calc(100% - 28px);
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 8px 10px;
  color: #fffdf7;
  background: rgba(23, 33, 31, 0.78);
  font-size: 0.84rem;
}

.stage-strip {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(22, 32, 31, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 252, 244, 0.84);
  box-shadow: var(--shadow);
}

.avatar-name {
  min-width: 0;
  margin: 0;
  font-weight: 900;
}

.avatar-status {
  min-width: 9rem;
  margin: 0;
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.control-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  padding: 18px;
  background: rgba(255, 252, 244, 0.9);
}

.panel-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 252, 244, 0.72);
}

.panel-section h1,
.panel-section h2,
.panel-section h3,
.panel-section p {
  margin: 0;
}

.panel-section h1 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.panel-section h2 {
  font-size: 1rem;
}

.eyebrow {
  color: var(--brand);
  font: 850 0.74rem/1.1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.45;
}

.code-form {
  display: grid;
  gap: 10px;
}

.field-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.code-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fffdf8;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-line {
  min-height: 1.3em;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.92rem;
}

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

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

.reviewer-evidence-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.reviewer-evidence-status[data-tone="good"] {
  color: var(--good);
}

.reviewer-evidence-status[data-tone="warn"] {
  color: #8a5b00;
}

.voice-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(20, 108, 108, 0.12);
}

.voice-meter span {
  display: block;
  width: calc(var(--level, 0) * 100%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--warm), var(--accent));
  transition: width 90ms linear;
}

.transcript-panel {
  min-height: 0;
  overflow: auto;
}

.transcript-list {
  display: grid;
  gap: 10px;
  min-height: 170px;
}

.transcript-empty {
  color: var(--muted);
  font-size: 0.92rem;
}

.transcript-message {
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--line);
  padding-left: 10px;
}

.transcript-message[data-role="user"] {
  border-color: var(--brand);
}

.transcript-message[data-role="assistant"] {
  border-color: var(--accent);
}

.transcript-role {
  color: var(--muted);
  font: 820 0.72rem/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.transcript-message p {
  margin: 0;
  line-height: 1.42;
}

audio {
  width: 100%;
}

.hidden {
  display: none !important;
}

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

  .avatar-stage {
    min-height: 58vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .avatar-canvas {
    min-height: 58vh;
  }

  .liveavatar-frame-wrap iframe {
    min-height: 58vh;
  }

  .control-panel {
    grid-template-rows: auto;
  }
}

@media (max-width: 620px) {
  .avatar-masthead {
    align-items: flex-start;
    flex-direction: column;
  }

  .avatar-nav {
    justify-content: flex-start;
  }

  .stage-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .avatar-status {
    text-align: left;
  }

  .code-row {
    grid-template-columns: 1fr;
  }
}
