:root {
  color-scheme: dark;
  --ink: #1d1826;
  --ink-deep: #110e17;
  --shadow: #09070d;
  --surface: #272033;
  --surface-raised: #332a42;
  --border: #4e4063;
  --border-light: #8a96a9;
  --border-warm: #97623d;
  --leather-dark: #4d2c22;
  --parchment: #fff7e1;
  --silver: #afb9c6;
  --muted: #8a96a9;
  --gold: #f4b848;
  --gold-bright: #ffdb2e;
  --gold-soft: #fff38d;
  --rose: #f897a8;
  --rose-deep: #ba5a7a;
  --success: #5cd69a;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-body: 'VT323', ui-monospace, 'Courier New', monospace;
}

* {
  box-sizing: border-box;
  border-radius: 0;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 20px;
  letter-spacing: 0.02em;
  background-color: var(--ink);
  background-image:
    linear-gradient(90deg, rgba(255, 247, 225, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(255, 247, 225, 0.03) 1px, transparent 1px);
  background-size: 16px 16px;
  color: var(--parchment);
  line-height: 1.35;
}

.layout {
  max-width: 1220px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1.5rem;
  align-items: start;
}

.main-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.shelf-sidebar {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 4px solid var(--border);
  outline: 2px solid var(--shadow);
  padding: 1.2rem;
  box-shadow:
    inset 0 0 0 3px var(--ink-deep),
    6px 6px 0 var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem;
  align-items: center;
  padding: 1.4rem;
  background: var(--surface);
  border: 4px solid var(--border-warm);
  outline: 2px solid var(--shadow);
  box-shadow:
    inset 0 0 0 3px var(--ink-deep),
    6px 6px 0 var(--shadow);
}

.mascot-frame {
  width: 132px;
  height: 132px;
  padding: 0;
  border: 4px solid var(--gold);
  background: var(--ink-deep);
  background-image:
    linear-gradient(45deg, #181322 25%, transparent 25%),
    linear-gradient(-45deg, #181322 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #181322 75%),
    linear-gradient(-45deg, transparent 75%, #181322 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--shadow);
}

.mascot-frame:hover {
  border-color: var(--gold-bright);
  background-color: #1a1426;
}

.mascot-frame:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--shadow);
}

#scabbers-canvas {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#scabbers-mini {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--ink-deep);
  border: 3px solid var(--gold);
  padding: 4px;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.pill {
  font-family: var(--font-pixel);
  font-size: 0.62rem;
  padding: 0.25rem 0.55rem;
  background: var(--ink-deep);
  border: 2px solid var(--gold);
  color: var(--gold-bright);
}

h1 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 1.35rem;
  line-height: 1.3;
  color: var(--parchment);
  text-shadow: 3px 3px 0 var(--shadow);
}

h2 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 0.78rem;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--gold-bright);
  text-shadow: 2px 2px 0 var(--shadow);
}

.speech-bubble {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--ink-deep);
  border: 3px solid var(--parchment);
  box-shadow:
    inset 0 0 0 2px var(--border),
    4px 4px 0 var(--shadow);
  color: var(--parchment);
  font-size: 1.15rem;
}

.speech-cursor {
  font-size: 0.85rem;
  color: var(--gold-bright);
  animation: pixel-blink 0.8s steps(2, start) infinite;
}

@keyframes pixel-blink {
  to {
    visibility: hidden;
  }
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.token-dot {
  width: 10px;
  height: 10px;
  background: var(--rose-deep);
  border: 2px solid var(--shadow);
  margin-right: 0.5rem;
}

.token-dot.is-set {
  background: var(--success);
}

.card {
  background: var(--surface);
  border: 4px solid var(--border);
  outline: 2px solid var(--shadow);
  padding: 1.3rem;
  box-shadow:
    inset 0 0 0 3px var(--ink-deep),
    6px 6px 0 var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 3px solid var(--border);
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  border: 3px dashed var(--gold);
  background: var(--ink-deep);
  text-align: center;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--gold-bright);
  background: var(--surface-raised);
}

.dropzone input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-title {
  font-family: var(--font-pixel);
  font-size: 0.66rem;
  line-height: 1.7;
  color: var(--parchment);
}

.cover-picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.cover-dropzone {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border: 3px dashed var(--border-light);
  background: var(--ink-deep);
  cursor: pointer;
}

.cover-dropzone:hover {
  border-color: var(--gold);
  background: var(--surface-raised);
}

.cover-dropzone input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.cover-preview {
  width: 40px;
  height: 54px;
  object-fit: cover;
  border: 2px solid var(--gold);
  background: var(--shadow);
  flex-shrink: 0;
}

.cover-label {
  font-family: var(--font-pixel);
  font-size: 0.56rem;
  line-height: 1.6;
  color: var(--silver);
}

.status {
  margin: 0.7rem 0 0;
  font-size: 1.15rem;
  min-height: 1.4rem;
  color: var(--silver);
}

.status.is-error {
  color: var(--rose);
}

.status.is-success {
  color: var(--success);
}

.books-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.book-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  padding: 0.7rem;
  background: var(--ink-deep);
  border: 3px solid var(--border);
  box-shadow: 3px 3px 0 var(--shadow);
}

.book-item:hover {
  border-color: var(--gold);
}

.book-cover {
  width: 56px;
  height: 76px;
  object-fit: cover;
  border: 2px solid var(--border-warm);
  background: var(--surface);
  display: block;
}

.book-cover-empty {
  display: grid;
  place-items: center;
  font-family: var(--font-pixel);
  font-size: 0.52rem;
  color: var(--muted);
  border-style: dashed;
}

.book-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.book-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.book-badge {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  padding: 0.18rem 0.38rem;
  background: var(--gold);
  border: 2px solid var(--shadow);
  color: var(--ink-deep);
}

.book-name {
  font-size: 1.15rem;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-meta {
  font-size: 0.95rem;
  color: var(--muted);
}

.book-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.2rem;
}

.empty-state {
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0.5rem 0.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.95rem;
  border: 3px solid var(--shadow);
  font-family: var(--font-pixel);
  font-size: 0.62rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 4px 4px 0 var(--shadow);
}

.btn-sm {
  padding: 0.38rem 0.55rem;
  font-size: 0.5rem;
  border-width: 2px;
  box-shadow: 2px 2px 0 var(--shadow);
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gold);
  border-color: var(--gold-soft);
  color: var(--ink-deep);
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-bright);
}

.btn-token {
  background: var(--surface-raised);
  border-color: var(--border-warm);
  color: var(--parchment);
}

.btn-token:hover {
  border-color: var(--gold);
}

.btn-secondary,
.btn-ghost {
  background: var(--surface-raised);
  border-color: var(--border-light);
  color: var(--parchment);
}

.btn-secondary:hover,
.btn-ghost:hover {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

.btn-danger {
  background: var(--leather-dark);
  border-color: var(--rose);
  color: var(--rose);
}

.btn-danger:hover:not(:disabled) {
  background: var(--rose-deep);
  color: var(--parchment);
}

.modal {
  padding: 0;
  border: 4px solid var(--gold);
  outline: 3px solid var(--shadow);
  background: var(--surface);
  color: var(--parchment);
  width: min(480px, calc(100vw - 2rem));
  box-shadow:
    inset 0 0 0 3px var(--ink-deep),
    8px 8px 0 var(--shadow);
}

.modal::backdrop {
  background: rgba(9, 7, 13, 0.85);
}

.modal-content {
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.modal-desc {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  color: var(--silver);
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

label {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--gold-soft);
}

input[type='password'] {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 3px solid var(--border-light);
  background: var(--ink-deep);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 1.2rem;
}

input[type='password']:focus {
  outline: none;
  border-color: var(--gold-bright);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.modal-actions-right {
  display: flex;
  gap: 0.6rem;
}

code {
  color: var(--gold-bright);
}

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

  .shelf-sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 600px) {
  .hero {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .hero-actions {
    justify-content: center;
  }

  .speech-bubble {
    text-align: left;
  }
}
