:root {
  color-scheme: light;
  --bg: radial-gradient(circle at 10% 0%, #fef3d4 0%, #fff9ee 40%, #edf5ff 100%);
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #5d7285;
  --primary: #0f7b6c;
  --primary-soft: #ecf9f6;
  --border: #dfe7f1;
  --accent: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

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

.topbar h1,
.auth-card h1 {
  font-family: "Iowan Old Style", "Georgia", serif;
  letter-spacing: 0.02em;
}

.topbar h1 {
  margin: 0.67em 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 10px 28px rgba(15, 42, 56, 0.08);
}

form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.inline-control,
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

.inline-field {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #f9fbff;
}

.score-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  color: var(--text);
  font-size: 0.95rem;
}

.range-slider {
  position: relative;
  flex: 1 1 220px;
  max-width: 420px;
  height: 24px;
}

.range-track,
.range-fill {
  position: absolute;
  top: 10px;
  height: 4px;
  border-radius: 2px;
}

.range-track {
  left: 0;
  right: 0;
  background: var(--border);
}

.range-fill {
  background: var(--primary);
}

/* Two overlaid inputs share one track; only the thumbs take pointer events. */
.range-slider input[type="range"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 24px;
  margin: 0;
  padding: 0;
  min-width: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-slider input[type="range"]::-webkit-slider-runnable-track {
  background: none;
}

.range-slider input[type="range"]::-moz-range-track {
  background: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
  cursor: pointer;
}

.range-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
  cursor: pointer;
}

#score-range-value {
  min-width: 6em;
  font-variant-numeric: tabular-nums;
}

.inline-field select,
.inline-field input {
  min-width: 120px;
}

input[type="file"],
input[type="number"] {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f9fbff;
}

button {
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(15, 123, 108, 0.28);
}

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

.hidden {
  display: none;
}

.book-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.book-item {
  position: relative;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  background: #fafcff;
}

.book-item:hover,
.book-item:focus-within {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.book-open {
  display: block;
  width: 100%;
  height: 100%;
  overflow-wrap: anywhere;
  padding: 10px 64px 10px 14px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}

.book-open:hover,
.book-delete:hover,
.book-edit:hover {
  transform: none;
  box-shadow: none;
}

.book-edit,
.book-delete {
  position: absolute;
  top: 6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  line-height: 0;
  display: flex;
  opacity: 0;
  transition: opacity 0.15s;
}

.book-edit {
  right: 30px;
}

.book-delete {
  right: 6px;
}

.book-item:hover .book-edit,
.book-item:focus-within .book-edit,
.book-edit:focus-visible,
.book-item:hover .book-delete,
.book-item:focus-within .book-delete,
.book-delete:focus-visible {
  opacity: 1;
}

.book-edit:hover {
  background: #e8f2ff;
  color: var(--primary);
}

.book-delete:hover {
  background: #fde8e6;
  color: #b42318;
}

.book-author {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  margin-top: 3px;
}

.job-list {
  display: grid;
  gap: 10px;
}

.job-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fafcff;
}

.job-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.job-status {
  color: var(--muted);
  text-transform: capitalize;
}

.job-card progress {
  display: block;
  width: 100%;
  height: 12px;
  margin: 8px 0;
  accent-color: var(--primary);
}

.job-message,
.job-error {
  margin: 4px 0 0;
  color: var(--muted);
}

.job-error {
  color: #9b2929;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.result-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.result-summary {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.pager button {
  padding: 8px 12px;
}

#page-indicator {
  font-size: 0.9rem;
  color: var(--muted);
}

.candidate-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--primary-soft);
  padding: 12px 14px;
}

.candidate-card strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.candidate-card .meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.candidate-card .definition {
  margin: 10px 0 6px;
  font-weight: 600;
  line-height: 1.4;
}

.definitions {
  margin: 10px 0 6px;
  padding-left: 20px;
  line-height: 1.45;
}

.definitions li + li {
  margin-top: 7px;
}

.meaning-pos {
  color: var(--primary);
  font-weight: 600;
}

.candidate-card .quotes {
  margin: 0;
  padding-left: 18px;
  color: var(--text);
}

.quote-word {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  font-weight: normal;
  font-style: italic;
}

.quotes-panel {
  margin-top: 8px;
}

.quotes-panel summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 6px;
}

.quote-empty {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: -1px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.tab:hover {
  transform: none;
  box-shadow: none;
  background: var(--primary-soft);
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab svg {
  flex: none;
}

.tab-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d92d20;
}

.tab-panel.hidden,
.tab-badge.hidden,
.inline-error.hidden {
  display: none;
}

.inline-error {
  margin: 0 0 18px;
  padding: 10px 14px;
  border: 1px solid #f4c7c3;
  border-radius: 10px;
  background: #fde8e6;
  color: #b42318;
}

.empty-state {
  margin: 8px 0;
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 700px) {
  .app-shell {
    padding: 14px;
  }

  form {
    align-items: stretch;
  }

  .inline-field,
  .inline-control,
  input[type="file"],
  input[type="number"],
  button:not(.book-delete):not(.book-edit):not(.tab):not(.back-button):not(.sign-out) {
    width: 100%;
  }

  .tab {
    flex: 1;
    justify-content: center;
    padding: 10px 8px;
  }

  .result-toolbar {
    flex-direction: column;
  }

  .pager {
    flex-wrap: wrap;
  }
}

.book-item.editing .book-open,
.book-item.editing .book-edit,
.book-item.editing .book-delete {
  display: none;
}

.book-edit-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 14px;
}

.book-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.book-edit-form input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  color: var(--text);
}

.book-edit-actions {
  display: flex;
  gap: 8px;
}

button.secondary {
  background: #eef2f7;
  color: var(--text);
}

.empty-library {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #fafcff;
  color: var(--muted);
}

.empty-library p {
  margin: 0 0 8px;
}

.empty-library p:first-child {
  color: var(--text);
  font-weight: 600;
}

.empty-library code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
}

.empty-library .go-import {
  margin-top: 6px;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  padding: 6px 10px 6px 6px;
  border: 0;
  background: transparent;
  color: var(--primary);
}

.back-button:hover {
  transform: none;
  box-shadow: none;
  background: var(--primary-soft);
}

#book-title {
  overflow-wrap: anywhere;
}

.sign-out {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
}

.sign-out:hover {
  transform: none;
  box-shadow: none;
  background: #eef2f7;
  color: var(--text);
}

.auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-shell.hidden,
.app-shell.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0;
}

.auth-card h1 {
  margin-top: 0;
}

.auth-intro {
  margin: 0 0 16px;
  color: var(--muted);
}

.auth-form {
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.auth-field input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f9fbff;
  font: inherit;
}

.auth-form .inline-error {
  margin: 0;
}
