:root {
  --bg: #fbfaf7;
  --fg: #1f2328;
  --muted: #5d6670;
  --line: #d3d0c8;
  --panel: #f1efe9;
  --accent: #1f5fae;
  --accent-fg: #ffffff;
  --hl: #fff1b8;
  --err: #b42318;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --fg: #e3e5e8;
    --muted: #9aa3ad;
    --line: #3a4048;
    --panel: #1e2328;
    --accent: #6ea8f0;
    --accent-fg: #0c1218;
    --hl: #4a4220;
    --err: #ff8a80;
  }
}

html {
  font-size: clamp(16px, 12px + 1.2vw, 24px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
}

main {
  max-width: 50rem;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

h1 {
  font-size: 1.5rem;
  margin: 0.5rem 0 1rem;
}

[hidden] {
  display: none !important;
}

button,
select,
input {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  min-height: 2.75rem;
  box-sizing: border-box;
}

button {
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 24rem;
}

.msg {
  margin: 0.5rem 0 0;
  color: var(--muted);
  min-height: 1.6em;
  overflow-wrap: anywhere;
}

.msg.error {
  color: var(--err);
}

.shelf {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.shelf button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
}

.shelf .name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.shelf .meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
}

.shelf progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  margin: 0.4rem 0;
  accent-color: var(--accent);
}

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

.titles {
  min-width: 0;
}

.series {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.chapter {
  margin: 0;
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.paras {
  position: relative;
  height: 45vh;
  min-height: 8rem;
  overflow-y: auto;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--panel);
}

.paras p {
  margin: 0 0 0.6rem;
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.paras p.cur {
  background: var(--hl);
}

.paras .empty {
  color: var(--muted);
  cursor: default;
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin: 0.75rem 0;
}

.controls button {
  padding: 0.5rem 0.2rem;
  min-height: 3rem;
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.buf {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

dialog {
  width: min(32rem, calc(100% - 2rem));
  box-sizing: border-box;
  padding: 0;
  color: var(--fg);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 0.75rem;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog form {
  padding: 1rem 1.25rem 1.25rem;
}

dialog h2 {
  font-size: 1.2rem;
  margin: 0 0 0.75rem;
}

dialog .close {
  display: block;
  width: 100%;
  margin-top: 1rem;
}

.settings {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
}

.settings select {
  width: 100%;
  color: var(--fg);
  font-size: 1rem;
}

@media (max-width: 40rem) {
  main {
    padding: 0.5rem 0.6rem 1.5rem;
  }

  .controls button {
    font-size: 0.85rem;
  }

  .settings {
    grid-template-columns: 1fr;
  }

  dialog form {
    padding: 0.75rem 0.9rem 1rem;
  }
}

@media (max-height: 30rem) and (orientation: landscape) {
  html {
    font-size: 14px;
  }

  .paras {
    height: 30vh;
  }
}
