:root {
  color-scheme: dark;
  --bg: #05090b;
  --panel: #0b1519;
  --panel-strong: #102027;
  --line: #1f3a41;
  --text: #e7f7f5;
  --muted: #83a0a5;
  --green: #2fe5b1;
  --blue: #46a6ff;
  --red: #ff6b6b;
  --amber: #ffca66;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(5, 9, 11, 0.18), rgba(5, 9, 11, 0.42)),
    url("./assets/bg.jpg") center / cover fixed;
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  color: var(--text);
  font-family: "IBM Plex Sans", "Avenir Next", ui-sans-serif, system-ui, sans-serif;
}

body[data-background="image"] {
  background:
    linear-gradient(180deg, rgba(5, 9, 11, 0.18), rgba(5, 9, 11, 0.42)),
    url("./assets/bg.jpg") center / cover fixed;
}

body[data-background="image"] .control-panel,
body[data-background="image"] .transcript-panel,
body[data-background="image"] .stage {
  background: rgba(4, 12, 15, 0.46);
  backdrop-filter: blur(2px);
}

body[data-background="image"] .avatar-zone {
  background:
    linear-gradient(rgba(47, 229, 177, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 229, 177, 0.08) 1px, transparent 1px),
    rgba(4, 12, 15, 0.32);
  background-size: 28px 28px;
}

body[data-background="image"] .wave-zone {
  background: rgba(4, 12, 15, 0.22);
}

body[data-background="image"] .transcript-grid article,
body[data-background="image"] input,
body[data-background="image"] select,
body[data-background="image"] textarea,
body[data-background="image"] .segmented,
body[data-background="image"] .background-switch {
  background: rgba(4, 12, 15, 0.56);
}

body[data-background="image"] .talk-button {
  background: linear-gradient(180deg, rgba(99, 255, 209, 0.84), rgba(32, 198, 151, 0.72));
}

body[data-background="image"] .secondary {
  background: rgba(23, 52, 60, 0.58);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(4, 12, 15, 0.72);
  backdrop-filter: blur(8px);
}

.startup-overlay[hidden] {
  display: none;
}

.startup-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  width: min(420px, calc(100vw - 48px));
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid rgba(47, 229, 177, 0.36);
  border-radius: 8px;
  color: #d7fff5;
  background: rgba(4, 12, 15, 0.7);
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.32);
}

.startup-authorize {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid rgba(185, 255, 240, 0.36);
  border-radius: 8px;
  color: #03110d;
  background: var(--green);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 14px 40px rgba(47, 229, 177, 0.18);
}

.startup-authorize[hidden] {
  display: none;
}

.shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(11, 21, 25, 0.76);
}

.reconnect-button[hidden] {
  display: none;
}

.connection-loading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin-top: 16px;
  padding: 0 16px;
  border: 1px solid rgba(47, 229, 177, 0.32);
  border-radius: 8px;
  color: #cffff2;
  background: rgba(4, 12, 15, 0.56);
  font-size: 13px;
  font-weight: 800;
  backdrop-filter: blur(2px);
}

.connection-loading[hidden] {
  display: none;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(185, 255, 240, 0.24);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5d757f;
}

.dot[data-state="connecting"] {
  background: var(--amber);
  box-shadow: 0 0 18px rgba(255, 202, 102, 0.5);
}

.dot[data-state="connected"] {
  background: var(--green);
  box-shadow: 0 0 18px rgba(47, 229, 177, 0.5);
}

.dot-blue[data-state="playing"] {
  background: var(--blue);
  box-shadow: 0 0 18px rgba(70, 166, 255, 0.55);
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

.primary,
.secondary {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 7px;
  color: #04100d;
  background: var(--green);
  font-weight: 800;
}

.secondary {
  width: 100%;
  color: var(--text);
  background: #17343c;
  border: 1px solid #2a5962;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(360px, 1fr) 380px;
  align-items: start;
  gap: 18px;
  padding-top: 20px;
}

.control-panel,
.transcript-panel,
.stage {
  min-height: calc(100vh - 126px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 18, 22, 0.82);
}

.control-panel,
.transcript-panel {
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

label,
summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #24464f;
  border-radius: 6px;
  color: var(--text);
  background: #071014;
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--green) 50%),
    linear-gradient(135deg, var(--green) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 18px,
    calc(100% - 12px) 18px;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
  font-family: "SFMono-Regular", "Menlo", ui-monospace, monospace;
  font-size: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 229, 177, 0.12);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #071014;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 6px;
  color: var(--muted);
}

.segmented input:checked + span {
  color: #04100d;
  background: var(--green);
}

.background-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #071014;
}

.background-switch label {
  position: relative;
}

.background-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.background-switch span {
  display: grid;
  place-items: center;
  min-height: 32px;
  min-width: 54px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.background-switch input:checked + span {
  color: #04100d;
  background: var(--green);
}

.talk-button {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 138px;
  margin-bottom: 12px;
  border-radius: 8px;
  color: #04100d;
  background: linear-gradient(180deg, #63ffd1, #20c697);
  box-shadow: 0 18px 50px rgba(47, 229, 177, 0.18);
}

.talk-button span {
  font-size: 24px;
  font-weight: 900;
}

.talk-button small {
  color: rgba(4, 16, 13, 0.72);
  font-weight: 800;
}

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

.settings summary {
  margin-bottom: 14px;
  cursor: pointer;
}

.settings:not([open]) summary {
  margin-bottom: 0;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.stage {
  display: grid;
  grid-template-rows: minmax(320px, 1fr) 220px;
  height: calc(100vh - 126px);
  overflow: hidden;
}

.avatar-zone,
.wave-zone {
  position: relative;
  min-width: 0;
}

.avatar-zone {
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(rgba(47, 229, 177, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 229, 177, 0.06) 1px, transparent 1px),
    #071014;
  background-size: 28px 28px;
}

.avatar-zone::before {
  content: "数字人展示区域";
  position: absolute;
  left: 18px;
  top: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.transcript-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  min-width: 0;
}

.transcript-grid {
  display: grid;
  gap: 14px;
}

.transcript-grid article {
  min-height: 148px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #071014;
}

.transcript-grid p {
  margin-top: 12px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.55;
  word-break: break-word;
}

.error {
  padding: 12px 14px;
  border: 1px solid rgba(255, 107, 107, 0.5);
  border-radius: 7px;
  color: #ffd5d5;
  background: rgba(255, 107, 107, 0.12);
}

.logs {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.logs summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.logs ol {
  min-height: 0;
  margin: 12px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.logs li {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid rgba(31, 58, 65, 0.68);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.logs li span {
  color: var(--muted);
}

.logs li[data-level="error"] {
  color: #ffd5d5;
}

.logs li[data-level="ok"] {
  color: #b9fff0;
}

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

  .transcript-panel {
    grid-column: 1 / -1;
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .status-strip {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .background-switch {
    width: 100%;
  }

  .control-panel,
  .transcript-panel,
  .stage {
    min-height: auto;
  }

  .stage {
    grid-template-rows: 320px 180px;
    height: auto;
  }
}
