:root {
  --bg: #f5f4ff;
  --bg-grad: radial-gradient(ellipse at top, #ece9ff 0%, #f5f4ff 60%);
  --card: #ffffff;
  --text: #1a1a2e;
  --subtext: #6b6b80;
  --hint: #9ca3af;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e5e7eb;
  --shadow: 0 10px 40px rgba(31, 25, 95, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 2.75rem 2.25rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

p { margin-bottom: 0.5rem; }
p:last-child { margin-bottom: 0; }

.subtext {
  color: var(--subtext);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.hint {
  color: var(--hint);
  font-size: 0.85rem;
  margin-top: 0.875rem;
  margin-bottom: 0;
}

.notice {
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border: 1.5px solid #f59e0b;
  border-left-width: 6px;
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin: 0 0 1.25rem;
  text-align: left;
  color: #78350f;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.12);
}

.notice-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b45309;
  background: rgba(245, 158, 11, 0.18);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.notice p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.notice strong {
  font-weight: 700;
  color: #78350f;
}

.notice-answer {
  margin-top: 0.4rem !important;
  font-size: 1.1rem !important;
  font-weight: 700;
  color: #78350f;
  letter-spacing: -0.005em;
}

#start-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.field-label {
  display: block;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--subtext);
  margin-bottom: -0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#start-form input[type="text"] {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
  outline: none;
  width: 100%;
}

#start-form input[type="text"]::placeholder {
  text-transform: none;
  letter-spacing: normal;
  color: var(--hint);
  font-weight: 400;
}

#start-form input[type="text"]:focus {
  border-color: var(--accent);
  background: #ffffff;
}

#start-form input[type="text"]:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}

.state.hidden { display: none; }

button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  padding: 0.75rem 1.5rem;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  font-size: 1.05rem;
  padding: 0.95rem 1.5rem;
  width: 100%;
  font-weight: 600;
}

button.primary:hover { background: var(--accent-hover); }
button.primary:active { transform: translateY(1px); }

button.secondary {
  background: #f3f4f6;
  color: var(--text);
}

button.secondary:hover { background: #e5e7eb; }

button.danger {
  background: var(--danger);
  color: #ffffff;
}

button.danger:hover { background: var(--danger-hover); }

button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  justify-content: center;
}

.controls button { flex: 1; max-width: 160px; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.pulse {
  width: 120px;
  height: 120px;
  margin: 0.5rem auto 1.5rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse span {
  position: absolute;
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.45);
  animation: pulse-dot 1.8s ease-out infinite;
}

.pulse::before,
.pulse::after {
  content: '';
  position: absolute;
  width: 38px;
  height: 38px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: pulse-ring 1.8s ease-out infinite;
}

.pulse::after { animation-delay: 0.9s; }

@keyframes pulse-ring {
  0% { width: 38px; height: 38px; opacity: 0.7; }
  100% { width: 120px; height: 120px; opacity: 0; }
}

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

.status {
  font-weight: 500;
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}

.transcript {
  margin: 1rem 0 0;
  height: 220px;
  overflow-y: auto;
  padding: 0.85rem;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: left;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.transcript::-webkit-scrollbar { width: 6px; }
.transcript::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.transcript-placeholder {
  color: var(--hint);
  font-size: 0.9rem;
  font-style: italic;
  margin: auto;
  text-align: center;
}

.turn {
  max-width: 88%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  word-wrap: break-word;
  animation: turn-in 0.2s ease-out;
}

@keyframes turn-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.turn-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.2rem;
  opacity: 0.75;
}

.turn.agent {
  align-self: flex-start;
  background: var(--accent-soft);
  color: #1e1b4b;
  border-bottom-left-radius: 4px;
}

.turn.agent .turn-label { color: var(--accent); }

.turn.user {
  align-self: flex-end;
  background: #ecfeff;
  color: #083344;
  border-bottom-right-radius: 4px;
}

.turn.user .turn-label { color: #0891b2; }

#download-btn {
  margin: 1rem 0 0.5rem;
}

#speaker-indicator {
  font-size: 0.85rem;
  min-height: 1.2rem;
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .card { padding: 2rem 1.25rem; border-radius: 14px; }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.3rem; }
  .pulse { width: 100px; height: 100px; }
  @keyframes pulse-ring {
    0% { width: 38px; height: 38px; opacity: 0.7; }
    100% { width: 100px; height: 100px; opacity: 0; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .pulse span, .pulse::before, .pulse::after { animation: none; }
}
