:root {
  --bg: #f2f5fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #65718a;
  --line: #dfe5f0;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #e8efff;
  --danger: #c02626;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: #0f172a;
  color: #ffffff;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ghost-link {
  color: #dbe4f7;
  text-decoration: none;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
}

.ghost-link:hover {
  background: rgba(255, 255, 255, 0.12);
}

.page {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 18px 16px 48px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

.search-panel {
  margin-bottom: 16px;
}

.search-field {
  display: block;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px 14px;
}

.search-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

#search-input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  min-height: 40px;
}

#search-input::placeholder {
  color: #9aa5ba;
}

.source-status {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff4e6;
  color: #8a4b04;
  font-size: 15px;
}

.results {
  display: grid;
  gap: 12px;
}

.course {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.course-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  width: 100%;
  min-height: 64px;
  padding: 16px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--ink);
}

.course-head:hover {
  background: #f8faff;
}

.course-name {
  font-size: 18px;
  font-weight: 600;
}

.course-meta {
  color: var(--muted);
  font-size: 14px;
}

.course-body {
  border-top: 1px solid var(--line);
  padding: 12px 14px 16px;
  background: #fbfcff;
}

.segment {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 6px;
  border-radius: 12px;
}

.segment:hover {
  background: var(--accent-soft);
}

.segment input[type="checkbox"],
.check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.segment-main {
  min-width: 0;
}

.segment-name {
  display: block;
  font-size: 16px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.segment-sub {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.segment-size {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.segment-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.segment-foot .check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  min-height: 44px;
}

.segment-hint {
  flex: 1;
  min-width: 120px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.primary,
.secondary {
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 12px;
  border: 0;
  font-size: 16px;
  font-weight: 600;
}

.primary {
  background: var(--accent);
  color: #ffffff;
}

.primary:hover {
  background: var(--accent-dark);
}

.primary:disabled {
  background: #c4cfe4;
  cursor: default;
}

.secondary {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.empty-hint {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.downloads {
  margin-top: 28px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.downloads-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  margin-bottom: 6px;
}

.downloads-head h2 {
  font-size: 18px;
}

.connection-mode {
  font-size: 14px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.download-summary {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 14px;
}

.download-list {
  display: grid;
  gap: 12px;
}

.download-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.download-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  margin-bottom: 8px;
}

.download-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.download-size {
  color: var(--muted);
  white-space: nowrap;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: #e9eef8;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s linear;
}

.downloads .secondary {
  margin-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 20px;
  border-radius: 12px;
  background: #1b2438;
  color: #ffffff;
  font-size: 15px;
  box-shadow: var(--shadow);
  z-index: 30;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #eef3ff 0%, #f7f9ff 55%, #e8f0ff 100%);
}

.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 6px;
}

.login-hint {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 18px;
}

.notice {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  margin-bottom: 16px;
}

.notice-error {
  background: #fdecec;
  color: var(--danger);
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcff;
  color: var(--ink);
  font-size: 17px;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 8px;
  font-size: 15px;
}

.login-card .primary {
  width: 100%;
  margin-top: 8px;
}

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

@media (min-width: 720px) {
  .page {
    padding-left: 24px;
    padding-right: 24px;
  }

  .downloads {
    padding: 22px 24px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .topbar {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .page {
    padding-top: 12px;
  }

  .login-page {
    align-items: flex-start;
    padding-top: 16px;
  }
}
