:root {
  --paper: #f7f3ee;
  --card: #fffdfa;
  --ink: #2c2622;
  --inkSoft: #6f645c;
  --line: #e3d9cd;
  --accent: #8c6b4f;
  --accentInk: #fffdfa;
  --danger: #a8462f;
  --good: #4f7a52;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(44, 38, 34, 0.06), 0 8px 24px rgba(44, 38, 34, 0.06);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191614;
    --card: #232020;
    --ink: #f0e9e2;
    --inkSoft: #a79c93;
    --line: #362f2b;
    --accent: #c79a72;
    --accentInk: #1c1917;
    --danger: #e0866c;
    --good: #8fbc92;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(2.5rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.masthead {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}

.masthead__flourish {
  margin: 0;
  color: var(--accent);
  font-size: 1.5rem;
  line-height: 1;
}

.masthead__title {
  margin: 0.5rem 0 0.25rem;
  font-family: var(--serif);
  font-size: clamp(1.75rem, 8vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.masthead__subtitle {
  margin: 0;
  color: var(--inkSoft);
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.card--flush {
  padding-bottom: 0.75rem;
}

.card--welcome {
  background: linear-gradient(160deg, var(--card), var(--paper));
  border-color: var(--accent);
  text-align: center;
}

.welcome__text {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.55;
  color: var(--ink);
  text-wrap: pretty;
}

.card__heading {
  margin: 0 0 0.75rem;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 500;
}

.card__headerRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.card__headerRow .card__heading {
  margin-bottom: 0.75rem;
}

.card__hint {
  margin: 0.75rem 0 0;
  color: var(--inkSoft);
  font-size: 0.85rem;
}

.pill {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  color: var(--inkSoft);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.namebar {
  display: flex;
  gap: 0.5rem;
}

.namebar__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.7rem 0.85rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
}

.namebar__input:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, opacity 0.15s ease;
}

.button:active {
  transform: scale(0.985);
}

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button--primary {
  background: var(--accent);
  color: var(--accentInk);
}

.button--secondary {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.button--quiet {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  min-height: 2.75rem;
  flex: 0 0 auto;
}

.button__glyph {
  font-size: 1.05rem;
  line-height: 1;
}

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

.queueItem__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.queueItem__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queueItem__state {
  flex: 0 0 auto;
  color: var(--inkSoft);
  font-variant-numeric: tabular-nums;
}

.queueItem__state--failed {
  color: var(--danger);
}

.queueItem__state--done {
  color: var(--good);
}

.track {
  position: relative;
  height: 5px;
  margin-top: 0.4rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.track__fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

.track--indeterminate .track__fill {
  width: 100% !important;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 40%,
    var(--accent) 60%,
    transparent 100%
  );
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: trackSweep 1.15s ease-in-out infinite;
}

@keyframes trackSweep {
  from {
    background-position: -45% 0;
  }
  to {
    background-position: 145% 0;
  }
}

.track--stalled .track__fill {
  background: var(--danger);
  animation: trackPulse 1.4s ease-in-out infinite;
}

@keyframes trackPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.track--batch {
  height: 8px;
}

.queueItem__detail {
  margin-top: 0.3rem;
  color: var(--inkSoft);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.queueItem__state--stalled {
  color: var(--danger);
}

.batch {
  padding: 0.7rem 0.8rem 0.8rem;
  margin-bottom: 0.9rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.batch__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.batch__label {
  font-size: 0.9rem;
  font-weight: 600;
}

.batch__percent {
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.batch__detail {
  margin: 0.4rem 0 0;
  color: var(--inkSoft);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.grid {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.6rem;
}

.tile {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
}

.tile__link {
  display: block;
  aspect-ratio: 1;
}

.tile__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--line);
}

.tile__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--inkSoft);
  font-size: 1.5rem;
}

.tile__badge {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  padding: 0.1rem 0.4rem;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 6px;
  color: #fff;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.tile__remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(0, 0, 0, 0.62);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.tile__caption {
  width: 100%;
  padding: 0.45rem 0.5rem;
  background: var(--card);
  border: none;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.78rem;
}

.tile__caption::placeholder {
  color: var(--inkSoft);
}

.tile__caption:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.footer {
  padding-top: 0.5rem;
  color: var(--inkSoft);
  font-size: 0.78rem;
  text-align: center;
}

.footer p {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 0.7rem 1rem;
  background: var(--ink);
  border-radius: 10px;
  color: var(--paper);
  font-size: 0.88rem;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 20;
}

.visuallyHidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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