/* ==========================================================================
   Study Hub · 基础样式与设计令牌
   ========================================================================== */

:root {
  color-scheme: light;

  --bg:            #f5f6f8;
  --bg-soft:       #eceef2;
  --surface:       #ffffff;
  --surface-2:     #f8f9fb;
  --surface-hover: #f1f3f7;
  --border:        #e2e5ec;
  --border-strong: #cfd4de;

  --text:      #1b1f27;
  --text-soft: #545c6b;
  --text-dim:  #8a92a3;

  --accent:      #4f6ef7;
  --accent-soft: #eaeefe;
  --accent-text: #ffffff;
  --accent-ring: rgba(79, 110, 247, .28);

  --green:  #18a06a;
  --orange: #d98219;
  --red:    #dc3f4d;
  --purple: #8b5cf6;

  --shadow-sm: 0 1px 2px rgba(16, 22, 40, .06);
  --shadow:    0 2px 8px rgba(16, 22, 40, .07), 0 1px 2px rgba(16, 22, 40, .05);
  --shadow-lg: 0 18px 44px rgba(16, 22, 40, .16), 0 2px 8px rgba(16, 22, 40, .08);

  --radius-sm: 7px;
  --radius:    11px;
  --radius-lg: 16px;

  --font: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", -apple-system,
          BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", Roboto, "Helvetica Neue",
          Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas,
               "Liberation Mono", Menlo, monospace;

  --header-h: 58px;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0e1116;
  --bg-soft:       #141922;
  --surface:       #171c25;
  --surface-2:     #1d232e;
  --surface-hover: #222937;
  --border:        #272e3b;
  --border-strong: #38414f;

  --text:      #e6eaf2;
  --text-soft: #a3adbe;
  --text-dim:  #6e7889;

  --accent:      #6b86ff;
  --accent-soft: #1e2740;
  --accent-text: #ffffff;
  --accent-ring: rgba(107, 134, 255, .34);

  --green:  #34c98a;
  --orange: #e3a03f;
  --red:    #f0606e;
  --purple: #a78bfa;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow:    0 2px 10px rgba(0, 0, 0, .38);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .4);
}

/* -------------------------------------------------------------- 重置 */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 作者样式里的 display 会盖掉 UA 的 [hidden]，这里补回来 */
[hidden] { display: none !important; }

h1, h2, h3, h4, h5, h6, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img { max-width: 100%; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-ring); }

/* 滚动条 */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-clip: content-box; background-color: var(--text-dim); }

/* -------------------------------------------------------------- 图标 */

/* 默认尺寸；具体位置（.btn / .card-icon / .empty 等）可以按需覆盖 */
.ico { width: 15px; height: 15px; flex: none; }

/* -------------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s, transform .08s;
  user-select: none;
}
.btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn .ico { width: 15px; height: 15px; flex: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); border-color: transparent; }

.btn-danger { color: var(--red); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 12%, transparent); border-color: color-mix(in srgb, var(--red) 35%, transparent); color: var(--red); }

.btn-icon { width: 34px; padding: 0; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }

/* -------------------------------------------------------------- 表单控件 */

.field { display: flex; flex-direction: column; gap: 6px; }

.field > label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: .01em;
}
.field .hint { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color .14s, box-shadow .14s, background .14s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.textarea { resize: vertical; min-height: 62px; line-height: 1.55; }
.select { cursor: pointer; appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a92a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; color: var(--text-soft); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 34px; height: 19px; border-radius: 99px; background: var(--border-strong);
  position: relative; transition: background .16s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .16s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(15px); }

/* 分段选择器 */
.seg {
  display: flex; border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}
.seg button {
  flex: 1; height: 32px; border: none; background: var(--surface);
  color: var(--text-soft); font-size: 12.5px; cursor: pointer; white-space: nowrap;
  border-right: 1px solid var(--border);
  transition: background .12s, color .12s;
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--surface-hover); color: var(--text); }
.seg button.active { background: var(--accent); color: var(--accent-text); font-weight: 500; }

/* 标签 / 徽标 */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-soft); white-space: nowrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; color: var(--text-soft); cursor: pointer;
  transition: all .14s; user-select: none; white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip .count { font-size: 11px; opacity: .7; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- 弹窗 */

.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(12, 16, 26, .5);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
  animation: mask-in .14s ease;
}
html[data-theme="dark"] .modal-mask { background: rgba(0, 0, 0, .62); }
@keyframes mask-in { from { opacity: 0 } to { opacity: 1 } }

.modal {
  width: 100%; max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s cubic-bezier(.2, .9, .3, 1.1);
  display: flex; flex-direction: column;
  max-height: 88vh;
  margin-bottom: 4vh;
}
.modal.wide { max-width: 880px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(-12px) scale(.98) } to { opacity: 1; transform: none } }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 15.5px; font-weight: 650; flex: 1; }
.modal-head .sub { font-size: 12px; color: var(--text-dim); font-weight: 400; }

.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.modal-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-foot .spacer { flex: 1; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- 提示条 */

.toast-wrap {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 15px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: 13px; color: var(--text);
  animation: toast-in .2s cubic-bezier(.2, .9, .3, 1.15);
  max-width: 76vw;
}
.toast.ok   { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); }
.toast.err  { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.toast .ico { width: 16px; height: 16px; flex: none; }
.toast.ok  .ico { color: var(--green); }
.toast.err .ico { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96) } to { opacity: 1; transform: none } }
.toast.out { animation: toast-out .16s ease forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.97) } }

/* -------------------------------------------------------------- 空状态 */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 66px 20px; text-align: center; color: var(--text-dim);
}
.empty svg { width: 46px; height: 46px; opacity: .4; }
.empty .title { font-size: 15px; font-weight: 600; color: var(--text-soft); }
.empty .desc { font-size: 13px; max-width: 420px; line-height: 1.7; }

/* -------------------------------------------------------------- 拖放区 */

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  width: 100%; padding: 30px 20px;
  border: 2px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-2); color: var(--text-dim);
  font-size: 13px; line-height: 1.7; text-align: center;
  transition: border-color .15s, background .15s, color .15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.over {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
}
.dropzone > svg { width: 30px; height: 30px; opacity: .75; }
.dropzone .dz-title { font-size: 13.5px; font-weight: 550; color: var(--text); }
.dropzone:hover .dz-title, .dropzone.over .dz-title { color: var(--accent); }
.dropzone .dz-hint { font-size: 12px; color: var(--text-dim); }

/* 内联文字按钮 */
.linkish {
  border: none; background: none; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* 上传队列 */
.upload-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 34vh; overflow-y: auto;
}
.upload-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.upload-row .info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.upload-row .info .t { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row .info .p { font-size: 11px; color: var(--text-dim); }

/* -------------------------------------------------------------- 工具类 */

.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.hidden { display: none !important; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
