/* ============================================================
   English E-Textbook Teaching System — Stylesheet
   ============================================================ */

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

:root {
  /* Color scheme: clean educational blue/white */
  --color-primary: #1a73e8;
  --color-primary-hover: #1557b0;
  --color-primary-light: #e8f0fe;
  --color-primary-bg: #f5f8ff;
  --color-accent: #34a853;
  --color-danger: #ea4335;
  --color-warning: #fbbc04;
  --color-text: #202124;
  --color-text-secondary: #5f6368;
  --color-text-light: #80868b;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #dadce0;
  --color-border-light: #e8eaed;
  --color-shadow: rgba(0, 0, 0, 0.08);
  --color-shadow-strong: rgba(0, 0, 0, 0.15);
  --color-overlay: rgba(0, 0, 0, 0.4);

  /* Sizing */
  --toolbar-height: 56px;
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 0px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  outline: none;
}

button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

img {
  display: block;
  max-width: 100%;
}

svg {
  display: block;
  flex-shrink: 0;
}

/* ============================================================
   Book Selection Page
   ============================================================ */
#book-selector {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: linear-gradient(135deg, var(--color-primary-bg) 0%, var(--color-bg) 100%);
}

#selector-header {
  text-align: center;
  padding: 48px 24px 24px;
}

#selector-header h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

#selector-header .subtitle {
  font-size: 16px;
  color: var(--color-text-secondary);
}

.selector-user-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.auth-btn:hover {
  background: var(--color-primary-hover);
}

.auth-btn-outline {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.auth-btn-outline:hover {
  background: var(--color-primary-light);
}

/* ---------- Student View ---------- */
.student-view {
  padding: 24px 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.student-welcome {
  text-align: center;
  margin-bottom: 32px;
}

.student-welcome h2 {
  font-size: 24px;
  color: var(--color-text);
  margin-bottom: 8px;
}

.student-role-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 13px;
  font-weight: 500;
}

.student-section {
  margin-bottom: 32px;
}

.student-section h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-border-light);
}

.student-empty {
  text-align: center;
  color: var(--color-text-light);
  font-size: 14px;
  padding: 32px;
  background: var(--color-bg);
  border-radius: var(--radius-lg);
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.recent-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.recent-book {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
}

.recent-pages {
  font-size: 13px;
  color: var(--color-text-secondary);
}

#book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  padding: 24px 40px 48px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.book-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px var(--color-shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--color-shadow-strong);
}

.book-card:active {
  transform: translateY(-2px);
}

.book-card-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary-bg));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.book-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card-cover-placeholder {
  width: 64px;
  height: 64px;
  color: var(--color-primary);
  opacity: 0.6;
}

.book-card-info {
  padding: 16px;
}

.book-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.book-card-meta span {
  font-size: 12px;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--color-text-light);
}

.empty-state .empty-icon {
  font-size: 64px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 16px;
}

/* ============================================================
   Reader Page
   ============================================================ */
#reader {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- Toolbar ---------- */
#toolbar {
  height: var(--toolbar-height);
  min-height: var(--toolbar-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 100;
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  min-width: 0;
  flex-shrink: 1;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.toolbar-book-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  background: transparent;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

.toolbar-btn:active,
.toolbar-btn.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.annotation-tool-btn.active-tool {
  background: var(--color-primary);
  color: #fff;
}

.annotation-tool-btn.active-tool:hover {
  background: var(--color-primary-hover);
  color: #fff;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-display {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  min-width: 52px;
  text-align: center;
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-jump-input {
  width: 52px;
  height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast);
}

.page-jump-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-light);
}

.page-jump-input::-webkit-inner-spin-button,
.page-jump-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--color-border);
  flex-shrink: 0;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.zoom-level {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  min-width: 40px;
  text-align: center;
}

.annotation-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
}

.annotation-color-picker {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
}

.annotation-color-picker::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.annotation-color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.brush-size-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.brush-label {
  font-size: 11px;
  color: var(--color-text-light);
  font-weight: 500;
}

.brush-size-slider {
  width: 60px;
  height: 4px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* Audio Speed Control */
.audio-speed-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.audio-speed-icon {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.audio-speed-slider {
  width: 70px;
  height: 4px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.speed-display {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  min-width: 32px;
  text-align: center;
  font-family: monospace;
}

.coord-display {
  font-family: monospace;
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* ---------- User Section ---------- */
.user-section {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  position: relative;
  z-index: 200;
}

#btn-favorite.favorited {
  color: var(--color-warning);
}

.user-avatar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}

.user-avatar-btn:hover {
  background: var(--color-border-light);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px var(--color-shadow-strong);
  min-width: 120px;
  display: none;
  z-index: 9999;
}

.user-dropdown.show {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  text-align: left;
  font-size: 13px;
  color: var(--color-text);
  background: none;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--color-bg);
}

/* ---------- Auth Modal ---------- */
.auth-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-panel {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: 360px;
  max-width: 90vw;
  overflow: hidden;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.2);
}

.auth-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-primary-light);
}

.auth-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--color-primary);
}

.auth-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 6px;
}

.auth-input {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--color-text);
  transition: border-color var(--transition-fast);
}

.auth-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.auth-error {
  color: var(--color-danger);
  font-size: 13px;
  min-height: 18px;
}

.auth-submit-btn {
  width: 100%;
  height: 44px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.auth-submit-btn:hover {
  background: var(--color-primary-hover);
}

.auth-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.auth-switch a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* ---------- Profile Modal ---------- */
.profile-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-panel {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: 400px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.profile-header {
  padding: 32px 24px 24px;
  text-align: center;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-bg) 100%);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 600;
  margin: 0 auto 12px;
}

.profile-header h3 {
  margin: 0 0 4px;
  font-size: 20px;
  color: var(--color-text);
}

.profile-username {
  font-size: 14px;
  color: var(--color-text-secondary);
}

.profile-joined {
  display: block;
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 8px;
}

.profile-body {
  padding: 20px 24px;
}

.profile-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.profile-section h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 12px;
}

.profile-favorites {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.fav-item:hover {
  background: var(--color-primary-light);
}

.fav-book {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.fav-page {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.empty-hint {
  text-align: center;
  color: var(--color-text-light);
  font-size: 13px;
  padding: 16px;
}

.profile-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.8);
  color: var(--color-text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.profile-close-btn:hover {
  background: #fff;
  color: var(--color-text);
}

/* ---------- Sidebar: Thumbnails ---------- */
#sidebar {
  position: absolute;
  top: var(--toolbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 90;
  transition: width var(--transition-normal), transform var(--transition-normal);
}

#sidebar.collapsed {
  width: 0;
}

#thumbnail-list {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumbnail-item {
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition-fast), opacity var(--transition-fast);
  position: relative;
  background: var(--color-bg);
}

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

.thumbnail-item.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-light);
}

.thumbnail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-page-number {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

/* ---------- Main View ---------- */
#main-view {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 15px;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition-normal);
  -webkit-overflow-scrolling: touch;
}

#reader.sidebar-hidden #main-view {
  margin-left: 0;
}

#page-wrapper {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: flex-start;
  transform-origin: top center;
  min-width: max-content;
}

.page-container-single {
  position: relative;
  display: inline-block;
  box-shadow: 0 2px 12px var(--color-shadow);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
  transform-origin: top center;
  transition: transform var(--transition-fast);
}

.page-container-single img {
  display: block;
  max-width: 45vw;
  height: auto;
  max-height: 90vh;
  user-select: none;
  -webkit-user-drag: none;
}

#page-container {
  position: relative;
  display: inline-block;
  box-shadow: 0 2px 12px var(--color-shadow);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
  transform-origin: top center;
  transition: transform var(--transition-fast);
}

#page-image {
  display: block;
  max-width: 90vw;
  height: auto;
  max-height: 90vh;
  user-select: none;
  -webkit-user-drag: none;
}

#annotation-canvas,
#annotation-canvas-2 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

#annotation-canvas.drawing-active,
#annotation-canvas-2.drawing-active {
  pointer-events: auto;
  cursor: crosshair;
}

#annotation-canvas.erasing-active,
#annotation-canvas-2.erasing-active {
  pointer-events: auto;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Crect x='2' y='2' width='16' height='16' fill='none' stroke='%23333' stroke-width='2'/%3E%3C/svg%3E") 10 10, cell;
}

#annotation-canvas.text-active,
#annotation-canvas-2.text-active {
  pointer-events: auto;
  cursor: text;
}

/* ---------- Knowledge Point Panels ---------- */
.kp-panel {
  width: 260px;
  min-width: 260px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--toolbar-height) - 50px);
  transition: width var(--transition-normal), min-width var(--transition-normal);
  overflow: hidden;
}

.kp-panel-collapsed {
  width: 40px;
  min-width: 40px;
}

.kp-panel-collapsed .kp-panel-body,
.kp-panel-collapsed .kp-panel-title {
  display: none;
}

.kp-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-primary-light);
  flex-shrink: 0;
}

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

.kp-panel-toggle {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-text-secondary);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.kp-panel-toggle:hover {
  background: rgba(0, 0, 0, 0.08);
}

.kp-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.kp-panel-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--color-text-light);
  font-size: 13px;
}

.kp-card {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.kp-card:last-child {
  margin-bottom: 0;
}

.kp-card:hover {
  border-color: var(--color-border);
}

.kp-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.kp-card-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.kp-badge-语法 {
  background: rgba(26, 115, 232, 0.12);
  color: var(--color-primary);
}

.kp-badge-词汇 {
  background: rgba(52, 168, 83, 0.12);
  color: var(--color-accent);
}

.kp-badge-句型 {
  background: rgba(251, 188, 4, 0.12);
  color: #b8860b;
}

.kp-badge-其他 {
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
}

.kp-badge-问候语,
.kp-badge-自我介绍 {
  background: rgba(236, 72, 153, 0.12);
  color: #db2777;
}

.kp-badge-数字 {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

.kp-badge-颜色 {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.kp-badge-家庭,
.kp-badge-生日 {
  background: rgba(244, 63, 94, 0.12);
  color: #e11d48;
}

.kp-badge-动物 {
  background: rgba(249, 115, 22, 0.12);
  color: #c2410c;
}

.kp-badge-服装 {
  background: rgba(168, 85, 247, 0.12);
  color: #7c3aed;
}

.kp-badge-时间 {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
}

.kp-badge-食物 {
  background: rgba(234, 179, 8, 0.12);
  color: #a16207;
}

.kp-badge-学校,
.kp-badge-学科 {
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
}

.kp-badge-日常生活,
.kp-badge-日常活动,
.kp-badge-家务 {
  background: rgba(107, 114, 128, 0.12);
  color: #4b5563;
}

.kp-badge-运动 {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

.kp-badge-爱好 {
  background: rgba(236, 72, 153, 0.12);
  color: #db2777;
}

.kp-badge-节日 {
  background: rgba(234, 88, 12, 0.12);
  color: #c2410c;
}

.kp-badge-星期 {
  background: rgba(14, 165, 233, 0.12);
  color: #0284c7;
}

.kp-badge-情感,
.kp-badge-情感表达,
.kp-badge-鼓励 {
  background: rgba(168, 85, 247, 0.12);
  color: #7c3aed;
}

.kp-badge-交通,
.kp-badge-环保,
.kp-badge-交通安全 {
  background: rgba(20, 184, 166, 0.12);
  color: #0d9488;
}

.kp-badge-旅行 {
  background: rgba(6, 182, 212, 0.12);
  color: #0891b2;
}

.kp-badge-社交礼仪,
.kp-badge-告别语,
.kp-badge-祝福语 {
  background: rgba(244, 114, 182, 0.12);
  color: #db2777;
}

.kp-badge-手工指令,
.kp-badge-指令,
.kp-badge-指示代词 {
  background: rgba(156, 163, 175, 0.12);
  color: #6b7280;
}

.kp-badge-方位介词,
.kp-badge-疑问句,
.kp-badge-现在进行时,
.kp-badge-频率,
.kp-badge-能力 {
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
}

.kp-badge-购物 {
  background: rgba(217, 119, 6, 0.12);
  color: #b45309;
}

.kp-badge-书信 {
  background: rgba(71, 85, 105, 0.12);
  color: #475569;
}

.kp-badge-地理 {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}

.kp-badge-形容词,
.kp-badge-日常对话 {
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
}

.kp-badge-职业 {
  background: rgba(251, 146, 60, 0.12);
  color: #ea580c;
}

.kp-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.kp-card-content {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}

.kp-card-examples {
  font-size: 11px;
  color: var(--color-text-light);
  font-style: italic;
  line-height: 1.5;
  padding-left: 8px;
  border-left: 2px solid var(--color-border-light);
}

/* ---------- Page Loading ---------- */
.page-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--color-bg);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.page-loading.visible {
  opacity: 1;
  pointer-events: auto;
}

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

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

.loading-text {
  font-size: 13px;
  color: var(--color-text-light);
}

/* ---------- Hotspot Layer ---------- */
#hotspot-layer,
#hotspot-layer-2 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

.hotspot-area {
  position: absolute;
  border: 2px dashed rgba(255, 77, 77, 0.7);
  background: rgba(255, 77, 77, 0.1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.2s ease;
  z-index: 1;
}

.hotspot-area::after {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  color: rgba(255, 77, 77, 0.8);
  font-weight: bold;
  pointer-events: none;
  white-space: nowrap;
}

.hotspot-area:hover {
  background: rgba(255, 77, 77, 0.3);
  border-color: rgba(255, 77, 77, 1);
  border-style: solid;
  box-shadow: 0 0 16px rgba(255, 77, 77, 0.5);
  transform: scale(1.02);
  z-index: 2;
}

.hotspot-area:hover::after {
  color: rgba(255, 77, 77, 1);
  box-shadow: 0 0 16px rgba(26, 115, 232, 0.5);
}

/* ---------- Dialog Bubble ---------- */

.dialog-bubble {
  position: absolute;
  width: 400px;
  max-width: 90vw;
  max-height: calc(100vh - var(--toolbar-height) - 40px);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px var(--color-shadow-strong);
  z-index: 200;
  animation: bubble-appear var(--transition-normal) ease-out;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@keyframes bubble-appear {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dialog-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-primary-light);
  flex-shrink: 0;
  cursor: move;
  user-select: none;
}

.dialog-speaker {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
}

.bubble-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  color: var(--color-text-light);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.bubble-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-text);
}

.dialog-bubble-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.dialog-original {
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  font-weight: 500;
}

.dialog-translation {
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Dialog Knowledge Points */
.dialog-kps {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-border-light);
}

.dialog-kps-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.dialog-kp-item {
  padding: 8px 10px;
  background: var(--color-primary-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.dialog-kp-item:last-child {
  margin-bottom: 0;
}

.dialog-kp-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}

.dialog-kp-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  vertical-align: middle;
}

.dialog-kp-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-top: 4px;
}

.dialog-kp-examples {
  margin-top: 6px;
  padding-left: 10px;
  border-left: 2px solid var(--color-primary-light);
}

.dialog-kp-example {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-style: italic;
  padding: 2px 0;
  line-height: 1.5;
}

.dialog-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg);
  flex-shrink: 0;
}

.bubble-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.play-btn {
  background: var(--color-primary);
  color: #fff;
}

.play-btn:hover {
  background: var(--color-primary-hover);
}

.play-btn.playing {
  background: var(--color-accent);
}

.dialog-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  padding: 4px 10px;
  font-size: 12px;
}

.nav-btn:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.dialog-index {
  font-size: 12px;
  color: var(--color-text-light);
  min-width: 32px;
  text-align: center;
}

/* ---------- Text Annotation Input ---------- */
.text-annotation-input {
  position: absolute;
  width: 320px;
  max-width: 90vw;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 24px var(--color-shadow-strong);
  z-index: 200;
  animation: bubble-appear var(--transition-fast) ease-out;
  overflow: hidden;
}

.annotation-textarea {
  width: 100%;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
}

.annotation-textarea::placeholder {
  color: var(--color-text-light);
}

.text-annotation-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg);
}

.btn-submit,
.btn-cancel {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-submit {
  background: var(--color-primary);
  color: #fff;
}

.btn-submit:hover {
  background: var(--color-primary-hover);
}

.btn-cancel {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-cancel:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

/* ---------- Fullscreen ---------- */
#reader.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: var(--color-bg);
}

#reader.fullscreen #toolbar {
  border-radius: 0;
}

#reader.fullscreen #main-view {
  padding: 12px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  #book-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding: 16px 24px 32px;
  }

  #sidebar {
    width: 180px;
  }

  #main-view {
    margin-left: 180px;
    padding: 16px;
  }

  .dialog-bubble {
    width: 300px;
  }
}

@media (max-width: 768px) {
  :root {
    --toolbar-height: 48px;
  }

  #book-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 12px 16px 24px;
  }

  #selector-header {
    padding: 32px 16px 16px;
  }

  #selector-header h1 {
    font-size: 24px;
  }

  #toolbar {
    gap: 4px;
    padding: 0 8px;
  }

  .toolbar-center {
    gap: 2px;
  }

  .toolbar-btn {
    width: 32px;
    height: 32px;
  }

  .toolbar-divider {
    display: none;
  }

  .toolbar-book-name {
    max-width: 100px;
    font-size: 13px;
  }

  .page-display {
    font-size: 12px;
  }

  .page-jump-input {
    width: 42px;
    height: 28px;
    font-size: 12px;
  }

  .brush-size-wrapper {
    display: none;
  }

  .color-picker-wrapper {
    display: none;
  }

  .audio-speed-wrapper {
    gap: 2px;
  }

  .audio-speed-slider {
    width: 50px;
  }

  .speed-display {
    font-size: 10px;
    min-width: 28px;
  }

  #sidebar {
    width: 100%;
    max-width: 280px;
    position: absolute;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: 4px 0 16px var(--color-shadow);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #main-view {
    margin-left: 0 !important;
    padding: 12px;
  }

  .dialog-bubble {
    width: 260px;
    max-width: 85vw;
  }

  .dialog-original {
    font-size: 14px;
  }

  .dialog-translation {
    font-size: 12px;
  }

  .annotation-tools {
    gap: 2px;
  }
}

@media (max-width: 480px) {
  #book-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px 12px 20px;
  }

  .book-card-name {
    font-size: 13px;
  }

  .book-card-meta span {
    font-size: 10px;
  }

  .book-card-info {
    padding: 10px;
  }

  .toolbar-book-name {
    display: none;
  }

  .page-jump {
    display: none;
  }

  .zoom-level {
    display: none;
  }
}

/* ============================================================
   Scrollbar Styling
   ============================================================ */
#sidebar::-webkit-scrollbar,
#main-view::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#sidebar::-webkit-scrollbar-track,
#main-view::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar::-webkit-scrollbar-thumb,
#main-view::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover,
#main-view::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-light);
}

/* ============================================================
   Utility States
   ============================================================ */
[hidden],
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Teaching Tools — Styles
   ============================================================ */

/* Toolbar button active state for toggle buttons */
.toolbar-btn.tool-active {
  background: var(--color-primary);
  color: #fff;
}

.toolbar-btn.tool-active:hover {
  background: var(--color-primary-hover);
  color: #fff;
}

/* Hotspot hidden state */
.hotspot-layer-hidden .hotspot-area {
  opacity: 0;
  pointer-events: none !important;
}

/* Annotation hidden state */
.annotation-canvas-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Translation hidden in dialog */
.dialog-translation.translation-hidden {
  display: none;
}

/* Big Text Modal */
.big-text-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

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

.big-text-content {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: 48px 64px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.3);
}

.big-text-text {
  font-size: 48px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  margin-bottom: 16px;
  word-break: break-word;
}

.big-text-translation {
  font-size: 28px;
  color: var(--color-text-secondary);
  font-style: italic;
  margin-bottom: 32px;
}

.big-text-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.big-text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  font-size: 20px;
  font-weight: 600;
  background: var(--color-primary-light);
  color: var(--color-primary);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.big-text-btn:hover {
  background: var(--color-primary);
  color: #fff;
}

.big-text-close-btn {
  background: var(--color-border-light);
  color: var(--color-text-secondary);
  font-size: 24px;
}

.big-text-close-btn:hover {
  background: var(--color-danger);
  color: #fff;
}

.big-text-index {
  font-size: 16px;
  color: var(--color-text-secondary);
  min-width: 48px;
  text-align: center;
}

/* Repeat mode - hidden text */
.dialog-original.repeat-hidden {
  color: transparent;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  position: relative;
  min-height: 1.6em;
}

.dialog-original.repeat-hidden::after {
  content: '点击显示';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-primary);
  font-size: 14px;
  font-weight: 500;
}

/* Play All indicator */
.play-all-active #btn-play-all {
  background: var(--color-accent);
  color: #fff;
}

/* Repeat mode indicator */
.repeat-mode-active #btn-repeat-mode {
  background: var(--color-primary);
  color: #fff;
}

/* ============================================================
   Classroom Timer - Side Panel
   ============================================================ */
.timer-side-panel {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
}

.timer-toggle-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.timer-toggle-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.timer-side-body {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
  max-height: 400px;
  overflow: hidden;
  transition: max-width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
  max-width: 200px;
  opacity: 1;
}

.timer-side-panel.collapsed .timer-side-body {
  max-width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
}

.timer-display {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-text);
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  line-height: 1;
  white-space: nowrap;
}

.timer-display.timer-warning {
  color: var(--color-warning);
}

.timer-display.timer-danger {
  color: var(--color-danger);
  animation: timer-blink 0.5s ease-in-out infinite;
}

@keyframes timer-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.timer-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.timer-preset-btn {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
}

.timer-preset-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.timer-preset-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.timer-custom {
  display: flex;
  gap: 4px;
  align-items: center;
}

.timer-custom-input {
  width: 50px;
  height: 28px;
  padding: 2px 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 12px;
  color: var(--color-text);
}

.timer-custom-input:focus {
  border-color: var(--color-primary);
  outline: none;
}

.timer-custom-set {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  background: var(--color-primary-light);
  color: var(--color-primary);
  transition: all var(--transition-fast);
}

.timer-custom-set:hover {
  background: var(--color-primary);
  color: #fff;
}

.timer-controls {
  display: flex;
  gap: 6px;
}

.timer-ctrl-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.timer-start-btn {
  background: var(--color-accent);
  color: #fff;
}

.timer-start-btn:hover {
  background: #2d9249;
}

.timer-pause-btn {
  background: var(--color-warning);
  color: #fff;
}

.timer-pause-btn:hover {
  background: #e5a800;
}

.timer-reset-btn {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.timer-reset-btn:hover {
  background: var(--color-border-light);
}
