:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-strong: #f0eee7;
  --text: #1e2320;
  --muted: #68706b;
  --line: #ded9cc;
  --accent: #0f766e;
  --accent-dark: #0b5f58;
  --accent-soft: #d9f0eb;
  --danger: #b42318;
  --warning: #a15c07;
  --shadow: 0 20px 60px rgba(34, 39, 36, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100dvh;
}

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-panel {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.login-panel h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.login-copy {
  margin: 12px 0 24px;
  color: var(--muted);
  line-height: 1.6;
}

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

.login-form label {
  font-size: 14px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.runtime-warning {
  margin: 18px 0 0;
  border: 1px solid #f2c98f;
  border-radius: 8px;
  background: #fff6e6;
  color: #7a4100;
  padding: 10px 12px;
  line-height: 1.5;
  font-size: 14px;
}

.primary-button,
.ghost-button,
.text-bar button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.chat-view {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  gap: 18px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-button:hover {
  border-color: var(--accent);
}

.icon-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-weight: 700;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.settings-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.settings-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #98a29d;
}

.status-dot.ready,
.status-dot.recording {
  background: var(--accent);
}

.status-dot.connecting,
.status-dot.responding {
  background: var(--warning);
}

.status-dot.error {
  background: var(--danger);
}

.messages {
  width: min(100%, 840px);
  min-height: 0;
  justify-self: center;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 8px 2px;
}

.message {
  max-width: min(78%, 640px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 12px;
  line-height: 1.55;
  word-break: break-word;
}

.message-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.message-assistant {
  align-self: flex-start;
}

.message-system,
.message-error {
  align-self: center;
  max-width: min(100%, 720px);
  color: var(--muted);
  background: var(--surface-strong);
}

.message-error {
  color: var(--danger);
}

.message-audio {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.audio-message-content {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.audio-message-label {
  font-weight: 700;
}

.audio-message-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.audio-message-text:empty {
  display: none;
}

.audio-message-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.replay-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 0 12px;
  font-weight: 700;
}

.replay-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

@media (max-width: 640px) {
  .message-audio {
    flex-direction: column;
  }

  .audio-message-actions {
    width: 100%;
  }

  .replay-button {
    flex: 1;
  }
}

.voice-area {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 6px 0;
  touch-action: none;
}

.voice-button {
  width: clamp(150px, 24vw, 220px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 18px 46px rgba(15, 118, 110, 0.28);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.voice-button:hover {
  background: var(--accent-dark);
}

.voice-button.recording {
  background: var(--danger);
  transform: scale(0.98);
}

.voice-hint {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.text-bar {
  width: min(100%, 840px);
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding-bottom: env(safe-area-inset-bottom);
}

.text-bar button {
  min-width: 84px;
  background: var(--text);
  color: #fff;
}

.text-bar button:hover {
  background: #343a36;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(30, 35, 32, 0.42);
  padding: 18px;
}

.settings-panel {
  width: min(100%, 520px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
  box-shadow: var(--shadow);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-header h2 {
  margin: 0;
  font-size: 22px;
}

.settings-field,
.settings-fieldset {
  display: grid;
  gap: 10px;
}

.settings-field span,
.settings-fieldset legend {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.settings-fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.radio-row input {
  width: 18px;
  min-height: 18px;
}

.settings-hint {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 640px) {
  .login-view {
    align-items: stretch;
    padding: 18px;
  }

  .login-panel {
    align-self: center;
    padding: 24px;
  }

  .chat-view {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 12px;
  }

  .top-bar {
    align-items: flex-start;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .status-pill {
    max-width: 58vw;
  }

  .message {
    max-width: 92%;
  }

  .voice-button {
    width: 150px;
    font-size: 17px;
  }

  .text-bar {
    grid-template-columns: minmax(0, 1fr) 72px;
  }

  .text-bar button {
    min-width: 72px;
    padding: 0 12px;
  }

  .settings-panel {
    align-self: end;
    max-height: calc(100dvh - 18px);
  }

  .settings-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
