/* ============  CSS 变量（一键换肤） ============ */
:root {
    /* 主色 */
    --primary: #a3a3a3;
    --primary-light: #ffffff;
    --primary-dark: #ca3838;
  
    /* 中性色 */
    --bg: #f7f8fc;
    --panel: rgba(255, 255, 255, 0.75);
    --text: #1f2937;
    --text-light: #6f6f6f;
    --border: rgba(0, 0, 0, 0.08);
  
    /* 强调 */
    --danger: #ef4444;
    --success: #10b981;
  
  
    /* 过渡 */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  /* 深色模式（自动跟随系统） */
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #111827;
      --panel: rgba(31, 41, 55, 0.75);
      --text: #f9fafb;
      --text-light: #9ca3af;
      --border: rgba(255, 255, 255, 0.08);
      --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
  }
  
  /* ============  通用 reset ============ */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  
  html,
  body {
    height: 100%;
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
      "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    scroll-behavior: smooth;
  }
  
  /* ============  首页（玻璃拟态） ============ */
  #homeScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: clamp(2rem, 5vw, 4rem);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-light) 100%);
  }
  
  #homeScreen h1 {
    font-size: clamp(2rem, 6vw, 3.5rem);
    font-weight: 700;
    margin-bottom: 2rem;
    text-align: center;
    letter-spacing: -1px;
    color: #000000;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }
  
  .card {
    background: var(--panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(1.5rem, 4vw, 2.5rem);
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  /* 按钮统一风格 */
  .btn {
    padding: 0.9rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    width: 100%;
  }
  
  .btn-primary {
    background: var(--primary);
    color: #fff;
  }
  .btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
  }
  
  .btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
  }
  .btn-outline:hover {
    background: var(--primary);
    color: #fff;
  }
  
  /* 输入框 */
  .input {
    padding: 0.9rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    transition: var(--transition);
  }
  .input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  }
  
  /* ============  白板页 ============ */
  #appScreen {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
  
  /* 白板+图库整体布局 */
  #boardLayout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0; /* 让子元素正确滚动 */
  }

  .hidden {
    display: none !important;
  }
  
  /* 顶部工具栏 */
  #controls {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--panel);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
  }
  
  #roomInfo {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-light);
    margin-right: auto;
  }
  
  /* 工具按钮 */
  .tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: var(--transition);
  }
  
  /* 滑块 */
  input[type="range"] {
    width: 100px;
    height: 4px;
    background: var(--border);
    border-radius: 4px;
  }
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: var(--transition);
  }
  input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
  }
  
  /* 色盘 */
  input[type="color"] {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
  }
  input[type="color"]:hover {
    transform: scale(1.1);
  }
  
  /* 画布区域 */
  #boardWrap {
    flex: 1 1 auto;
    padding: 1rem;
    overflow: auto;
    background: var(--bg);
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }
  
  canvas {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: block;
    width: 100%;
    height: auto;
    /* 纵横比由JS动态设置 */
    touch-action: none;
  }

  /* ============  左侧PDF文件管理侧边栏 ============ */
  #pdfSidebar {
    flex: 0 0 200px;
    max-width: 220px;
    padding: 0.75rem 0.75rem 1rem;
    border-right: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    overflow-y: auto;
    order: -1; /* 放到左侧 */
  }

  .pdf-file-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .pdf-file-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background: rgba(0,0,0,0.03);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    gap: 8px;
  }
  .pdf-file-item:hover {
    background: rgba(0,0,0,0.06);
  }
  .pdf-file-item.active {
    background: var(--primary);
    color: #fff;
  }
  .pdf-file-item .file-name {
    flex: 1;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pdf-file-item .file-pages {
    font-size: 0.75rem;
    opacity: 0.7;
  }
  .pdf-file-item .file-delete {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.6;
    font-size: 1rem;
    line-height: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
  }
  .pdf-file-item .file-delete:hover {
    opacity: 1;
    background: rgba(255,0,0,0.2);
  }

  /* ============  图片图库侧边栏 ============ */
  #imageSidebar {
    flex: 0 0 260px;
    max-width: 280px;
    padding: 0.75rem 0.75rem 1rem;
    border-left: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    overflow-y: auto;
    order: 1; /* 放到右侧 */
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
  }

  .sidebar-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    flex: 1;
  }

  .sidebar-icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-light);
    transition: var(--transition);
  }
  .sidebar-icon-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text);
  }

  .sidebar-section {
    margin-bottom: 0.75rem;
  }

  .sidebar-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-light);
    margin-bottom: 0.35rem;
  }

  .sidebar-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
  }

  .sidebar-btn,
  .sidebar-upload-btn {
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    transition: var(--transition);
  }

  .sidebar-btn:hover,
  .sidebar-upload-btn:hover {
    background: #ffffff;
    transform: translateY(-1px);
  }

  /* 次级按钮目前跟主按钮保持一致外观，仅通过文案区分语义 */
  .sidebar-btn-secondary {
    /* 保留类名用于语义，不额外改变样式 */
  }

  .sidebar-upload-btn {
    position: relative;
    overflow: hidden;
  }

  .gallery-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.45rem;
  }

  .gallery-item {
    position: relative;
    border-radius: 0.5rem;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--border);
    cursor: grab;
    transition: var(--transition);
  }
  .gallery-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
  }

  .gallery-item img {
    width: 100%;
    height: 70px;
    object-fit: cover;
    display: block;
    pointer-events: none;
  }

  .gallery-item-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    border: none;
    border-radius: 999px;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
  }
  .gallery-item:hover .gallery-item-delete {
    opacity: 1;
  }

  /* 摄像头区域相关样式已移除，移动端统一通过上传入口调用系统的拍照/相册选择 */
  
  /* ============  响应式细节 ============ */
  @media (max-width: 768px) {
    #controls {
      padding: 0.5rem;
      gap: 0.5rem;
    }
    .tool-btn {
      width: 36px;
      height: 36px;
    }

    #imageSidebar {
      flex: 0 0 210px;
    }
  }