:root {
  color-scheme: light;
  --paper: #fff7ed;
  --panel: #fff7ed;
  --stone-900: #1c1917;
  --stone-800: #292524;
  --stone-700: #44403c;
  --stone-600: #57534e;
  --stone-500: #78716c;
  --stone-400: #a8a29e;
  --stone-300: #d6d3d1;
  --stone-200: #e7e5e4;
  --stone-100: #f5f5f4;
  --red-800: #991b1b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--stone-800);
  font: 16px/1.45 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: Merriweather, Georgia, serif;
  color: var(--stone-900);
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 2px solid var(--stone-800);
  border-radius: 2px;
  background: transparent;
  color: var(--stone-800);
  cursor: pointer;
  font-family: Merriweather, Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0 16px;
  text-transform: uppercase;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

button:hover,
button:focus-visible {
  background: var(--stone-800);
  color: var(--paper);
}

button.secondary {
  border-color: var(--stone-400);
  color: var(--stone-700);
}

button.secondary:hover,
button.secondary:focus-visible {
  border-color: var(--stone-800);
  background: var(--stone-800);
  color: var(--paper);
}

button.danger {
  border-color: var(--red-800);
  color: var(--red-800);
}

button.danger:hover,
button.danger:focus-visible {
  background: var(--red-800);
  color: var(--paper);
}

input,
textarea {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--stone-400);
  border-radius: 0;
  background: transparent;
  color: var(--stone-800);
  padding: 9px 0;
  transition: border-color 0.2s, background-color 0.2s;
}

textarea {
  border: 2px solid var(--stone-300);
  padding: 10px 12px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--stone-800);
  outline: none;
}

label {
  display: grid;
  gap: 5px;
  color: var(--stone-500);
  font-size: 0.9rem;
  font-weight: 700;
}

.app {
  min-height: 100vh;
}

.login-panel {
  width: min(440px, calc(100vw - 32px));
  margin: 12vh auto 0;
  padding: 28px;
  background: var(--panel);
  border: 2px solid var(--stone-800);
  box-shadow: 8px 8px 0 var(--stone-300);
}

.login-panel h1 {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  line-height: 1.05;
  margin-bottom: 22px;
}

.stack {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 18px;
  border-bottom: 2px solid var(--stone-300);
}

.topbar h1 {
  font-size: clamp(2.6rem, 6vw, 4.5rem);
  line-height: 1;
  margin-bottom: 6px;
}

.topbar p {
  color: var(--stone-600);
  font-size: 1.05rem;
  margin-bottom: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px;
  border-bottom: 2px solid var(--stone-300);
}

.search {
  color: var(--stone-800);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 22px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 24px 40px;
}

.results,
.editor,
.scanner {
  background: var(--panel);
  border: 2px solid var(--stone-800);
}

.book-list {
  display: grid;
  max-height: calc(100vh - 205px);
  overflow: auto;
}

.book-item {
  border: 0;
  border-bottom: 1px solid var(--stone-300);
  border-radius: 0;
  background: transparent;
  color: var(--stone-800);
  font-family: Inter, system-ui, sans-serif;
  letter-spacing: 0;
  min-height: 0;
  padding: 14px 16px;
  text-align: left;
  text-transform: none;
}

.book-item:hover,
.book-item:focus-visible,
.book-item.active {
  background: var(--stone-200);
  color: var(--stone-900);
}

.book-item.active .book-title {
  text-decoration: underline;
  text-decoration-color: var(--red-800);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.book-title {
  display: block;
  font-weight: 700;
}

.book-meta {
  display: block;
  color: var(--stone-600);
  font-size: 0.9rem;
}

.editor {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.editor-head,
.form-actions,
.scanner-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-head h2 {
  font-size: 1.6rem;
  margin-bottom: 0;
}

.grid,
.isbn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.isbn-row {
  grid-template-columns: 1fr auto;
  align-items: end;
  background: var(--stone-100);
  border: 1px solid var(--stone-300);
  padding: 14px;
}

.message {
  min-height: 1.45em;
  color: var(--stone-600);
  font-weight: 500;
}

.scanner {
  max-width: 1240px;
  margin: 18px auto 0;
  overflow: hidden;
}

.scanner video {
  width: 100%;
  max-height: 360px;
  background: var(--stone-900);
  object-fit: cover;
}

.scanner-actions {
  padding: 12px;
}

@media (max-width: 760px) {
  .topbar,
  .toolbar,
  .workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    display: grid;
  }

  .toolbar,
  .workspace,
  .grid {
    grid-template-columns: 1fr;
  }

  .isbn-row {
    grid-template-columns: 1fr;
  }

  .book-list {
    max-height: 38vh;
  }

  .scanner {
    margin-left: 14px;
    margin-right: 14px;
  }

  .form-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }
}
