/* =============================================
   English Pronunciation Coach - styles
   ============================================= */

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

:root {
  --bg-dark: #0a0e1a;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border-active: rgba(120,180,255,0.4);

  --primary:   #4f8eff;
  --primary-glow: rgba(79,142,255,0.3);
  --accent:    #a78bfa;
  --accent2:   #34d399;
  --danger:    #f87171;
  --warning:   #fbbf24;

  --text-1:  #f0f4ff;
  --text-2:  #9ba8c0;
  --text-3:  #5c6a84;

  --highlight-bg:  rgba(255,220,0,0.28);
  --highlight-border: #ffd700;
  --highlight-text: #fff3a0;
  --spoken-bg: rgba(79,142,255,0.15);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.45);
  --shadow-glow: 0 0 32px rgba(79,142,255,0.18);

  --font-body: 'Inter', 'Noto Sans TC', sans-serif;
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ─── Animated BG orbs ─── */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  animation: floatOrb 14s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: #4f8eff; top: -120px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #a78bfa; bottom: -80px; right: -80px; animation-delay: -5s; }
.orb-3 { width: 300px; height: 300px; background: #34d399; top: 50%; left: 55%; animation-delay: -9s; }

@keyframes floatOrb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(30px, -40px) scale(1.05); }
  66%       { transform: translate(-20px, 25px) scale(0.97); }
}

/* ─── Container ─── */
.container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
}
.logo { display: flex; align-items: center; gap: 14px; }
.logo-icon { font-size: 2.4rem; line-height: 1; filter: drop-shadow(0 0 12px rgba(79,142,255,0.6)); }
.logo-text h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; background: linear-gradient(135deg, #fff 30%, var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-text p  { font-size: 0.85rem; color: var(--text-2); margin-top: 2px; }
.header-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 100px;
  border: 1px solid var(--border-active);
  background: rgba(79,142,255,0.09);
  font-size: 0.78rem; color: var(--primary); font-weight: 500;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent2); box-shadow: 0 0 8px var(--accent2); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1}50%{opacity:.4} }

/* ─── Main grid ─── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr;
  gap: 20px;
  align-items: start;
}
.input-panel   { display: none; }
.settings-panel{ grid-column: 2; grid-row: 1; position: sticky; top: 20px; }
.reading-panel { grid-column: 1; grid-row: 1; height: calc(100vh - 40px); }

/* ─── Panel ─── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: 0.95rem; font-weight: 600; color: var(--text-1); }
.panel-actions { display: flex; gap: 8px; }

/* ─── Textarea ─── */
.article-textarea {
  flex: 1;
  min-height: 180px;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  padding: 20px 24px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text-1);
  caret-color: var(--primary);
}
.article-textarea::placeholder { color: var(--text-3); }
.input-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}
.word-count { font-size: 0.8rem; color: var(--text-3); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 0.88rem; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6b9fff);
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 22px var(--primary-glow); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text-1); border-color: var(--border-active); }

/* ─── Settings ─── */
.settings-panel { padding-bottom: 0; }
.setting-group { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.setting-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.83rem; color: var(--text-2); margin-bottom: 10px; font-weight: 500;
}
.setting-value { color: var(--primary); font-weight: 600; }
.setting-select {
  width: 100%; padding: 8px 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-1); font-family: var(--font-body); font-size: 0.85rem;
  cursor: pointer; outline: none;
  transition: border-color 0.2s;
}
.setting-select:focus { border-color: var(--border-active); }
.setting-select option { background: #1a1f2e; }
.setting-slider {
  -webkit-appearance: none; width: 100%; height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--pct, 50%), rgba(255,255,255,0.1) var(--pct, 50%));
  outline: none; cursor: pointer;
}
.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); border: 3px solid #fff;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: transform 0.15s;
}
.setting-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-labels {
  display: flex; justify-content: space-between;
  font-size: 0.72rem; color: var(--text-3); margin-top: 6px;
}
.tips-box {
  margin: 16px 20px 20px;
  padding: 14px 16px;
  background: rgba(167,139,250,0.07);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: var(--radius-md);
}
.tips-title { font-size: 0.82rem; font-weight: 600; color: var(--accent); margin-bottom: 10px; }
.tips-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.tips-list li { font-size: 0.78rem; color: var(--text-2); padding-left: 14px; position: relative; line-height: 1.5; }
.tips-list li::before { content: '›'; position: absolute; left: 0; color: var(--accent); font-weight: 700; }

/* ─── Playback Controls ─── */
.playback-controls { display: flex; align-items: center; gap: 10px; }
.ctrl-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.ctrl-btn:hover:not(:disabled) { background: var(--bg-card-hover); color: var(--text-1); border-color: var(--border-active); }
.ctrl-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.ctrl-btn-main {
  width: 50px; height: 50px;
  background: linear-gradient(135deg, var(--primary), #6b9fff);
  color: #fff; border: none;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.ctrl-btn-main:hover:not(:disabled) { transform: scale(1.07); box-shadow: 0 6px 22px var(--primary-glow); }
.ctrl-btn-main:disabled { background: rgba(255,255,255,0.1); box-shadow: none; }

/* ─── Status ─── */
.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}
.status-indicator { display: flex; align-items: center; gap: 8px; font-size: 0.83rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); transition: background 0.3s; }
.status-idle   .status-dot { background: var(--text-3); }
.status-playing .status-dot { background: var(--accent2); animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 8px var(--accent2); }
.status-paused .status-dot { background: var(--warning); }
.status-done   .status-dot { background: var(--primary); }
#status-text { color: var(--text-2); }
.progress-info { font-size: 0.8rem; color: var(--text-3); }

/* ─── Progress bar ─── */
.progress-bar-container {
  height: 3px; background: rgba(255,255,255,0.06);
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--primary);
}

/* ─── Article display ─── */
.article-display {
  flex: 1;
  padding: 24px;
  min-height: 260px;
  overflow-y: auto;
  line-height: 2;
  font-size: 1.05rem;
}
.placeholder-hint {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 200px; gap: 14px; color: var(--text-3);
}
.hint-icon { font-size: 2.4rem; animation: bounce 2s ease-in-out infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0)}50%{transform:translateY(-8px)} }
.placeholder-hint p { font-size: 0.9rem; }

/* ─── Words ─── */
.word {
  display: inline-block;
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 2px;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  position: relative;
}
.word:hover {
  background: rgba(79,142,255,0.15);
  color: var(--primary);
  transform: translateY(-2px);
}
.word.spoken {
  background: var(--spoken-bg);
  color: rgba(255,255,255,0.6);
}
.word.active {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  border-bottom: 2px solid var(--highlight-border);
  animation: wordPop 0.18s ease;
}
@keyframes wordPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.non-word { color: var(--text-2); }
.sentence-break { display: block; margin-bottom: 6px; }

/* ─── Current word display ─── */
.current-word-box {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: rgba(255,220,0,0.04);
  display: flex; align-items: center; gap: 16px;
}
.current-word-label { font-size: 0.75rem; color: var(--text-3); min-width: 60px; }
.current-word { font-size: 1.6rem; font-weight: 700; color: var(--highlight-text); letter-spacing: 1px; }

/* ─── Footer ─── */
.footer {
  text-align: center; font-size: 0.78rem; color: var(--text-3);
  padding: 8px;
}
.highlight-demo {
  background: var(--highlight-bg); color: var(--highlight-text);
  padding: 1px 6px; border-radius: 4px; border-bottom: 2px solid var(--highlight-border);
}

/* ─── Selection-speak popup ─── */
.selection-popup {
  position: absolute;
  z-index: 9999;
  left: -9999px; top: -9999px;
  opacity: 0;
  transform: translateY(6px) scale(0.95);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.55));
}
.selection-popup.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.sel-popup-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #1e2640, #161c30);
  border: 1px solid rgba(120,180,255,0.35);
  border-radius: 12px;
  padding: 9px 14px;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.07);
}
/* little downward arrow */
.sel-popup-arrow {
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px; height: 7px;
  overflow: hidden;
}
.sel-popup-arrow::before {
  content: '';
  position: absolute;
  top: -7px; left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 14px; height: 14px;
  background: #1e2640;
  border: 1px solid rgba(120,180,255,0.35);
}
.sel-label {
  font-size: 0.8rem;
  color: var(--text-2);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sel-speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #6b9fff);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 12px var(--primary-glow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.sel-speak-btn:hover {
  transform: scale(1.04);
  box-shadow: 0 5px 18px var(--primary-glow);
}
.sel-speak-btn:active { transform: scale(0.98); }

/* ─── IPA Tooltip ─── */
.ipa-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px) scale(0.94);
  transition: opacity 0.15s ease, transform 0.15s ease;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.6));
}
.ipa-tooltip.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.ipa-tooltip-inner {
  background: linear-gradient(135deg, #1a2035, #111827);
  border: 1px solid rgba(167,139,250,0.45);
  border-radius: 10px;
  padding: 7px 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
}
.ipa-word {
  font-size: 0.78rem;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.5px;
}
.ipa-text {
  font-size: 1rem;
  color: #c4b5fd;
  font-weight: 600;
  letter-spacing: 1px;
  line-height: 1.2;
}
.ipa-loading {
  font-size: 0.78rem;
  color: var(--text-3);
  font-style: italic;
}
.ipa-not-found {
  font-size: 0.78rem;
  color: var(--text-3);
}
/* tooltip downward arrow */
.ipa-tooltip-arrow {
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px; height: 7px;
  overflow: hidden;
}
.ipa-tooltip-arrow::before {
  content: '';
  position: absolute;
  top: -7px; left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 14px; height: 14px;
  background: #1a2035;
  border: 1px solid rgba(167,139,250,0.45);
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .settings-panel { grid-column: 1; grid-row: 2; position: static; }
  .reading-panel  { grid-column: 1; grid-row: 1; height: 65vh; }
}
@media (max-width: 600px) {
  .container { padding: 12px; }
  .panel-header { padding: 14px 16px; }
  .article-display { padding: 16px; font-size: 1rem; line-height: 1.8; }
  .status-bar { padding: 8px 16px; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .logo-text h1 { font-size: 1.2rem; }
  .reading-panel { height: 70dvh; } /* iOS / Android Safe space */
}
