:root {
  color-scheme: light dark;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #17212b;
  --muted: #66727f;
  --line: #d9e0e6;
  --accent: #176c7a;
  --accent-strong: #11515c;
  --accent-soft: #dff0f2;
  --gold: #b46d16;
  --danger: #b42318;
  --ok: #16804f;
  --warn: #9a6700;
  --shadow: 0 18px 50px rgb(21 32 43 / 10%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161b;
    --surface: #182129;
    --surface-2: #202b34;
    --text: #edf3f6;
    --muted: #a3b0ba;
    --line: #33424c;
    --accent: #7fc3cb;
    --accent-strong: #a7dbe0;
    --accent-soft: #19343a;
    --gold: #d59642;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-soft), transparent 30%) 0, transparent 320px),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1040px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  letter-spacing: 0;
}

.topbar p,
.section-title span,
.helper-note,
.meta,
.job-line {
  color: var(--muted);
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: color-mix(in srgb, var(--surface), transparent 10%);
  color: var(--muted);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgb(21 32 43 / 6%);
}

.status-pill.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok), var(--line) 72%);
}

.status-pill.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn), var(--line) 70%);
}

.panel {
  background: color-mix(in srgb, var(--surface), transparent 2%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.connect-panel {
  display: grid;
  gap: 14px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--surface), var(--accent-soft) 42%), var(--surface));
}

.connect-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.login-grid {
  display: none;
}

.login-finish {
  margin-top: 4px;
}

.grid-two,
.file-grid,
.stack {
  display: grid;
  gap: 14px;
}

.grid-two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 24px;
}

.file-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 650;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 11px;
}

textarea {
  min-height: 86px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 720;
  box-shadow: 0 10px 18px rgb(23 108 122 / 16%);
}

button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  box-shadow: none;
}

.library {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.queue {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.library-actions {
  margin-top: 0;
}

.helper-note {
  margin-top: 6px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  border: 1px dashed color-mix(in srgb, var(--line), transparent 8%);
  border-radius: 8px;
  background: var(--surface-2);
}

.book,
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.book {
  min-height: 104px;
}

.book-main {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.cover {
  width: 66px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--gold), transparent 72%));
  color: var(--accent-strong);
  font-weight: 800;
  border: 1px solid color-mix(in srgb, var(--line), transparent 18%);
}

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

.book-copy {
  min-width: 0;
}

.book-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.download-primary {
  min-width: 112px;
}

.book h3,
.item h3 {
  margin: 0 0 4px;
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.book-progress {
  margin-top: 12px;
}

.book-progress.idle {
  opacity: 0.7;
}

.job-line {
  margin-top: 6px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.progress {
  height: 7px;
  background: color-mix(in srgb, var(--line), transparent 30%);
  border-radius: 999px;
  overflow: hidden;
}

.wasm-progress {
  margin: 14px 0 12px;
}

.bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--ok));
  transition: width 140ms linear;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.done {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok), var(--line) 60%);
}

.badge.todo {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn), var(--line) 60%);
}

.inspect {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.inspect dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 4px 10px;
  margin: 0 0 10px;
}

.inspect dt {
  color: var(--muted);
}

.inspect dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.item .meta {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.state {
  font-weight: 700;
}

.state.done {
  color: var(--ok);
}

.state.error {
  color: var(--danger);
}

.state.running {
  color: var(--accent);
}

.log {
  margin: 0;
  min-height: 130px;
  max-height: 280px;
  overflow: auto;
  background: color-mix(in srgb, var(--surface), #000 7%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.log.compact {
  min-height: 90px;
}

.dev-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

.dev-grid,
.dev-section {
  margin-top: 16px;
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 24px, 1040px);
    padding-top: 18px;
  }

  .topbar,
  .section-title,
  .connect-row {
    align-items: flex-start;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .grid-two,
  .file-grid,
  .item,
  .book {
    grid-template-columns: 1fr;
  }

  .book-main {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .cover {
    width: 58px;
  }

  .book-actions {
    justify-content: flex-start;
  }

  .download-primary,
  #startLoginButton {
    width: 100%;
  }
}
