:root {
  color-scheme: light;
  --phone-w: 390px;
  --phone-h: 844px;
  --bg: #eef2f0;
  --panel: #ffffff;
  --ink: #151b1f;
  --muted: #65717d;
  --line: #dce2e3;
  --accent: #176f63;
  --accent-strong: #10594f;
  --danger: #c84848;
  --shadow: 0 18px 48px rgba(28, 39, 44, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100dvw;
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(23, 111, 99, 0.1), transparent 360px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  position: relative;
  width: var(--phone-w);
  height: var(--phone-h);
  max-width: 100dvw;
  max-height: 100dvh;
  overflow: hidden;
  border: 1px solid rgba(220, 226, 227, 0.96);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  contain: layout paint size;
  touch-action: manipulation;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fbfcfa;
}

.topbar {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 760;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

h2 {
  font-size: 18px;
}

.icon-button {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #edf2ef;
  color: var(--ink);
}

.icon-button span,
.icon-button::before,
.icon-button::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.icon-button span {
  top: 18px;
}

.icon-button::before {
  top: 12px;
}

.icon-button::after {
  top: 24px;
}

.close-button::before,
.close-button::after {
  top: 18px;
}

.close-button::before {
  transform: rotate(45deg);
}

.close-button::after {
  transform: rotate(-45deg);
}

.close-button span {
  display: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 86px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #aab4b9;
}

.status-pill.ready span {
  background: #228b57;
}

.status-pill.recording span {
  background: var(--danger);
}

.conversation {
  min-height: 0;
  padding: 14px;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: linear-gradient(180deg, #fbfcfa, #f5f7f3);
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.message {
  width: min(310px, 92%);
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.5;
  font-size: 14px;
}

.message.user {
  margin-left: auto;
  background: #eaf6f3;
  border-color: #c7e6dc;
}

.message.system,
.message.error {
  width: 100%;
  color: var(--muted);
  background: #f9faf7;
}

.message.error {
  color: #923535;
  border-color: #eec7c7;
  background: #fff6f6;
}

.message small {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.composer {
  display: grid;
  gap: 12px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.talk-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 54px;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(23, 111, 99, 0.24);
  touch-action: none;
  user-select: none;
}

.talk-button.recording {
  background: var(--danger);
  box-shadow: 0 12px 26px rgba(200, 72, 72, 0.24);
}

.mic-icon {
  width: 16px;
  height: 24px;
  border: 3px solid currentColor;
  border-radius: 10px;
  position: relative;
}

.mic-icon::before,
.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: currentColor;
}

.mic-icon::before {
  bottom: -10px;
  width: 3px;
  height: 9px;
}

.mic-icon::after {
  bottom: -13px;
  width: 17px;
  height: 3px;
  border-radius: 3px;
}

.input-stack,
.meter-row {
  display: grid;
  gap: 8px;
  min-width: 0;
}

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

.text-row button,
.primary-action,
.secondary {
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 750;
}

.primary-action {
  width: 100%;
  margin: 2px 0 14px;
}

.level-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e7ecec;
}

.level-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #d59d34);
  transition: width 80ms linear;
}

.meter-row > span {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 111, 99, 0.12);
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: rgba(16, 26, 30, 0);
  transition: background 180ms ease;
}

.settings {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 30;
  width: 340px;
  max-width: calc(100% - 38px);
  height: 100%;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: -16px 0 34px rgba(28, 39, 44, 0.18);
  transform: translateX(104%);
  transition: transform 220ms ease;
}

.app-shell.drawer-open .drawer-backdrop {
  pointer-events: auto;
  background: rgba(16, 26, 30, 0.28);
}

.app-shell.drawer-open .settings {
  transform: translateX(0);
}

.settings-header {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.settings label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.secondary {
  background: #edf2ef;
  color: var(--ink);
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 12px 0 16px;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 750;
}

dl {
  margin: 12px 0 0;
}

dt {
  margin-top: 10px;
  font-weight: 750;
}

dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

@media (max-width: 420px), (max-height: 860px) {
  .app-shell {
    border-radius: 0;
    border: 0;
  }
}
