/* ─── Reset & Base ─── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-hover: #f0f1f3;
  --border: #e5e7eb;
  --border-light: #f0f1f3;
  --text: #111827;
  --text-sub: #6b7280;
  --text-muted: #9ca3af;
  --accent: #111827;
  --accent-soft: #374151;
  --green: #059669;
  --green-bg: #ecfdf5;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 16px;
  --radius-sm: 10px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

/* ─── Layout ─── */

.app-container {
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  position: relative;
}

/* ─── Header ─── */

.header {
  text-align: center;
  padding: 24px 0 12px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
}

.header p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ─── Status Bar ─── */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 20px;
  margin: 8px 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 100px;
  flex-shrink: 0;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
  flex-shrink: 0;
}

.status-dot.idle { background: var(--text-muted); }
.status-dot.connecting { background: var(--amber); animation: pulse-dot 1s infinite; }
.status-dot.listening { background: var(--green); animation: pulse-dot 1.5s infinite; }
.status-dot.speaking { background: var(--blue); animation: pulse-dot 1s infinite; }
.status-dot.error { background: var(--red); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.status-text {
  font-size: 0.75rem;
  color: var(--text-sub);
  font-weight: 500;
}

/* ─── Visualizer Area ─── */

.visualizer-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 180px;
}

#visualizer {
  width: 100%;
  height: 100%;
  max-height: 340px;
}

/* ─── Mic Button ─── */

.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 0 32px;
  flex-shrink: 0;
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  position: relative;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--bg);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.mic-btn:hover {
  border-color: var(--text);
  transform: scale(1.04);
}

.mic-btn:active {
  transform: scale(0.96);
}

/* Idle */
.mic-btn.idle {
  border-color: var(--text);
  background: var(--text);
  color: white;
}

/* Connecting */
.mic-btn.connecting {
  border-color: var(--amber);
  background: var(--bg);
  animation: spin-gentle 2s infinite linear;
  pointer-events: none;
}

/* Listening */
.mic-btn.listening {
  border-color: var(--green);
  background: var(--green);
  color: white;
  animation: pulse-btn 2s infinite;
}

/* Speaking */
.mic-btn.speaking {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
  animation: pulse-btn 1.5s infinite;
}

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

@keyframes spin-gentle {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.mic-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ─── Toolbar ─── */

.toolbar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 100;
}

.toolbar-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-sub);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.toolbar-btn:hover {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--text-muted);
}

/* ─── Transcript Panel ─── */

.transcript-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: min(400px, 100vw);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.transcript-panel.open {
  right: 0;
}

.transcript-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.transcript-header-bar h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.btn-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.transcript-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.transcript-entry {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}

.transcript-entry.ai {
  border-left: 2px solid var(--blue);
}

.transcript-entry.user {
  border-left: 2px solid var(--green);
}

.transcript-entry.system {
  border-left: 2px solid var(--text-muted);
  opacity: 0.6;
}

.transcript-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.transcript-role {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.transcript-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.transcript-text {
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text);
}

/* ─── API Key Modal ─── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.modal-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.modal-card p {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-card input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.modal-card input:focus {
  border-color: var(--text);
}

.modal-btn {
  width: 100%;
  padding: 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--text);
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-bottom: 14px;
}

.modal-btn:hover {
  opacity: 0.85;
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-link {
  font-size: 0.75rem;
  color: var(--text-sub);
  text-decoration: none;
  font-weight: 500;
}

.modal-link:hover {
  color: var(--text);
  text-decoration: underline;
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Responsive ─── */

@media (max-width: 480px) {
  .app-container { padding: 12px 18px; }
  .header { padding: 18px 0 8px; }
  .header h1 { font-size: 1.1rem; }
  .mic-btn { width: 66px; height: 66px; font-size: 1.5rem; }
  .mic-area { padding: 12px 0 24px; }
  .toolbar { top: 8px; right: 8px; }
  .toolbar-btn { width: 34px; height: 34px; font-size: 0.9rem; }
  .transcript-panel { width: 100vw; right: -100vw; }
}

@media (min-width: 769px) {
  .app-container { max-width: 440px; }
}

@supports (padding: max(0px)) {
  .app-container {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
