:root {
  color-scheme: dark;
  --canvas: #08090c;
  --surface: #111318;
  --surface-subtle: #171a20;
  --surface-strong: #21252d;
  --surface-raised: var(--surface-strong);
  --ink: #f5f5f2;
  --ink-primary: var(--ink);
  --ink-secondary: #b3b6bd;
  --ink-tertiary: #7e838d;
  --ink-inverse: #111315;
  --line: #292d35;
  --line-default: var(--line);
  --line-strong: #5a6270;
  --signal: #62e29b;
  --signal-strong: #36be78;
  --signal-soft: #122c20;
  --success: var(--signal-strong);
  --stage: #e7ad50;
  --stage-soft: #302412;
  --warning: var(--stage);
  --danger: #f16d71;
  --danger-soft: #33191d;
  --info: #73b5ff;
  --info-soft: #14263d;
  --shadow: 0 12px 32px rgb(0 0 0 / 28%);
  --shadow-sm: var(--shadow);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --button-height: 40px;
  --control-height-sm: 34px;
  --control-height: 42px;
  --touch-target: 44px;
  --icon-size-sm: 15px;
  --icon-size: 18px;
  --icon-size-lg: 22px;
  --content-max: 1320px;
  --sidebar-width: 248px;
  --player-height: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-nav-height: var(--m-tab-height, 60px);
  --mobile-gutter: 16px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "Segoe UI", Arial, Roboto, "PingFang SC", miui, "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: var(--font-ui);
  --text-1: 12px;
  --text-2: 14px;
  --text-3: 16px;
  --text-4: 18px;
  --text-5: 20px;
  --text-6: 24px;
  --text-7: 28px;
  --text-8: 35px;
  --leading-1: 16px;
  --leading-2: 20px;
  --leading-3: 24px;
  --leading-4: 26px;
  --leading-5: 28px;
  --leading-6: 30px;
  --leading-7: 36px;
  --leading-8: 40px;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --duration-fast: 150ms;
  --duration-enter: 180ms;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  --z-sticky: 20;
  --z-sidebar: 30;
  --z-mobile-nav: 55;
  --z-toast: 1000;
}

/* Layout modes: compact <= 540, mobile < 640, app shell <= 820,
   desktop >= 1280 and wide desktop >= 1440. */

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  scroll-behavior: smooth;
}

/* 手机端与微信小程序 web-view：禁掉双指缩放与双击放大，并阻止 iOS 旋转后的字号放大。 */
html[data-client="mobile"],
html[data-client="mobile"] body {
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-ui);
  font-size: var(--text-2);
  font-weight: var(--weight-regular);
  line-height: var(--leading-2);
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}

body.has-player {
  padding-bottom: var(--player-height);
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: inherit;
}

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

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--signal), transparent 58%);
  outline-offset: 2px;
}

::selection {
  color: var(--ink);
  background: color-mix(in oklch, var(--signal), white 55%);
}

.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;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: 0 0 auto;
  stroke-width: 1.8;
}

.icon-sm {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

.icon-lg {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-size: 15px;
  font-weight: var(--weight-bold);
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-md);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.btn {
  min-height: var(--button-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--ink);
  background: transparent;
  font-weight: var(--weight-medium);
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease), opacity var(--duration-fast) var(--ease);
}

.btn:hover {
  background: var(--surface-subtle);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-primary {
  color: oklch(16% 0.025 145);
  background: var(--signal);
  border-color: var(--signal);
}

.btn-primary:hover {
  background: var(--signal-strong);
  border-color: var(--signal-strong);
  color: oklch(16% 0.025 145);
}

.btn-dark {
  color: var(--ink-inverse);
  background: var(--ink);
  border-color: var(--ink);
}

.btn-dark:hover {
  color: white;
  background: oklch(26% 0.01 85);
  border-color: oklch(26% 0.01 85);
}

.btn-outline {
  border-color: var(--line);
  background: var(--surface);
}

.btn-outline:hover {
  border-color: var(--line-strong);
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in oklch, var(--danger), transparent 68%);
  background: var(--danger-soft);
}

.btn-icon {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

.btn-sm {
  min-height: var(--control-height-sm);
  padding: 6px 10px;
  font-size: var(--text-1);
}

.field {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.field label,
.field-label {
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: var(--weight-medium);
}

.field-hint {
  color: var(--ink-tertiary);
  font-size: 12px;
  line-height: 1.45;
}

.input,
.textarea,
.select {
  width: 100%;
  min-width: 0;
  min-height: var(--control-height);
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  outline: none;
  color: var(--ink);
  background: var(--surface);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}

.textarea {
  min-height: 104px;
  resize: vertical;
}

/* 下拉框用自绘箭头：原生箭头会顶死在右边缘，没有呼吸感。 */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3a0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 15px 15px;
}

.select::-ms-expand {
  display: none;
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--line-strong);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--signal-strong);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--signal), transparent 78%);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--ink-tertiary);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.segmented button {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}

.segmented button[aria-pressed="true"],
.segmented button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  background: var(--surface-subtle);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-success {
  color: var(--success);
  background: var(--signal-soft);
}

.badge-stage {
  color: var(--warning);
  background: var(--stage-soft);
}

.badge-danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge-info {
  color: var(--info);
  background: var(--info-soft);
}

.empty-state,
.error-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 32px 20px;
  color: var(--ink-secondary);
  text-align: center;
}

.empty-state .icon,
.error-state .icon {
  width: 28px;
  height: 28px;
  color: var(--ink-tertiary);
}

.empty-state strong,
.error-state strong {
  color: var(--ink);
  font-size: 15px;
}

.empty-state p,
.error-state p {
  max-width: 420px;
  margin: 0;
  color: var(--ink-tertiary);
  font-size: 13px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: oklch(100% 0 0 / 0.5);
  animation: skeleton-sweep 1.4s infinite;
}

@keyframes skeleton-sweep {
  to { transform: translateX(100%); }
}

.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

body.has-player > .toast-region {
  bottom: calc(var(--player-height) + 16px);
}

.toast-region-dialog {
  z-index: 10;
}

.toast {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 10px 28px oklch(18% 0.01 85 / 0.14);
  pointer-events: auto;
  animation: toast-in var(--duration-enter) var(--ease);
}

.toast.is-error {
  border-color: color-mix(in oklch, var(--danger), transparent 62%);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 80px oklch(18% 0.01 85 / 0.24);
}

.modal::backdrop {
  background: oklch(10% 0.01 85 / 0.58);
  backdrop-filter: blur(3px);
}

.modal-head,
.modal-body,
.modal-foot {
  padding: 16px 20px;
}

.mobile-sheet {
  display: none;
}

/* Short landscape phones still need the H5 sheet treatment. */
@media (max-width: 820px), (max-width: 1024px) and (max-height: 500px) {
  .mobile-sheet[open] {
    width: 100%;
    max-width: none;
    max-height: min(86dvh, 720px);
    inset: 0;
    display: block;
    margin: auto 0 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 -22px 64px rgb(0 0 0 / 46%);
  }

  .mobile-sheet::backdrop {
    background: rgb(0 0 0 / 68%);
    backdrop-filter: blur(3px);
  }

  .mobile-sheet-card {
    max-height: min(86dvh, 720px);
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    padding-bottom: var(--safe-bottom);
  }

  .mobile-sheet-handle {
    width: 38px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 99px;
    background: var(--line-strong);
  }

  .mobile-sheet-head {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 9px var(--mobile-gutter) 10px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-sheet-head span,
  .mobile-sheet-head h2 {
    display: block;
    margin: 0;
  }

  .mobile-sheet-head span {
    color: var(--signal);
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-sheet-head h2 {
    margin-top: 2px;
    font-size: 18px;
    line-height: 24px;
  }

  .mobile-sheet-nav {
    min-height: 0;
    display: grid;
    align-content: start;
    padding: 8px var(--mobile-gutter) 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .mobile-sheet-label {
    padding: 13px 2px 6px;
    color: var(--ink-tertiary);
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-sheet-nav > a,
  .mobile-sheet-logout {
    width: 100%;
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 10px;
    padding: 8px 2px;
    border: 0;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    background: transparent;
    text-align: left;
    text-decoration: none;
  }

  .mobile-sheet-nav > a > .icon:first-child,
  .mobile-sheet-logout > .icon:first-child {
    width: 34px;
    height: 34px;
    padding: 8px;
    border-radius: var(--radius-md);
    color: var(--signal);
    background: var(--signal-soft);
  }

  .mobile-sheet-nav > a > span,
  .mobile-sheet-nav > a strong,
  .mobile-sheet-nav > a small,
  .mobile-sheet-logout > span,
  .mobile-sheet-logout strong,
  .mobile-sheet-logout small {
    min-width: 0;
    display: block;
  }

  .mobile-sheet-nav strong,
  .mobile-sheet-logout strong {
    font-size: 14px;
  }

  .mobile-sheet-nav small,
  .mobile-sheet-logout small {
    margin-top: 2px;
    overflow: hidden;
    color: var(--ink-tertiary);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-sheet-logout {
    cursor: pointer;
  }

  .mobile-sheet-logout > .icon:first-child,
  .mobile-sheet-logout strong {
    color: var(--danger);
  }
}

@media (max-width: 639px), (max-width: 1024px) and (max-height: 500px) {
  .btn,
  .input,
  .select,
  .segmented button,
  button:not(.btn-icon) {
    min-height: var(--touch-target);
  }

  .btn-sm {
    min-height: 40px;
  }

  .btn-icon {
    width: var(--touch-target);
    min-width: var(--touch-target);
    min-height: var(--touch-target);
  }

  .input,
  .textarea,
  .select,
  input,
  textarea,
  select {
    font-size: 16px;
  }

  .toast-region {
    right: var(--mobile-gutter);
    bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 12px);
    left: var(--mobile-gutter);
  }

  .toast {
    width: 100%;
  }

  .modal:not(.mobile-sheet) {
    width: 100%;
    max-width: none;
    max-height: 88dvh;
    margin: auto 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 16px 16px 0 0;
  }

  .modal:not(.mobile-sheet) > form,
  .modal:not(.mobile-sheet) > .download-dialog {
    max-height: 88dvh;
  }

  .modal-head,
  .modal-body,
  .modal-foot {
    padding-right: var(--mobile-gutter);
    padding-left: var(--mobile-gutter);
  }

  .modal-foot {
    padding-bottom: calc(12px + var(--safe-bottom));
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--line);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
