/* ============================================
   Loke Translator - Real-time Translation App
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-surface: #1a1a3e;
  --bg-header: rgba(10, 10, 26, 0.85);
  --bg-control: rgba(10, 10, 26, 0.9);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.3);
  --text-en: #ffffff;
  --text-zh: rgba(255, 255, 255, 0.6);
  --accent: #4A90D9;
  --accent-hover: #5BA0E9;
  --accent-glow: rgba(74, 144, 217, 0.3);
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #00d4aa;
  --warning: #f39c12;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.15);
  --shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 50px rgba(0, 0, 0, 0.6);
  --radius: 8px;
  --radius-lg: 14px;
  --transition: 0.2s ease;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-size-base: 42px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- App Layout --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.header.hidden-controls {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--accent), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  border-color: var(--border-light);
}

/* --- Subtitle Area --- */
.subtitle-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px 30px 10px;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(74, 144, 217, 0.06) 0%, transparent 60%),
    var(--bg-primary);
}

/* --- History Scroll --- */
.history-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
  overflow: hidden;
  transition: opacity 0.3s ease;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  animation: fadeSlideUp 0.3s ease forwards;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.history-item .zh {
  font-size: calc(var(--font-size-base) * 0.38);
  color: var(--text-zh);
  line-height: 1.3;
}

.history-item .en {
  font-size: calc(var(--font-size-base) * 0.48);
  color: var(--text-secondary);
  line-height: 1.3;
  font-weight: 500;
}

/* --- Current Display --- */
.current-display {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: flex-end;
  padding: 12px 0;
  min-height: 120px;
}

.interim-text {
  font-size: calc(var(--font-size-base) * 0.42);
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
  min-height: 1.4em;
  transition: opacity 0.2s ease;
}

.interim-text:empty {
  display: none;
}

.original-text {
  font-size: calc(var(--font-size-base) * 0.48);
  color: var(--text-zh);
  line-height: 1.4;
  min-height: 1.4em;
  transition: opacity 0.3s ease;
}

.original-text:empty {
  display: none;
}

.translated-text {
  font-size: var(--font-size-base);
  color: var(--text-en);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.3px;
  min-height: 1.3em;
  text-shadow: 0 2px 20px rgba(74, 144, 217, 0.2);
  transition: opacity 0.3s ease;
}

.translated-text:empty {
  display: none;
}

/* --- Placeholder --- */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
  user-select: none;
}

.placeholder.hidden {
  display: none;
}

.placeholder-icon {
  font-size: 48px;
  opacity: 0.5;
  animation: float 3s ease-in-out infinite;
}

.placeholder p {
  font-size: 18px;
}

.placeholder-en {
  font-size: 14px !important;
  opacity: 0.7;
}

.placeholder-hint {
  font-size: 12px !important;
  opacity: 0.5 !important;
  margin-top: 8px;
}

/* --- Listening Indicator --- */
.listening-indicator {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--success);
  background: rgba(0, 212, 170, 0.1);
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid rgba(0, 212, 170, 0.2);
  z-index: 10;
  transition: opacity 0.3s ease;
}

.listening-indicator.hidden {
  opacity: 0;
  pointer-events: none;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

/* --- Control Bar --- */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-control);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.control-bar.hidden-controls {
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-light);
}

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

.btn-icon {
  font-size: 16px;
}

.btn-text {
  font-weight: 500;
}

.btn-large {
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #3A7BC8);
  border-color: transparent;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-large:hover {
  background: linear-gradient(135deg, var(--accent-hover), var(--accent));
  box-shadow: 0 4px 25px var(--accent-glow);
}

.btn-large.recording {
  background: linear-gradient(135deg, var(--danger), #c0392b);
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.btn-large.recording:hover {
  background: linear-gradient(135deg, var(--danger-hover), var(--danger));
}

.btn-toggle {
  background: rgba(255, 255, 255, 0.04);
}

.btn-toggle.active {
  background: rgba(74, 144, 217, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
}

.btn-danger {
  background: rgba(231, 76, 60, 0.1);
  border-color: rgba(231, 76, 60, 0.3);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(231, 76, 60, 0.2);
}

/* --- Status Indicator --- */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

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

.status-dot.ready {
  background: var(--success);
}

.status-dot.listening {
  background: var(--danger);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.error {
  background: var(--warning);
}

.status-text {
  font-size: 13px;
}

/* --- Side Panels --- */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100%;
  height: 100dvh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}

.side-panel.open {
  transform: translateX(0);
}

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

.panel-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: all var(--transition);
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.panel-footer .btn {
  flex: 1;
  justify-content: center;
}

/* --- Setting Groups --- */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-group label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.setting-group label.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
  cursor: pointer;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-value {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  min-width: 40px;
  text-align: right;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.select {
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
}

.select:focus {
  border-color: var(--accent);
}

/* --- Switch Toggle --- */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  transition: all var(--transition);
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition);
}

.switch input:checked + .switch-slider {
  background: var(--accent);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
  background: white;
}

/* --- History List --- */
.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-history {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
}

.history-list .zh {
  font-size: 13px;
  color: var(--text-zh);
  line-height: 1.4;
  margin-bottom: 2px;
}

.history-list .en {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
  font-weight: 500;
}

.history-list .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Overlays --- */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  max-width: 500px;
}

.overlay-content h1 {
  font-size: 28px;
  margin-bottom: 16px;
}

.overlay-content p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.6;
}

.overlay-content .en-text {
  font-size: 14px;
  opacity: 0.7;
}

.overlay-content .btn {
  margin-top: 20px;
}

/* --- Fullscreen mode --- */
body.fullscreen-mode .header,
body.fullscreen-mode .control-bar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

body.fullscreen-mode:hover .header,
body.fullscreen-mode:hover .control-bar {
  opacity: 1;
  pointer-events: auto;
}

body.fullscreen-mode .subtitle-area {
  padding: 40px 50px;
}

/* --- Animations --- */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Translating indicator --- */
.translating-indicator {
  font-size: calc(var(--font-size-base) * 0.35);
  color: var(--text-muted);
  font-style: italic;
  animation: fadeIn 0.5s ease;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .subtitle-area {
    padding: 15px 20px 8px;
  }

  :root {
    --font-size-base: 32px;
  }

  .control-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 15px;
  }

  .btn-large {
    padding: 10px 24px;
    font-size: 15px;
  }

  .status-indicator {
    width: 100%;
    justify-content: center;
    margin-left: 0;
    margin-top: 4px;
  }

  .side-panel {
    width: 100%;
    max-width: 100vw;
  }
}

@media (max-width: 480px) {
  :root {
    --font-size-base: 26px;
  }

  .logo-text {
    font-size: 15px;
  }

  .btn-text {
    display: none;
  }

  .btn-large .btn-text {
    display: inline;
    font-size: 14px;
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- Panel Backdrop --- */
.panel-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.panel-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}
