/* ============================================
   Plant Encyclopedia - Premium Mobile UI
   v1.2.0 - History panel toggle button added
   ============================================ */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --accent: #34c759;
  --accent-dark: #28a745;
  --border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.08);
  --radius: 20px;
  --radius-sm: 12px;
  --font:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    sans-serif;
}

/* ============================================
   GLOBAL RESET
   ============================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============================================
   SITE HEADER (home view)
   ============================================ */

.site-header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 50;
  height: 56px;
  background: var(--bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
}

.header-logo-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
}

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

/* Home header: left group (logo + tag) + right theme button */
.header-left-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-theme-btn {
  width: 40px;
  height: 36px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.home-theme-btn:active {
  background: rgba(52, 199, 89, 0.1);
}

.header-logo-img {
  height: 32px;
  width: 32px;
  border-radius: 8px;
  object-fit: contain;
}

.header-logo-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.header-tag {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ============================================
   HOME VIEW
   ============================================ */

/* Prevent page scroll - only history panel scrolls */
#homeView {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}

#homeView::before {
  content: "";
  position: absolute;
  top: -20%;
  right: -25%;
  width: 70vw;
  height: 70vw;
  background: radial-gradient(
    circle,
    rgba(52, 199, 89, 0.07) 0%,
    transparent 70%
  );
  pointer-events: none;
}

.home-inner {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 28px 48px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.home-hero-logo {
  height: 80px;
  width: 80px;
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}

.home-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 10px;
}

.home-title span {
  display: none;
}

.home-desc {
  font-size: 20px;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 400px;
  margin-bottom: 36px;
}

.home-search {
  width: 100%;
  max-width: 420px;
  position: relative;
  margin-bottom: 20px;
}

.home-input {
  width: 100%;
  height: 56px;
  padding: 0 52px 0 20px;
  font-size: 16px;
  font-family: var(--font);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: all 0.2s ease;
  color: var(--text-primary);
}

.home-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.1);
}

.home-input::placeholder {
  color: #b4b4b8;
}

.home-search-icon {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  opacity: 0.4;
}

.home-btn {
  width: 100%;
  max-width: 420px;
  height: 56px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(52, 199, 89, 0.3);
  letter-spacing: 0.3px;
}

.home-btn:active {
  transform: scale(0.98);
  background: var(--accent-dark);
}

.home-error {
  font-size: 13px;
  color: #ff3b30;
  min-height: 18px;
  margin-bottom: 12px;
  max-width: 420px;
  width: 100%;
}

.home-examples {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
  margin-bottom: 24px;
}

.example-chip {
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
}
.example-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(52, 199, 89, 0.04);
}

/* Footer pinned to bottom of #homeView flex column (matches wiki main page) */
.footer {
  margin-top: auto;
  flex-shrink: 0;
}

/* ============================================
   HISTORY SECTION (Home page)
   ============================================ */

.history-section {
  width: 100%;
  max-width: 100%;
  margin-top: 8px;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.history-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.history-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.history-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}

.history-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: visible;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  width: 140px;
  flex-shrink: 0;
}

.history-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.history-card:active {
  transform: scale(0.97);
}

.history-card-img-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  overflow: visible;
  position: relative;
}

.history-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.history-card:hover .history-card-img {
  transform: scale(1.05);
}

.history-card-info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.history-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;
}

.history-card-tab {
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Tab badge colors */
.history-card-tab[data-tab="morphology"] {
  color: #34c759;
  background: rgba(52, 199, 89, 0.08);
}
.history-card-tab[data-tab="evolution"] {
  color: #5856d6;
  background: rgba(88, 86, 214, 0.08);
}
.history-card-tab[data-tab="uses"] {
  color: #ff9500;
  background: rgba(255, 149, 0, 0.08);
}

.history-clear-btn {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.15s;
}
.history-clear-btn:hover {
  color: #ff3b30;
  background: rgba(255, 59, 48, 0.08);
}

.history-card-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  color: white;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  z-index: 5;
}
.history-card:hover .history-card-delete {
  display: flex;
}
.history-card-delete:hover {
  background: #ff3b30;
  transform: scale(1.15);
}

.history-card {
  position: relative;
}
.history-empty {
  width: 100%;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ============================================
   RIGHT SIDE PANEL: History (Collapsible)
   ============================================ */

.history-panel {
  position: fixed;
  top: 56px; /* below explore-header */
  right: 0;
  bottom: 0;
  z-index: 150;
  display: flex;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0;
  overflow: visible;
  pointer-events: none;
}

.history-panel.open {
  width: var(--panel-width, 400px);
  pointer-events: auto;
}

.history-panel.collapsed {
  --panel-width: 48px;
}

/* Hide panel content when collapsed */
.history-panel.collapsed .history-panel-inner {
  visibility: hidden;
  opacity: 0;
}

.history-panel-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 28px;
  height: 56px;
  background: #ff9500;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  transition: all 0.2s ease;
  z-index: 160;
  writing-mode: horizontal-tb;
  box-shadow: 2px 0 12px rgba(255, 149, 0, 0.3);
  pointer-events: auto;
}

.history-panel-toggle:hover {
  background: #34c759;
  box-shadow: -2px 0 12px rgba(52, 199, 89, 0.3);
}

.history-panel.collapsed .history-panel-toggle {
  left: calc(100% - 24px);
}

.history-panel-inner {
  width: 100%;
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: visible;
  min-width: 200px;
}

.history-panel-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-panel-spacer {
  flex: 1;
}

.history-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.history-panel-clear {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.history-panel-clear:hover {
  background: rgba(255, 59, 48, 0.2);
  transform: scale(1.1);
}

.history-panel-collapse,
.history-panel-resize {
  background: #ff9500;
  border: none;
  font-size: 14px;
  color: white;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  font-weight: 600;
}

.history-panel-collapse:hover,
.history-panel-resize:hover {
  background: #34c759;
  color: white;
}

/* Resize button (right side of header) */
/* Collapsed edge button (visible only when panel is collapsed at 48px) */
.history-panel-collapsed-toggle {
  position: absolute;
  top: 50%;
  right: -28px;
  transform: translateY(-50%);
  width: 28px;
  height: 52px;
  background: #ff9500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  transition: all 0.2s ease;
  z-index: 200;
  box-shadow: -2px 2px 8px rgba(255, 149, 0, 0.3);
  pointer-events: auto;
}

.history-panel-collapsed-toggle:hover {
  background: #34c759;
  box-shadow: -2px 2px 8px rgba(52, 199, 89, 0.3);
}

/* Show collapsed toggle only when panel is collapsed */
.history-panel.collapsed .history-panel-toggle {
  right: auto;
  left: 0;
  z-index: 5;
}

.history-panel.collapsed .history-panel-collapsed-toggle {
  display: flex;
  z-index: 200;
}

.history-panel-clear {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.history-panel-clear:hover {
  background: rgba(255, 59, 48, 0.1);
}

.history-panel-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  align-content: start;
}

.history-panel-grid::-webkit-scrollbar {
  width: 4px;
}
.history-panel-grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Panel history card overrides (smaller for narrow panel) */
.history-panel-grid .history-card {
  width: 100%;
  max-width: 180px;
  margin: 0 auto;
}

.history-panel.collapsed .history-panel-grid .history-card {
  max-width: 140px;
}

/* History panel: always visible (both home and explore views) */
.history-panel {
  display: flex;
}

/* ============================================
   EXPLORE VIEW
   ============================================ */

#exploreView {
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-bottom: 72px;
}

.explore-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  height: 56px;
  position: relative;
}

.explore-logo-link {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  width: 30px;
  flex-shrink: 0;
  margin-right: 4px;
  border-radius: 8px;
  overflow: visible;
  text-decoration: none;
  color: inherit;
}

.explore-logo {
  height: 32px;
  width: 32px;
  border-radius: 8px;
  object-fit: contain;
}

.explore-nav-btn {
  width: 44px;
  height: 36px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--accent);
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.explore-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}
.explore-nav-btn:active:not(:disabled) {
  background: rgba(52, 199, 89, 0.1);
}

/* Header left zone */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1;
}

/* Header center zone (absolute centered) */
.explore-query {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;
  max-width: 40%;
  text-align: center;
  z-index: 2;
}

/* Header right zone */
.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 1;
}

/* Header hint text */
.header-hint {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  margin-right: 4px;
}

.hint-desktop {
  display: inline;
}
.hint-mobile {
  display: none;
}

@media (max-width: 767px) {
  .hint-desktop {
    display: none;
  }
  .hint-mobile {
    display: inline;
    font-size: 11px;
  }
  .header-hint {
    margin-right: 2px;
  }
}

.explore-lang-bar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px;
  background: var(--surface);
}

.lang-select {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
}

/* ============================================
   FLOATING BOTTOM DOCK
   ============================================ */

#bottomDock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px)) 6px;
  display: none;
}
#bottomDock.visible {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dock-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 0;
  position: relative;
}

.dock-btn .dock-icon {
  font-size: 20px;
  line-height: 1;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dock-btn .dock-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;
  max-width: 100%;
  font-family: var(--font);
  transition: color 0.2s;
}
.dock-btn .dock-logo {
  height: 22px;
  width: 22px;
  border-radius: 5px;
  object-fit: contain;
}

.dock-btn.active .dock-label {
  color: var(--accent);
  font-weight: 600;
}
.dock-btn.active .dock-icon {
  color: var(--accent);
}

.dock-btn.dock-plant {
  flex: 1.4;
}
.dock-btn.dock-plant .dock-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
}
.dock-btn.dock-plant.active .dock-label {
  color: var(--accent);
}

/* ============================================
   OLD TAB BAR (hidden)
   ============================================ */
#tabs {
  display: none;
}

/* ============================================
   EXPLORE CONTENT - LEFT/RIGHT SPLIT LAYOUT
   Left: large image | Right: thumbnails + caption
   ============================================ */

.explore-content {
  display: flex;
  flex: 1;
  overflow: visible;
  height: 0; /* Force flex container to respect parent height */
  transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Shrink content when panel is open (via JS adding class to body) */
body.panel-open .explore-content {
  margin-right: var(--panel-width, 400px);
}

body.panel-open.panel-narrow .explore-content {
  margin-right: 48px;
}

/* ====== Left: Large Image Area ====== */
.explore-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.poster-frame {
  position: relative;
  background: var(--surface);
  margin: 6px;
  border-radius: var(--radius);
  overflow: visible;
  box-shadow: var(--shadow-md);
  flex: 1;
}

.poster-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.poster-image[src=""] {
  visibility: hidden;
}

/* ====== Image Generation Loading Overlay ====== */

.image-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(250, 250, 250, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
}

.image-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(52, 199, 89, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

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

.image-loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.image-loading-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.image-loading-progress {
  width: 140px;
  height: 3px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  overflow: visible;
}

.image-loading-bar {
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, var(--accent), #58d68d, var(--accent));
  background-size: 200% 100%;
  border-radius: 2px;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ====== General Page Loading Overlay ====== */

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.loading-spinner {
  margin-bottom: 12px;
}
.spinner-logo {
  height: 56px;
  width: 56px;
  border-radius: 18px;
  object-fit: fill;
  animation: logo-breathe 2s ease-in-out infinite;
}

@keyframes logo-breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

.loading-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.loading-sub {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.loading-progress {
  width: 120px;
  height: 3px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  margin-top: 16px;
  overflow: visible;
}

.loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: loading 2s ease-in-out infinite;
  width: 40%;
}

@keyframes loading {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

/* Click zone */
.click-zone {
  text-align: center;
  padding: 8px 16px 4px;
}
.click-hint {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* ====== Right Sidebar: Thumbnails (top) + Caption (bottom) ====== */
.explore-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow: visible;
  min-height: 0;
}

/* Caption Title - fixed header above caption */
.caption-title {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

/* Caption - SIDEBAR MODE, BILINGUAL */
.caption-text {
  padding: 14px 14px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--surface);
  margin: 0;
  border-radius: 0;
  overflow-y: auto;
  text-align: left;
  flex: 1;
  min-height: 0;
}
.caption-text::-webkit-scrollbar {
  width: 5px;
}
.caption-text::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
.caption-text::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* Bilingual caption: Chinese + English (sidebar mode) */
.caption-zh {
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-primary);
  margin-bottom: 8px;
  text-align: left;
}

.caption-en {
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-secondary);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  text-align: left;
}

/* factual-warning REMOVED as requested - orange bar no longer needed */

/* Thumbnails - SIDEBAR MODE (grid layout) */
.thumbnail-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  overflow-y: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  justify-content: center;
  flex-shrink: 0;
}
.thumbnail-strip::-webkit-scrollbar {
  width: 4px;
}
.thumbnail-strip::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.thumbnail-strip button {
  flex: 0 0 56px;
  height: 56px;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: visible;
  cursor: pointer;
  background: var(--bg);
  transition: all 0.2s ease;
  aspect-ratio: 1;
}
.thumbnail-strip button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.2);
}
.thumbnail-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.explore-error {
  padding: 10px 16px;
  font-size: 13px;
  color: #ff3b30;
  text-align: center;
}
.explore-bottom {
  display: none;
}

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */

/* Mobile (< 768px): Vertical stack (no sidebar) */
@media (max-width: 767px) {
  .site-header {
    padding: 0 20px;
  }
  .explore-header {
    padding: 0 20px;
  }
  .header-left {
    gap: 8px;
  }
  .explore-content {
    flex-direction: column;
  }
  .explore-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .thumbnail-strip {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .caption-text {
    text-align: center;
  }
  .caption-zh {
    text-align: center;
  }
  .caption-en {
    text-align: center;
  }

  .home-title {
    font-size: 10px;
  }
  .home-desc {
    font-size: 14px;
    max-width: 100%;
    padding: 0 8px;
  }
  .home-inner {
    padding: 28px 20px 56px;
  }
  .home-search,
  .home-btn,
  .home-error {
    max-width: 100%;
  }
  .home-input {
    height: 52px;
    font-size: 15px;
  }
  #exploreView {
    padding-bottom: 68px;
  }
  .poster-frame {
    margin: 6px;
    border-radius: 16px;
  }
  #bottomDock {
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)) 4px;
  }
  .dock-btn .dock-label {
    font-size: 9px;
  }
  .dock-btn.dock-plant .dock-label {
    font-size: 10px;
  }
  .dock-btn .dock-logo {
    height: 20px;
    width: 20px;
  }
  .dock-btn .dock-icon {
    font-size: 18px;
    height: 22px;
  }
  .history-section {
    width: 100%;
  }
  .history-grid {
    gap: 8px;
  }
  .history-card {
    width: 120px;
  }
  .history-card-info {
    padding: 6px 8px;
  }
  .history-card-name {
    font-size: 12px;
  }
  .history-card-tab {
    font-size: 9px;
    padding: 1px 6px;
  }

  /* Mobile: history panel is narrower */
  .history-panel.open {
    --panel-width: 280px;
  }
  .history-panel.collapsed {
    --panel-width: 48px;
  }
  .history-panel-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 8px;
  }
  .history-panel-grid .history-card {
    max-width: 130px;
  }
}
@media (min-width: 768px) and (max-width: 1024px) {
  .home-inner {
    max-width: 600px;
    margin: 0 auto;
  }
  #exploreView {
    padding-bottom: 72px;
  }
  #bottomDock {
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px)) 6px;
  }
  .dock-btn .dock-label {
    font-size: 11px;
  }
  .history-grid {
    gap: 10px;
  }
  .history-card {
    width: 140px;
  }
}

/* Desktop (1025px+): Full sidebar */
@media (min-width: 1025px) {
  .explore-sidebar {
    width: 280px;
  }
  .poster-frame {
    margin: 8px;
    border-radius: var(--radius-lg);
  }
  .home-inner {
    max-width: 720px;
    margin: 0 auto;
    padding: 48px 32px 56px;
  }
  .home-title {
    font-size: 26px;
  }
  .home-desc {
    font-size: 16px;
    max-width: 480px;
  }
  .home-search,
  .home-btn {
    max-width: 480px;
  }
  #exploreView {
    padding-bottom: 80px;
  }
  #bottomDock {
    max-width: 720px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 20px 20px 0 0;
  }
  .dock-btn .dock-label {
    font-size: 12px;
  }
  .dock-btn.dock-plant .dock-label {
    font-size: 13px;
  }
  .history-section {
    width: 100%;
    margin-top: 16px;
  }
  .history-grid {
    gap: 12px;
  }
  .history-card {
    width: 160px;
    border-radius: 16px;
  }
  .history-card-info {
    padding: 10px 14px;
  }
  .history-card-name {
    font-size: 14px;
  }

  /* Desktop: wider panel cards */
  .history-panel-grid .history-card {
    max-width: 180px;
  }
  .history-panel.collapsed .history-panel-grid .history-card {
    max-width: 140px;
  }
}

/* ============================================
   DARK MODE
   ============================================ */

body.dark {
  --bg: #1c1c1e;
  --surface: #2c2c2e;
  --text-primary: #f5f5f7;
  --text-secondary: #98989d;
  --accent: #30d158;
  --accent-dark: #248a3d;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.4);
}

body.dark /* Prevent page scroll - only history panel scrolls */
#homeView {
  background: rgba(0, 0, 0, 0.85);
}
body.dark .site-header {
  background: rgba(0, 0, 0, 0.85);
}

body.dark .explore-header {
  background: rgba(0, 0, 0, 0.85);
}

body.dark #bottomDock {
  background: rgba(28, 28, 30, 0.92);
}

body.dark .home-input {
  background: var(--surface);
  color: var(--text-primary);
}

body.dark .home-input::placeholder {
  color: #636366;
}

body.dark .home-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.15);
}

body.dark .example-chip {
  background: var(--surface);
  border-color: var(--border);
}
body.dark .example-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(48, 209, 88, 0.06);
}

body.dark .lang-select {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border);
}

body.dark .poster-frame {
  box-shadow: var(--shadow-md);
}

body.dark .loading-overlay,
body.dark .image-loading-overlay {
  background: rgba(28, 28, 30, 0.95);
}

body.dark .image-loading-overlay {
  background: rgba(28, 28, 30, 0.95);
}

body.dark .history-card {
  background: var(--surface);
  border-color: var(--border);
}
body.dark .history-card:hover {
  border-color: var(--accent);
}

body.dark .thumbnail-strip {
  background: var(--surface);
  border-bottom-color: var(--border);
  border-top-color: transparent;
}

body.dark .explore-sidebar {
  border-left-color: var(--border);
}

body.dark .explore-sidebar .thumbnail-strip {
  border-top-color: transparent;
}

body.dark .thumbnail-strip button {
  background: var(--surface);
}

body.dark .caption-text {
  background: var(--surface);
}

body.dark .dock-btn {
  color: var(--text-primary);
}

body.dark .home-btn {
  box-shadow: 0 4px 16px rgba(48, 209, 88, 0.25);
}

body.dark .loading-bar {
  background: var(--accent);
}

body.dark .image-loading-bar {
  background: linear-gradient(90deg, var(--accent), #58d68d, var(--accent));
  background-size: 200% 100%;
}

body.dark .explore-nav-btn {
  color: var(--accent);
}

body.dark .header-tag {
  background: var(--bg);
  border-color: var(--border);
}

/* Dark mode: history panel */
body.dark .history-panel-inner {
  background: var(--bg);
}
body.dark .history-panel-toggle {
  background: #ff9500;
  color: white;
}
body.dark .history-panel-toggle:hover {
  background: #34c759;
  color: white;
}
body.dark .history-panel-clear:hover {
  background: rgba(255, 59, 48, 0.15);
}

/* Dark mode: collapsed toggle */
body.dark .history-panel-collapsed-toggle {
  background: #ff9500;
  color: white;
}
body.dark .history-panel-collapsed-toggle:hover {
  background: #34c759;
  color: white;
}

/* Dark mode transition */
body,
body.dark .site-header,
body.dark .explore-header,
body.dark #bottomDock,
body.dark .home-input,
body.dark .example-chip,
body.dark .history-card,
body.dark .thumbnail-strip button,
body.dark .poster-frame,
body.dark .caption-text {
  transition:
    background 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

/* ============================================
   UTILITY
   ============================================ */

.hidden {
  display: none !important;
}

.header-tag-logo {
  display: none;
}

@media (min-width: 600px) {
  .caption-text {
    margin: 0;
    padding: 18px 24px;
    font-size: 15px;
  }
}
