:root {
  --paper: #eae7dd;
  --surface: #f5f3ec;
  --ink: #1b1e1c;
  --ink-soft: #4a4d47;
  --line: #cdc7b6;
  --teal: #2c5f58;
  --teal-deep: #1d423d;
  --teal-tint: #dce7e4;
  --amber: #a3612a;
  --error: #963b2e;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "IBM Plex Sans", -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: var(--teal-deep); }
a:hover { color: var(--teal); }

code {
  font-family: var(--mono);
  background: var(--surface);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.9em;
}

.masthead {
  position: relative;
  padding: 4.5rem 1.5rem 3rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.masthead-inner { max-width: 40rem; margin: 0 auto; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-deep);
  display: inline-block;
  padding: 0.3em 0.8em;
  border: 1px solid var(--teal);
  border-radius: 999px;
  background: var(--teal-tint);
}

h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  margin: 0.6em 0 0.3em;
  letter-spacing: -0.01em;
}
h1 .dash { color: var(--teal); }

.tagline {
  font-size: 1.08rem;
  color: var(--ink-soft);
  max-width: 32rem;
  margin: 0 auto;
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  position: relative;
  z-index: 1;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}
.tab-btn {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.6em 0.2em;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab-btn + .tab-btn { margin-left: 1.2rem; }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--teal-deep); border-bottom-color: var(--teal); }

.tab-panel[hidden] { display: none; }

.dropzone-section { margin-bottom: 2.5rem; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 2.6rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.drag-over {
  border-color: var(--teal);
  background: var(--teal-tint);
  outline: none;
}

.book-icon {
  width: 48px;
  height: 48px;
  color: var(--teal-deep);
  margin-bottom: 0.6rem;
}

.drop-title {
  font-family: var(--serif);
  font-size: 1.25rem;
  margin: 0 0 0.25rem;
}
.drop-hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.wasm-status {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.7rem;
}
.wasm-status.ready { color: var(--teal-deep); }
.wasm-status.failed { color: var(--error); }

.queue-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.queue-header h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0;
}
.queue-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55em 1.1em;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-primary:not(:disabled):hover { background: var(--teal-deep); }
.btn-accent { background: var(--teal); color: #fff; }
.btn-accent:not(:disabled):hover { background: var(--teal-deep); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:not(:disabled):hover { border-color: var(--ink-soft); color: var(--ink); }

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.empty-hint {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-style: italic;
}
.file-list:not(:empty) + .empty-hint,
.queue-section.has-files .empty-hint { display: none; }

/* "book spine" row: the signature element.
   A vertical accent bar acts as the spine; a fill sweeps up it while
   converting, echoing the Kobo "Page Flip" corner used on real KEPUBs. */
.file-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.9rem 0.7rem 0;
  overflow: hidden;
}

.spine {
  width: 6px;
  align-self: stretch;
  background: var(--line);
  position: relative;
  overflow: hidden;
}
.spine::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: var(--teal);
  transition: height 0.25s ease;
}
.file-row[data-status="converting"] .spine::after { height: 55%; animation: spine-pulse 1.1s ease-in-out infinite; }
.file-row[data-status="done"] .spine::after { height: 100%; background: var(--teal-deep); animation: none; }
.file-row[data-status="error"] .spine { background: var(--error); }

@keyframes spine-pulse {
  0%, 100% { height: 35%; }
  50% { height: 80%; }
}

.file-meta { min-width: 0; }
.file-name {
  font-weight: 500;
  font-size: 0.94rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-status {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
}
.file-status.error { color: var(--error); }
.file-status.done { color: var(--teal-deep); }

.page-flip {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--teal);
  border-radius: 2px;
  position: relative;
  visibility: hidden;
}
.file-row[data-status="converting"] .page-flip {
  visibility: visible;
  animation: flip 0.9s linear infinite;
  transform-style: preserve-3d;
  transform-origin: left center;
}
@keyframes flip {
  0% { transform: perspective(40px) rotateY(0deg); }
  50% { transform: perspective(40px) rotateY(180deg); }
  100% { transform: perspective(40px) rotateY(360deg); }
}

.file-download {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--teal-deep);
  text-decoration: none;
  padding: 0.3em 0.7em;
  border: 1px solid var(--teal);
  border-radius: 5px;
  visibility: hidden;
  white-space: nowrap;
}
.file-row[data-status="done"] .file-download { visibility: visible; }
.file-download:hover { background: var(--teal-tint); }

/* ---- metadata tab ---- */

.meta-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.meta-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
}

.meta-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.meta-card-body {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1.2rem;
}

.cover-preview {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}
.cover-preview img {
  width: 9rem;
  height: 12.5rem;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.cover-placeholder {
  width: 9rem;
  height: 12.5rem;
  border-radius: 4px;
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-align: center;
  background: var(--paper);
}

.btn-small {
  font-size: 0.76rem;
  padding: 0.35em 0.7em;
  cursor: pointer;
  text-align: center;
}

.meta-fields {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: flex-start;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.field input[type="text"] {
  font-family: var(--sans);
  font-size: 0.95rem;
  color: var(--ink);
  padding: 0.45em 0.6em;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
}
.field input[type="text"]:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

@media (max-width: 30rem) {
  .meta-card-body { grid-template-columns: 1fr; }
  .cover-preview { flex-direction: row; }
}

.about {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}
.about h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
}
.about p { color: var(--ink-soft); }

.site-footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding: 2rem 1.5rem 3rem;
}

@media (max-width: 30rem) {
  .file-row { grid-template-columns: auto 1fr; grid-template-rows: auto auto; row-gap: 0.4rem; }
  .page-flip, .file-download { grid-column: 2; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .file-row[data-status="converting"] .spine::after,
  .file-row[data-status="converting"] .page-flip {
    animation: none;
  }
}
