:root {
  --paper: #e6e9ed;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-soft: #545b66;
  --tone: #a3aab4;
  --spot: #c8102e;
  --spot-ink: #ffffff;
  --ok: #1f7a4d;
  --panel: #16181d;
  --panel-ink: #f3f4f6;
  --radius-field: 4px;
  --font: 'Zen Kaku Gothic New', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #121418;
    --surface: #1b1e24;
    --ink: #eceef1;
    --ink-soft: #a1a8b3;
    --tone: #3b414b;
    --spot: #ff4a5f;
    --spot-ink: #16181d;
    --ok: #4cc38a;
    --panel: #050608;
    --panel-ink: #eceef1;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --paper: #121418;
  --surface: #1b1e24;
  --ink: #eceef1;
  --ink-soft: #a1a8b3;
  --tone: #3b414b;
  --spot: #ff4a5f;
  --spot-ink: #16181d;
  --ok: #4cc38a;
  --panel: #050608;
  --panel-ink: #eceef1;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Auth layout: a manga panel beside the form ---------- */

.auth {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  min-height: 100vh;
}

.panel {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  color: var(--panel-ink);
  padding: clamp(2rem, 5vw, 4rem);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  /* Diagonal gutter, like the cut between two manga panels. */
  clip-path: polygon(0 0, 100% 0, 88% 100%, 0 100%);
}

/* Screentone: halftone dots that fade out toward the bottom-left. */
.panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(
    circle,
    var(--panel-ink) 1.3px,
    transparent 1.6px
  );
  background-size: 9px 9px;
  opacity: 0.22;
  mask-image: radial-gradient(
    ellipse at 85% 10%,
    #000 0%,
    rgb(0 0 0 / 0.5) 35%,
    transparent 70%
  );
}

.panel > * {
  position: relative;
}

.panel-title {
  font-size: clamp(2.75rem, 6.5vw, 5.5rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
  max-width: 9ch;
}

.panel-title .arrow {
  display: block;
  color: var(--spot);
}

.panel-text {
  max-width: 34ch;
  margin: 0;
  color: color-mix(in srgb, var(--panel-ink) 72%, transparent);
  font-size: 1.05rem;
}

.form-side {
  display: flex;
  align-items: center;
  padding: clamp(2rem, 6vw, 5rem) clamp(1rem, 6vw, 5rem);
}

.form-wrap {
  width: 100%;
  max-width: 24rem;
}

.form-wrap h1 {
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

.form-wrap .lead {
  color: var(--ink-soft);
  margin: 0 0 2rem;
}

/* ---------- Form controls ---------- */

.field {
  display: block;
  margin-bottom: 1.25rem;
}

.field span {
  display: block;
  font-weight: 700;
  font-size: 0.925rem;
  margin-bottom: 0.375rem;
}

.field small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.8125rem;
  margin-top: 0.375rem;
}

input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--tone);
  border-radius: var(--radius-field);
  padding: 0.7rem 0.85rem;
  transition: border-color 120ms ease;
}

input:hover {
  border-color: var(--ink-soft);
}

input:focus-visible {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--spot) 35%, transparent);
}

input[aria-invalid='true'] {
  border-color: var(--spot);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: inherit;
  font-weight: 700;
  border: 2px solid var(--ink);
  border-radius: var(--radius-field);
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  background: var(--ink);
  color: var(--paper);
  /* Hard offset shadow, like an inked panel border. */
  box-shadow: 4px 4px 0 var(--spot);
  transition:
    transform 80ms ease,
    box-shadow 80ms ease;
}

.btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--spot);
}

.btn:focus-visible {
  outline: 3px solid var(--spot);
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.btn-quiet {
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  padding: 0.45rem 0.9rem;
}

.form-error {
  min-height: 1.5rem;
  margin: 0 0 0.75rem;
  color: var(--spot);
  font-weight: 700;
  font-size: 0.925rem;
}

/* ---------- App shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  background: var(--panel);
  color: var(--panel-ink);
}

.brand {
  font-weight: 900;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.brand span {
  color: var(--spot);
}

.topbar .btn-quiet {
  color: var(--panel-ink);
  border-color: color-mix(in srgb, var(--panel-ink) 40%, transparent);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.925rem;
}

.content {
  max-width: 64rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2.5rem);
}

.content h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 900;
  line-height: 1.15;
  margin: 0 0 0.5rem;
}

.content .lead {
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 0 2.5rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.status::before {
  content: '';
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--tone);
}

.status[data-state='online']::before {
  background: var(--ok);
}

.status[data-state='offline']::before {
  background: var(--spot);
}

.empty {
  border: 2px dashed var(--tone);
  border-radius: 6px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  background: var(--surface);
}

.empty h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.empty p {
  margin: 0;
  color: var(--ink-soft);
  max-width: 60ch;
}

.log {
  margin-top: 2.5rem;
}

.log h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.log ol {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 3px solid var(--ink);
}

.log li {
  padding: 0.375rem 0 0.375rem 1rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.log time {
  color: var(--ink);
  font-weight: 700;
  margin-right: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Mangas ---------- */

.add-form {
  margin-bottom: 2rem;
}

.add-form .field {
  margin-bottom: 0;
}

.add-row {
  display: flex;
  gap: 0.75rem;
}

.add-row input {
  flex: 1;
  min-width: 0;
}

.add-row .btn {
  flex: none;
}

.mangas {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.25rem;
}

.manga {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: 1.25rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--tone);
}

.manga-cover {
  width: 100%;
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border: 2px solid var(--ink);
  border-radius: var(--radius-field);
  background: var(--paper);
}

.manga-cover-empty {
  background-image: radial-gradient(
    circle,
    var(--tone) 1.3px,
    transparent 1.6px
  );
  background-size: 8px 8px;
}

.manga-body h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.manga-meta,
.manga-summary {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.manga progress {
  display: block;
  width: 100%;
  height: 0.6rem;
  margin-top: 0.75rem;
  accent-color: var(--spot);
}

.manga-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.chapters-loading {
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.chapters {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  max-height: 28rem;
  overflow-y: auto;
  border-top: 2px solid var(--ink);
}

.chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--tone);
  font-size: 0.9rem;
}

.chapter-info {
  overflow-wrap: anywhere;
}

.chapter-info small {
  display: block;
  color: var(--ink-soft);
}

.chapter-status {
  font-weight: 700;
  font-size: 0.8125rem;
  white-space: nowrap;
  color: var(--ink-soft);
}

.chapter[data-status='done'] .chapter-status {
  color: var(--ok);
}

.chapter[data-status='downloading'] .chapter-status {
  color: var(--ink);
}

.chapter[data-status='failed'] .chapter-status {
  color: var(--spot);
  cursor: help;
}

.chapter .btn-quiet {
  padding: 0.25rem 0.6rem;
  font-size: 0.8125rem;
}

/* ---------- Phone ---------- */

@media (max-width: 760px) {
  .auth {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: 15rem;
    clip-path: polygon(0 0, 100% 0, 100% 82%, 0 100%);
    padding-bottom: 3rem;
  }

  .panel-title {
    max-width: none;
  }

  .form-side {
    align-items: flex-start;
    padding: 2rem 1rem 3rem;
  }

  .topbar-user .who {
    display: none;
  }

  .add-row {
    flex-direction: column;
  }

  .manga {
    grid-template-columns: 4.5rem minmax(0, 1fr);
    gap: 0.875rem;
    padding: 1rem;
  }

  .chapter {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .chapter .btn-quiet {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
