:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eef1f2;
  --border: #d7dddf;
  --text: #182124;
  --muted: #667377;
  --green: #19785b;
  --green-soft: #dcefe8;
  --coral: #c84f3d;
  --coral-soft: #f8e4df;
  --yellow: #b47a12;
  --focus: #1466b8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button,
select,
textarea,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

button,
select {
  min-height: 44px;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent);
  outline-offset: 2px;
}

.app-shell {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-width: 0;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.topbar-actions,
.account-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-bar {
  color: var(--muted);
  font-size: 13px;
}

.account-bar > span {
  max-width: 190px;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-command,
.close-command {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.text-command {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.text-command:hover:not(:disabled) {
  border-color: var(--green);
  color: var(--green);
}

.text-command:disabled {
  cursor: wait;
  opacity: 0.55;
}

.brand-block {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-block > div {
  min-width: 0;
}

.topbar-actions {
  flex: 0 0 auto;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: white;
  font-weight: 700;
}

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

h1 {
  font-size: 17px;
  line-height: 24px;
}

.brand-block p {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b979a;
}

.connection-state[data-state="connecting"] .state-dot {
  background: var(--yellow);
}

.connection-state[data-state="connected"] .state-dot {
  background: var(--green);
}

.connection-state[data-state="error"] .state-dot {
  background: var(--coral);
}

.access-gate {
  min-height: calc(100vh - 76px);
  min-height: calc(100dvh - 76px);
  display: grid;
  place-items: center;
  padding: 36px 20px;
}

.login-form {
  width: min(390px, 100%);
  display: grid;
  gap: 10px;
}

.login-heading {
  display: grid;
  gap: 5px;
  margin-bottom: 18px;
}

.login-heading h2 {
  font-size: 24px;
  line-height: 32px;
}

.login-heading p,
.modal-header p {
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
}

.login-form label,
.share-form > label,
.share-fields label > span {
  color: var(--muted);
  font-size: 13px;
}

.login-form input,
.share-form input,
.share-result input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
}

.auth-submit {
  min-height: 46px;
  margin-top: 8px;
  border: 1px solid var(--green);
  border-radius: 6px;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-weight: 650;
}

.auth-submit:hover:not(:disabled) {
  background: #11684e;
}

.auth-submit:disabled {
  cursor: wait;
  opacity: 0.55;
}

.form-error {
  color: var(--coral);
  font-size: 13px;
  line-height: 20px;
}

.voice-workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

.voice-stage {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 32px;
  padding: clamp(28px, 6vh, 72px) clamp(20px, 7vw, 96px) 36px;
}

.stage-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: 14px;
}

.stage-heading strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.level-display {
  width: min(680px, 100%);
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 24px;
}

.level-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
}

.level-track {
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-muted);
}

.level-track > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 80ms linear;
}

.level-output > span {
  background: var(--coral);
}

.primary-controls {
  justify-self: center;
  display: grid;
  grid-template-columns: 92px minmax(150px, 190px) 92px;
  align-items: center;
  gap: 14px;
}

.call-button,
.icon-command {
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.call-button {
  min-height: 54px;
  padding: 0 24px;
  border-color: var(--green);
  background: var(--green);
  color: white;
  font-weight: 650;
}

.call-button:hover:not(:disabled) {
  background: #11684e;
}

.call-button:disabled,
.icon-command:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-command {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.icon-command[aria-pressed="true"] {
  border-color: var(--yellow);
  background: #fff3d8;
  color: #6d4a09;
}

.danger-command:not(:disabled) {
  border-color: #e3aaa0;
  background: var(--coral-soft);
  color: #8c2e20;
}

.session-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}

.tab-button {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}

.tab-button.active {
  border-bottom-color: var(--green);
  color: var(--text);
  font-weight: 650;
}

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

.tab-panel[hidden] {
  display: none;
}

.transcript,
.event-log,
.settings-panel {
  padding: 24px;
}

.transcript {
  display: grid;
  align-content: start;
  gap: 16px;
}

.empty-state {
  padding: 44px 0;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.transcript-entry {
  display: grid;
  gap: 5px;
}

.transcript-entry span {
  color: var(--muted);
  font-size: 12px;
}

.transcript-entry p {
  font-size: 15px;
  line-height: 24px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.event-log {
  display: grid;
  gap: 8px;
  margin: 0;
  list-style: none;
}

.event-log li {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--surface-muted);
  color: var(--muted);
  font: 12px/18px ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.settings-panel {
  align-content: start;
  display: grid;
  gap: 10px;
}

.field-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

select {
  padding: 0 12px;
}

textarea {
  min-height: 140px;
  resize: vertical;
  padding: 12px;
  line-height: 22px;
}

.check-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(12 18 20 / 55%);
}

.modal-surface {
  width: min(660px, 100%);
  max-height: min(780px, calc(100dvh - 40px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgb(0 0 0 / 18%);
}

.modal-header,
.share-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-header {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.modal-header h2 {
  font-size: 18px;
  line-height: 26px;
}

.close-command {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.share-form {
  display: grid;
  gap: 10px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.share-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.share-fields label {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.share-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--green-soft);
}

.share-result .text-command {
  min-height: 44px;
}

.share-list-heading {
  padding: 18px 22px 10px;
}

.share-list-heading h3 {
  font-size: 15px;
}

.share-list {
  display: grid;
  padding: 0 22px 20px;
}

.share-item {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--surface-muted);
}

.share-item-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.share-item-copy strong,
.share-item-copy span {
  overflow-wrap: anywhere;
}

.share-item-copy strong {
  font-size: 14px;
}

.share-item-copy span,
.share-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.share-item[data-active="false"] {
  opacity: 0.58;
}

.share-empty {
  padding: 6px 22px 24px;
}

.error-banner {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 12px 14px;
  border: 1px solid #dc9b90;
  border-radius: 7px;
  background: #fff2ef;
  color: #7f2a1e;
  font-size: 14px;
  line-height: 21px;
}

@media (max-width: 820px) {
  .voice-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(460px, 58dvh) minmax(360px, 42dvh);
  }

  .voice-stage {
    padding: 26px 20px 24px;
  }

  .session-panel {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 520px) {
  .topbar {
    min-height: 68px;
    padding: 10px 14px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .connection-state {
    padding: 0 9px;
  }

  .connection-state span:last-child {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    gap: 7px;
  }

  .account-bar > span {
    max-width: 92px;
  }

  .account-bar .text-command {
    min-height: 32px;
    padding: 0 8px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .modal-surface {
    width: 100%;
    max-height: 92dvh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .share-fields {
    grid-template-columns: 1fr;
  }

  .voice-workspace {
    grid-template-rows: minmax(410px, 56dvh) minmax(360px, 44dvh);
  }

  .voice-stage {
    gap: 22px;
  }

  .level-row {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 10px;
  }

  .primary-controls {
    width: 100%;
    grid-template-columns: 76px minmax(128px, 1fr) 76px;
    gap: 8px;
  }

  .icon-command {
    padding: 0 7px;
  }

  .transcript,
  .event-log,
  .settings-panel {
    padding: 18px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101516;
    --surface: #171d1f;
    --surface-muted: #232b2d;
    --border: #344044;
    --text: #edf3f4;
    --muted: #9da9ac;
    --green: #2f9e78;
    --green-soft: #173a2f;
    --coral: #e06a56;
    --coral-soft: #41231f;
    --yellow: #d59c35;
    --focus: #63a9ed;
  }

  .icon-command[aria-pressed="true"] {
    background: #3b301a;
    color: #f1ca79;
  }

  .error-banner {
    background: #42231f;
    color: #ffc2b7;
  }
}
