:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #087f5b;
  --accent-strong: #066949;
  --warn: #b54708;
  --user: #e8f3ff;
  --assistant: #f0f7f4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1220px, calc(100vw - 32px));
  height: 100dvh;
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgb(31 41 55 / 4%);
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.status-pill.ready {
  background: #e7f7ef;
  color: var(--accent-strong);
}

.status-pill.error {
  background: #fff4ed;
  color: var(--warn);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  margin-top: 18px;
  min-height: 0;
}

.chat-panel,
.control-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 26px rgb(31 41 55 / 4%);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message {
  width: fit-content;
  max-width: min(720px, 92%);
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  margin-left: auto;
  background: var(--user);
}

.message.assistant {
  background: var(--assistant);
}

.control-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 18px;
  min-width: 0;
}

.voice-actions {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.mic-button {
  width: 116px;
  height: 116px;
  margin: 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 42px;
  cursor: pointer;
  box-shadow: 0 12px 24px rgb(8 127 91 / 20%);
}

.stop-speech-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.stop-speech-button:hover {
  background: #f8fafc;
}

.mic-button.recording {
  background: #d92d20;
  box-shadow: 0 12px 24px rgb(217 45 32 / 20%);
}

.mic-button.preparing {
  background: #0b5cad;
  box-shadow: 0 12px 24px rgb(11 92 173 / 20%);
}

.mic-button.speaking {
  background: #7a4d00;
  box-shadow: 0 12px 24px rgb(122 77 0 / 18%);
}

.message-text {
  margin-bottom: 8px;
}

.recording-player {
  display: block;
  width: min(280px, 100%);
  height: 34px;
  margin-top: 8px;
}

.recording-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent-strong);
  font-size: 12px;
  text-decoration: none;
}

.recording-link:hover {
  text-decoration: underline;
}

.mini-log {
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 920px) {
  .app-shell {
    width: 100%;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
  }

  .topbar {
    padding: 12px 14px;
  }

  h1 {
    font-size: 20px;
  }

  p {
    font-size: 14px;
  }

  .status-pill {
    min-width: 68px;
    padding: 7px 10px;
    font-size: 13px;
  }

  .chat-panel {
    flex: 1 1 auto;
    min-height: 0;
    padding: 12px;
  }

  .control-panel {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    padding: 10px;
  }

  .voice-actions {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-rows: 64px 34px;
    gap: 8px;
  }

  .mic-button {
    width: 64px;
    height: 64px;
    font-size: 28px;
    box-shadow: 0 8px 18px rgb(8 127 91 / 18%);
  }

  .stop-speech-button {
    min-height: 34px;
    width: 64px;
    padding: 0 6px;
    font-size: 12px;
    line-height: 1.15;
  }

  .mini-log {
    grid-column: 2;
    grid-row: 1;
    min-height: 106px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    font-size: 13px;
  }

  .message {
    max-width: 94%;
    margin-bottom: 10px;
    padding: 10px 12px;
    line-height: 1.55;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .topbar {
    gap: 10px;
  }

  h1 {
    font-size: 18px;
  }

  .topbar p {
    margin-top: 4px;
    font-size: 12px;
  }

  .workspace {
    gap: 8px;
    margin-top: 8px;
  }

  .control-panel {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .voice-actions {
    grid-template-rows: 58px 34px;
  }

  .mic-button {
    width: 58px;
    height: 58px;
    font-size: 25px;
  }

  .stop-speech-button {
    width: 58px;
    font-size: 11px;
  }

  .status-pill {
    min-width: 60px;
    font-size: 12px;
  }

  .mini-log {
    min-height: 100px;
  }
}
