:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3fb;
  --text: #182033;
  --muted: #69738a;
  --line: #dfe5ef;
  --blue: #2f5dff;
  --blue-dark: #2048db;
  --blue-soft: #e9efff;
  --red: #dc3f53;
  --red-soft: #fff0f2;
  --shadow: 0 12px 32px rgba(44, 62, 105, 0.09);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 7% 0%, rgba(47, 93, 255, 0.08), transparent 28rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 93, 255, 0.28);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) clamp(18px, 4vw, 48px) max(104px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
}

.topbar-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.title-group {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  overflow: hidden;
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.icon-button,
.soft-button,
.primary-button,
.danger-button {
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.icon-button:hover,
.soft-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.icon-button {
  display: inline-flex;
  width: 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(44, 62, 105, 0.08);
}

.soft-button,
.primary-button,
.danger-button {
  padding: 0 16px;
}

.soft-button {
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(44, 62, 105, 0.08);
}

.soft-button.is-active {
  color: var(--blue);
  background: var(--blue-soft);
}

.primary-button {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 20px rgba(47, 93, 255, 0.24);
}

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

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

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 16px;
}

.user-card {
  position: relative;
  display: flex;
  min-height: 196px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 14px 18px;
  overflow: hidden;
  border: 1px solid rgba(223, 229, 239, 0.82);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 22px rgba(44, 62, 105, 0.055);
  cursor: pointer;
  text-align: center;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.user-card::after {
  position: absolute;
  inset: auto -28px -48px auto;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--avatar-gradient);
  content: "";
  opacity: 0.07;
}

.user-card:hover {
  border-color: rgba(47, 93, 255, 0.3);
  box-shadow: var(--shadow);
  transform: translateY(-3px);
}

.user-card.is-selected {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px rgba(47, 93, 255, 0.11);
}

.avatar {
  display: grid;
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
  place-items: center;
  border: 4px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  color: #fff;
  background: var(--avatar-gradient);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--avatar-color) 24%, transparent);
  font-size: 1.5rem;
  font-weight: 850;
}

.user-name {
  width: 100%;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-count {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
}

.mark-dot {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 2px 5px rgba(220, 63, 83, 0.38);
}

.selection-indicator {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid #b4bfd1;
  border-radius: 8px;
  color: transparent;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 900;
}

.user-card.is-selected .selection-indicator {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.floating-actions {
  position: fixed;
  z-index: 20;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.fab-secondary,
.fab-primary {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(37, 53, 91, 0.2);
}

.fab-secondary {
  background: #fff;
}

.fab-secondary.is-active {
  color: var(--red);
  background: var(--red-soft);
}

.fab-primary {
  color: #fff;
  background: var(--blue);
}

.mark-confirm-bar {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 15px 40px rgba(37, 53, 91, 0.18);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
}

.mark-confirm-bar span {
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.work-groups {
  display: grid;
  gap: 28px;
}

.category-section {
  min-width: 0;
}

.category-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.category-heading::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.category-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.work-list {
  display: grid;
  gap: 10px;
}

.work-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  width: 100%;
  min-height: 88px;
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(44, 62, 105, 0.04);
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, transform 150ms ease, background 150ms ease;
}

.work-row:hover {
  border-color: rgba(47, 93, 255, 0.36);
  transform: translateY(-1px);
}

.work-row.is-selected {
  border-color: var(--blue);
  background: var(--blue-soft);
}

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

.work-title-line {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.work-title {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marked-x {
  flex: 0 0 auto;
  color: var(--red);
  font-size: 1.08rem;
  font-weight: 950;
}

.work-checkbox {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid #b4bfd1;
  border-radius: 7px;
  color: transparent;
  background: #fff;
  font-size: 0.8rem;
  font-weight: 900;
}

.work-row.is-selected .work-checkbox {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.tag {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  color: #4c5f84;
  background: var(--surface-soft);
  font-size: 0.75rem;
  font-weight: 650;
}

.work-meta {
  display: grid;
  justify-items: end;
  gap: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.reader-shell {
  width: min(860px, 100%);
  margin: 0 auto;
}

.reader-header {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.novel-text {
  padding: clamp(30px, 6vw, 60px) clamp(2px, 4vw, 34px) 80px;
  font-family: ui-serif, Georgia, "Noto Serif SC", "Songti SC", serif;
  font-size: 1.08rem;
  line-height: 2;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.reader-large .novel-text {
  font-size: clamp(1.28rem, 4.8vw, 1.52rem);
  line-height: 2.05;
}

.reader-large .reader-shell {
  width: min(920px, 100%);
}

.empty-state,
.error-state,
.loading-screen {
  display: grid;
  min-height: 54vh;
  place-content: center;
  justify-items: center;
  padding: 48px 20px;
  color: var(--muted);
  text-align: center;
}

.loading-screen {
  min-height: 100vh;
}

.empty-state h2,
.error-state h2 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 1.25rem;
}

.empty-state p,
.error-state p {
  max-width: 440px;
  margin-bottom: 20px;
  line-height: 1.7;
}

.loading-mark {
  width: 36px;
  height: 36px;
  margin-bottom: 14px;
  border: 4px solid #dbe3f4;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 16px;
}

.skeleton-card {
  min-height: 196px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, #e9eef6 35%, #f8faff 50%, #e9eef6 65%);
  background-size: 300% 100%;
  animation: shimmer 1.35s ease infinite;
}

.toast-region {
  position: fixed;
  z-index: 100;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  width: min(92vw, 460px);
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  margin-bottom: 9px;
  padding: 13px 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 13px;
  color: #fff;
  background: #252d40;
  box-shadow: 0 12px 30px rgba(24, 32, 51, 0.24);
  font-size: 0.9rem;
  font-weight: 650;
  text-align: center;
  animation: toast-in 180ms ease-out;
}

.toast.is-error {
  background: #a52c3c;
}

.hidden {
  display: none !important;
}

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

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

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

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .topbar-actions .soft-button {
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  .user-grid,
  .skeleton-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
  }

  .user-card {
    min-height: 176px;
    padding-inline: 10px;
  }

  .avatar {
    width: 64px;
    height: 64px;
  }

  .work-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .work-meta {
    display: flex;
    justify-content: space-between;
  }

  .work-meta .category-name {
    display: none;
  }

  .floating-actions {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    justify-content: flex-end;
  }

  .fab-secondary,
  .fab-primary {
    padding-inline: 15px;
    font-size: 0.88rem;
  }

  .mark-confirm-bar {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    justify-content: flex-end;
    transform: none;
  }

  .mark-confirm-bar span {
    margin-right: auto;
  }

  .novel-text {
    font-size: 1.04rem;
    line-height: 1.95;
  }
}

@media (max-width: 420px) {
  .topbar {
    gap: 10px;
  }

  .subtitle {
    font-size: 0.84rem;
  }

  .topbar-actions {
    gap: 7px;
  }

  .category-heading {
    font-size: 1rem;
  }
}

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