/* ========== Reset & Base ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-hover: #22222f;
  --border: #2a2a3a;
  --text: #e8e8ef;
  --text-muted: #8888a0;
  --primary: #6c5ce7;
  --primary-glow: rgba(108, 92, 231, 0.35);
  --danger: #ff4757;
  --danger-glow: rgba(255, 71, 87, 0.35);
  --success: #2ed573;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 16px;
}

/* ========== Layout ========== */
.container {
  width: 100%;
  max-width: 560px;
}

header {
  text-align: center;
  padding: 24px 0 8px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 16px;
}

/* ========== Settings Bar ========== */
.settings-bar {
  display: flex;
  align-items: center;
  gap: 16px;
}

.settings-bar .control-row {
  flex: 1;
}

/* ========== Controls ========== */
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 60px;
}

select {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238888a0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ========== Toggle Switch ========== */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

.toggle-label input {
  display: none;
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: "";
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}

.toggle-label input:checked + .toggle-switch {
  background: var(--primary);
}

.toggle-label input:checked + .toggle-switch::after {
  left: 18px;
  background: #fff;
}

/* ========== Result Sections ========== */
.result-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

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

.section-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.text-area {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  min-height: 100px;
  max-height: 240px;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.text-area .placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.text-area .interim {
  color: var(--text-muted);
}

.translation-section .control-row {
  margin-bottom: 12px;
}

/* ========== Copy Button ========== */
.copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: var(--surface-hover);
}

.copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
}

/* ========== Mic Button ========== */
.mic-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 0 0 0 var(--primary-glow);
}

.mic-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--primary-glow);
}

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

.mic-btn.recording {
  background: var(--danger);
  box-shadow: 0 0 20px var(--danger-glow);
  animation: pulse 1.5s ease-in-out infinite;
}

.mic-btn.recording:hover {
  box-shadow: 0 0 30px var(--danger-glow);
}

/* VAD active: brighter glow when speech is detected */
.mic-btn.recording.vad-active {
  box-shadow: 0 0 30px var(--danger-glow), 0 0 60px rgba(255, 71, 87, 0.2);
  animation: pulse-vad 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-glow); }
  50% { box-shadow: 0 0 0 16px transparent; }
}

@keyframes pulse-vad {
  0%, 100% { box-shadow: 0 0 20px var(--danger-glow), 0 0 40px rgba(255, 71, 87, 0.15); }
  50% { box-shadow: 0 0 30px var(--danger-glow), 0 0 60px rgba(255, 71, 87, 0.25); }
}

.mic-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.mic-label.recording {
  color: var(--danger);
  font-weight: 600;
}

.mic-label.error {
  color: var(--danger);
}

/* Prevent SVGs inside button from capturing click/touch events */
.mic-btn svg {
  pointer-events: none;
}

/* ========== VAD Level Indicator ========== */
.vad-indicator {
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.vad-bar {
  height: 100%;
  width: 0%;
  background: var(--danger);
  border-radius: 2px;
  transition: width 0.1s ease-out;
}

/* ========== Shortcut Hint ========== */
.shortcut-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 0;
}

.shortcut-hint kbd {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.7rem;
  line-height: 1.6;
}

/* ========== History ========== */
.history-section .history-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list .placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
  padding: 8px 0;
}

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.history-item:hover {
  border-color: var(--primary);
}

.history-item-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-item-original {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 2px;
}

.history-item-translated {
  font-size: 0.85rem;
  color: var(--primary);
}

.history-item-langs {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========== Model Loading Overlay ========== */
.model-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 15, 20, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.model-loading-content {
  text-align: center;
  max-width: 320px;
  padding: 32px;
}

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

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

.model-loading-text {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 16px;
}

.model-loading-progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.model-loading-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease-out;
}

.model-loading-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* ========== Utility ========== */
.hidden {
  display: none !important;
}

/* ========== Unsupported Banner ========== */
.unsupported-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 14px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 100;
}

/* ========== Scrollbar ========== */
.text-area::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
  width: 6px;
}

.text-area::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.text-area::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
  body {
    padding: 8px;
  }

  header {
    padding: 16px 0 4px;
  }

  header h1 {
    font-size: 1.3rem;
  }

  .settings-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .toggle-label {
    justify-content: flex-end;
  }

  .text-area {
    min-height: 80px;
    font-size: 0.95rem;
  }

  .mic-btn {
    width: 64px;
    height: 64px;
  }

  .mic-btn svg {
    width: 28px;
    height: 28px;
  }
}

/* ========== Mobile-specific (set by JS) ========== */
body.is-mobile .mic-btn {
  width: 80px;
  height: 80px;
  /* Larger tap target on mobile */
}

body.is-mobile .mic-btn svg {
  width: 34px;
  height: 34px;
}

body.is-mobile .mic-container {
  padding: 16px 0;
}

body.is-mobile .mic-label {
  font-size: 0.9rem;
}

/* Prevent text selection on mic button (mobile) */
.mic-btn {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

/* iOS safe area padding */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body.platform-ios {
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.platform-ios .toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }

  body.platform-ios .unsupported-banner {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
}
