:root {
  --bg: #ece8df;
  --panel: rgba(248, 246, 241, 0.92);
  --panel-strong: #f6f2e8;
  --border: rgba(63, 54, 44, 0.12);
  --text: #201b16;
  --muted: #6f655b;
  --accent: #8a5a32;
  --accent-strong: #5f3a1f;
  --assistant: #ffffff;
  --user: #dcefe4;
  --shadow: 0 24px 70px rgba(52, 44, 35, 0.12);
  --sidebar-width: 320px;
  --coach-left-gap: 24px;
  --coach-bottom-gap: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Inter", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 122, 90, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(177, 137, 72, 0.16), transparent 26%),
    linear-gradient(180deg, #f6f1e7 0%, #ece8df 100%);
}

body {
  min-height: 100vh;
}

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

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 24px 18px;
  background: rgba(244, 239, 230, 0.82);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand-block,
.settings-header,
.key-row,
.composer-actions,
.message {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark,
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-mark {
  background: linear-gradient(135deg, #1f7a5a, #c59f5d);
  color: white;
  box-shadow: var(--shadow);
}

.eyebrow,
.section-label,
.helper-text,
.composer-hint {
  color: var(--muted);
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-size: 1.2rem;
}

.sidebar-button,
.send-button,
.text-button,
.model-select,
.key-input,
textarea {
  border-radius: 16px;
  border: 1px solid var(--border);
}

.sidebar-button,
.send-button,
.text-button {
  cursor: pointer;
}

.sidebar-button {
  width: 100%;
  padding: 12px 14px;
  background: white;
  color: var(--text);
}

.primary-button,
.send-button {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.primary-button:hover,
.send-button:hover {
  background: var(--accent-strong);
}

.sidebar-section {
  margin-top: 20px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.notes-list {
  padding-left: 18px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.settings-header {
  justify-content: space-between;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

.key-row {
  gap: 10px;
}

.key-input,
.model-select {
  width: 100%;
  padding: 12px 14px;
  background: white;
}

.helper-text {
  margin-top: 10px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.settings-textarea {
  width: 100%;
  min-height: 210px;
  margin-top: 4px;
  padding: 12px 14px;
  resize: vertical;
  background: white;
}

.settings-actions {
  margin-top: 12px;
}

.model-select {
  margin-top: 6px;
}

.text-button {
  padding: 8px 10px;
  background: transparent;
}

.chat-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.coach-panel {
  position: fixed;
  left: calc(var(--sidebar-width) + var(--coach-left-gap));
  bottom: var(--coach-bottom-gap);
  z-index: 4;
  width: 224px;
  padding: 16px 16px 14px;
  border: 1px solid rgba(63, 54, 44, 0.1);
  border-radius: 28px;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.96), transparent 30%),
    radial-gradient(circle at 80% 18%, rgba(121, 195, 255, 0.12), transparent 22%),
    linear-gradient(180deg, rgba(252, 249, 244, 0.98) 0%, rgba(243, 237, 228, 0.98) 100%);
  box-shadow:
    0 26px 54px rgba(52, 44, 35, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(14px);
}

.coach-avatar {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.coach-figure {
  position: relative;
  width: 168px;
  height: 164px;
  display: grid;
  place-items: center;
  border-radius: 32px;
  transform-origin: center bottom;
  animation: coach-float 3.2s ease-in-out infinite;
}

.coach-figure::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 10px;
  width: 86px;
  height: 18px;
  border-radius: 999px;
  background: rgba(31, 46, 87, 0.14);
  filter: blur(8px);
  transform: translateX(-50%);
  animation: coach-shadow 3.2s ease-in-out infinite;
}

.coach-figure::before {
  content: "";
  position: absolute;
  inset: 18px 16px 20px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(107, 193, 255, 0.18) 0%, rgba(107, 193, 255, 0.08) 36%, rgba(107, 193, 255, 0) 72%);
  pointer-events: none;
}

.coach-robot {
  position: relative;
  z-index: 1;
  width: 162px;
  height: 162px;
  filter: drop-shadow(0 16px 24px rgba(27, 64, 124, 0.22));
  transform-origin: center bottom;
  animation: coach-sway 3.2s ease-in-out infinite;
}

.robot-shadow {
  fill: rgba(16, 35, 68, 0.12);
}

.robot-aura {
  fill: url(#robot-aura);
  opacity: 0.55;
}

.robot-body {
  transform-origin: center;
}

.robot-face {
  transform-origin: center;
}

.eyes-open {
  animation: eyes-open 5.4s steps(1, end) infinite;
}

.eyes-closed {
  opacity: 0;
  animation: eyes-closed 5.4s steps(1, end) infinite;
}

.mouth-closed,
.mouth-open {
  opacity: 0;
}

.coach-panel.is-speaking .coach-figure {
  animation: coach-speak-bob 620ms ease-in-out infinite;
}

.coach-panel.is-speaking .coach-figure::after {
  animation: coach-shadow-speak 620ms ease-in-out infinite;
}

.coach-panel.is-speaking .coach-figure::before {
  background: radial-gradient(circle, rgba(107, 230, 255, 0.28) 0%, rgba(107, 230, 255, 0.12) 40%, rgba(107, 230, 255, 0) 74%);
}

.coach-panel.is-speaking .coach-robot {
  animation: coach-speak-tilt 620ms ease-in-out infinite;
}

.coach-panel.is-speaking .robot-aura {
  animation: robot-aura-pulse 620ms ease-in-out infinite;
}

.coach-panel.is-speaking .robot-face {
  animation: robot-face-shift 620ms ease-in-out infinite;
}

.coach-panel.is-speaking .eyes-open {
  animation: eyes-open-talk 620ms steps(1, end) infinite;
}

.coach-panel.is-speaking .mouth-smile {
  opacity: 0;
}

.coach-panel.is-speaking .mouth-closed {
  animation: mouth-closed-talk 520ms steps(1, end) infinite;
}

.coach-panel.is-speaking .mouth-open {
  animation: mouth-open-talk 520ms steps(1, end) infinite;
}

.coach-waveform {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  min-height: 18px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.coach-wave-bar {
  width: 5px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #6be6ff 0%, #2f7df0 100%);
  transform-origin: center bottom;
}

.coach-panel.is-speaking .coach-waveform {
  opacity: 1;
  transform: translateY(0);
}

.coach-panel.is-speaking .coach-wave-bar {
  animation: waveform 780ms ease-in-out infinite;
}

.coach-panel.is-speaking .coach-wave-bar:nth-child(2) {
  animation-delay: 120ms;
}

.coach-panel.is-speaking .coach-wave-bar:nth-child(3) {
  animation-delay: 240ms;
}

.coach-panel.is-speaking .coach-wave-bar:nth-child(4) {
  animation-delay: 360ms;
}

.coach-controls {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(36, 79, 150, 0.1);
}

.coach-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1f5ca8;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #5b9dff;
  box-shadow: 0 0 0 4px rgba(91, 157, 255, 0.12);
  flex: 0 0 auto;
}

.coach-panel.is-speaking .status-dot {
  background: #59dfff;
  box-shadow:
    0 0 0 4px rgba(89, 223, 255, 0.18),
    0 0 14px rgba(89, 223, 255, 0.45);
  animation: status-pulse 620ms ease-in-out infinite;
}

.coach-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.coach-voice-row {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
}

.coach-voice-label {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.coach-voice-select {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(36, 79, 150, 0.12);
  background: linear-gradient(180deg, #ffffff 0%, #edf4ff 100%);
  color: #1f5ca8;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.88),
    0 6px 12px rgba(60, 93, 150, 0.06);
}

.coach-button {
  flex: 1 1 auto;
  min-height: 38px;
  padding: 7px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #edf4ff 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.88),
    0 6px 12px rgba(60, 93, 150, 0.06);
}

.coach-button.is-muted {
  color: var(--muted);
  background: #eef0f4;
}

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

.coach-note {
  margin: 10px 2px 0;
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 32px 14px;
}

.messages {
  flex: 1;
  padding: 18px 32px 140px;
  overflow-y: auto;
}

.message {
  align-items: flex-start;
  gap: 16px;
  max-width: 860px;
  margin: 0 auto 26px;
  animation: rise 220ms ease;
}

.message.assistant {
  padding-right: 88px;
}

.message.user {
  flex-direction: row-reverse;
  padding-left: 132px;
}

.message.assistant .avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: linear-gradient(135deg, #efe1be, #f8f2e4);
  color: #6d5220;
  border: 1px solid rgba(125, 93, 40, 0.14);
  box-shadow: 0 12px 28px rgba(125, 93, 40, 0.12);
}

.message.user .avatar {
  width: 36px;
  height: 36px;
  margin-top: 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1f7a5a, #2f8d6c);
  color: #f7fbf9;
  box-shadow: 0 12px 28px rgba(31, 122, 90, 0.24);
}

.bubble {
  width: 100%;
  padding: 18px 20px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--assistant);
  box-shadow: var(--shadow);
  line-height: 1.6;
}

.message.assistant .bubble {
  max-width: 720px;
  border-top-left-radius: 10px;
}

.message.user .bubble {
  width: auto;
  max-width: min(100%, 580px);
  background: var(--user);
  border-top-right-radius: 10px;
  box-shadow: 0 18px 42px rgba(31, 122, 90, 0.12);
  white-space: pre-wrap;
}

.message.user + .message.assistant,
.message.assistant + .message.user {
  margin-top: 34px;
}

.intro-card .bubble p + p {
  margin-top: 10px;
}

.bubble p + p,
.bubble p + ul,
.bubble ul + p,
.bubble h1 + p,
.bubble h2 + p,
.bubble h3 + p,
.bubble pre + p,
.bubble p + pre,
.bubble ul + pre,
.bubble pre + ul {
  margin-top: 12px;
}

.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 0;
  line-height: 1.3;
}

.bubble h1 {
  font-size: 1.25rem;
}

.bubble h2 {
  font-size: 1.12rem;
}

.bubble h3 {
  font-size: 1rem;
}

.bubble ul {
  margin: 0;
  padding-left: 20px;
}

.bubble li + li {
  margin-top: 6px;
}

.bubble a {
  color: var(--accent-strong);
}

.bubble strong {
  font-weight: 800;
}

.bubble code {
  padding: 0.14rem 0.42rem;
  border-radius: 8px;
  background: #f2ede5;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
}

.bubble pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: 18px;
  background: #1e1c19;
  color: #f5f0e7;
}

.bubble pre code {
  display: block;
  padding: 0;
  background: transparent;
  color: inherit;
  white-space: pre;
}

.code-label {
  display: inline-block;
  margin-bottom: 10px;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #d7c6aa;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 20px 24px 28px;
  background: linear-gradient(180deg, rgba(236, 232, 223, 0) 0%, rgba(236, 232, 223, 0.92) 18%, #ece8df 100%);
}

.composer textarea {
  width: min(860px, 100%);
  display: block;
  margin: 0 auto;
  min-height: 64px;
  max-height: 220px;
  resize: none;
  padding: 18px 18px 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.composer-actions {
  width: min(860px, 100%);
  justify-content: space-between;
  margin: 12px auto 0;
}

.send-button {
  min-width: 92px;
  padding: 10px 18px;
}

.mobile-only {
  display: none;
}

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

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes waveform {
  0%,
  100% {
    transform: scaleY(0.55);
    opacity: 0.48;
  }

  50% {
    transform: scaleY(1.65);
    opacity: 1;
  }
}

@keyframes coach-float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

@keyframes coach-shadow {
  0%,
  100% {
    transform: translateX(-50%) scaleX(1);
    opacity: 0.18;
  }

  50% {
    transform: translateX(-50%) scaleX(0.88);
    opacity: 0.1;
  }
}

@keyframes coach-sway {
  0%,
  100% {
    transform: rotate(-1.4deg);
  }

  50% {
    transform: rotate(1.4deg);
  }
}

@keyframes eyes-open {
  0%,
  44%,
  48%,
  92%,
  96%,
  100% {
    opacity: 1;
  }

  45%,
  47%,
  93%,
  95% {
    opacity: 0;
  }
}

@keyframes eyes-open-talk {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.86;
  }
}

@keyframes eyes-closed {
  0%,
  44%,
  48%,
  92%,
  96%,
  100% {
    opacity: 0;
  }

  45%,
  47%,
  93%,
  95% {
    opacity: 1;
  }
}

@keyframes coach-speak-bob {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  25% {
    transform: translateY(-4px) scale(1.01);
  }

  50% {
    transform: translateY(-1px) scale(0.995);
  }

  75% {
    transform: translateY(-5px) scale(1.015);
  }
}

@keyframes coach-shadow-speak {
  0%,
  100% {
    transform: translateX(-50%) scaleX(1);
    opacity: 0.18;
  }

  50% {
    transform: translateX(-50%) scaleX(0.8);
    opacity: 0.09;
  }
}

@keyframes coach-speak-tilt {
  0%,
  100% {
    transform: rotate(-2.2deg);
  }

  25% {
    transform: rotate(1deg) translateY(-1px);
  }

  50% {
    transform: rotate(-0.5deg);
  }

  75% {
    transform: rotate(2.2deg) translateY(-2px);
  }
}

@keyframes robot-aura-pulse {
  0%,
  100% {
    opacity: 0.52;
    transform: scale(1);
  }

  50% {
    opacity: 0.92;
    transform: scale(1.06);
  }
}

@keyframes robot-face-shift {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-1px);
  }
}

@keyframes mouth-closed-talk {
  0%,
  15%,
  36%,
  55%,
  76%,
  100% {
    opacity: 1;
  }

  16%,
  35%,
  56%,
  75% {
    opacity: 0;
  }
}

@keyframes mouth-open-talk {
  0%,
  15%,
  36%,
  55%,
  76%,
  100% {
    opacity: 0;
  }

  16%,
  35%,
  56%,
  75% {
    opacity: 1;
  }
}

@keyframes status-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .coach-figure,
  .coach-figure::after,
  .coach-figure::before,
  .coach-robot,
  .robot-aura,
  .robot-face,
  .eyes-open,
  .eyes-closed,
  .coach-panel.is-speaking .eyes-open,
  .coach-panel.is-speaking .mouth-closed,
  .coach-panel.is-speaking .mouth-open,
  .coach-panel.is-speaking .coach-wave-bar,
  .coach-panel.is-speaking .status-dot {
    animation: none;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 320px);
    z-index: 10;
    overflow-y: auto;
  }

  .sidebar.is-open {
    display: block;
  }

  .mobile-only {
    display: inline-flex;
  }

  .chat-header,
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .coach-panel {
    left: 16px;
    bottom: 122px;
    width: 184px;
    padding: 12px;
  }

  .coach-figure {
    width: 132px;
    height: 132px;
  }

  .coach-robot {
    width: 126px;
    height: 126px;
  }

  .message.assistant,
  .message.user {
    padding-left: 0;
    padding-right: 0;
  }
}

@media (max-width: 640px) {
  .messages {
    padding-bottom: 220px;
  }

  .composer {
    padding-top: 12px;
  }

  .composer textarea,
  .composer-actions {
    width: 100%;
  }

  .coach-panel {
    left: 16px;
    right: 16px;
    bottom: 128px;
    width: auto;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .coach-avatar {
    flex: 0 0 auto;
  }

  .coach-controls {
    flex: 1;
    margin-top: 0;
  }
}
