/* Thai4Family — Mobile-first dark theme */

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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --gold: #f5a623;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --thai: #ffd700;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(16px + var(--safe-bottom));
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--accent2);
}
header .flag { font-size: 1.6rem; }
header h1 { flex: 1; font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.icon-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 4px; }

/* Mode bar */
.mode-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: var(--surface2);
  border-bottom: 2px solid var(--accent2);
}
.mode-btn {
  padding: 14px 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
}
.mode-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

/* Mode panels */
.mode-panel { display: none; padding: 20px; }
.mode-panel.active { display: block; }

.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* Mic button */
.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.mic-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 3px solid var(--accent2);
  background: var(--surface2);
  font-size: 2.2rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mic-btn:active { transform: scale(0.93); }
.mic-btn.recording {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.4); }
  50% { box-shadow: 0 0 0 14px rgba(233,69,96,0); }
}
.status-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

/* Thai heard / English spoken */
.thai-text, .english-spoken {
  text-align: center;
  font-size: 1rem;
  color: var(--text-dim);
  min-height: 28px;
  margin-bottom: 12px;
  font-style: italic;
}
.thai-text { font-size: 1.2rem; color: var(--thai); font-style: normal; }

/* Translation box */
.translation-box {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 80px;
}
.translation-box .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.result-text {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--text);
}
.result-text.thai {
  font-size: 1.5rem;
  color: var(--thai);
  font-weight: 600;
  margin-bottom: 6px;
}
.rtgs-text {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-style: italic;
}
.context-note {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--gold);
  font-style: italic;
  line-height: 1.4;
}

/* TTS controls */
.tts-controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.play-btn, .replay-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.play-btn { background: var(--accent); color: white; }
.replay-btn { background: var(--accent2); color: var(--text); }
.play-btn:disabled, .replay-btn:disabled { opacity: 0.35; cursor: default; }

/* History */
#historyPanel {
  margin: 0 16px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--accent2);
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--accent2);
}
.clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
}
#historyList {
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.history-item.me { background: rgba(15,52,96,0.6); border-left: 3px solid var(--accent2); }
.history-item.them { background: rgba(233,69,96,0.08); border-left: 3px solid var(--accent); }
.history-speaker { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; color: var(--text-dim); margin-bottom: 3px; }
.history-time { font-weight: 400; margin-left: 6px; }
.history-original { color: var(--text-dim); font-style: italic; }
.history-translation { color: var(--text); margin-top: 2px; }

/* Manual text input fallback */
.manual-input {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.manual-input input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
}
.manual-input input::placeholder { color: var(--text-dim); }
.manual-input button {
  background: var(--accent2);
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.manual-input button:disabled { opacity: 0.4; }

/* Source toggle (Mic / Video) */
.source-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.source-btn {
  padding: 10px 8px;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.source-btn.active {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--text);
}
.source-panel.hidden { display: none; }

/* Extension status */
.ext-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 0.88rem;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #333;
  flex-shrink: 0;
}
.dot.active {
  background: var(--accent);
  animation: pulse-dot 1s infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity: 1; } 50% { opacity: 0.3; }
}
.ext-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
  margin-bottom: 16px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.modal-content h2 { font-size: 1.1rem; color: var(--gold); }
.modal-content label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  gap: 12px;
}
.modal-content input[type="text"] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.8rem;
}
.modal-content select {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
}
.modal-content input[type="range"] { flex: 1; accent-color: var(--accent); }
.save-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.close-btn {
  background: none;
  border: 1px solid var(--accent2);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
}
