:root {
  color-scheme: light;
  --ink: #26241f;
  --muted: #676258;
  --paper: #fffdf8;
  --canvas: #f4efe4;
  --line: #d7cdbd;
  --accent: #8a3f2d;
  --accent-dark: #672d20;
  --gold: #d49b38;
  --used-bg: #e7e3d9;
  --focus: #1268a8;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic UI", "Hiragino Sans", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgb(212 155 56 / 16%), transparent 24rem),
    var(--canvas);
  line-height: 1.65;
}

button,
input,
textarea {
  font: inherit;
}

button,
.file-label {
  touch-action: manipulation;
}

input[type="text"],
input[type="search"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #9c9589;
  border-radius: 0.45rem;
}

textarea {
  resize: vertical;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 20;
  padding: 0.6rem 0.8rem;
  color: #fff;
  background: #111;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
main {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 2.2rem 0 1.2rem;
}

.site-header h1,
.section-heading h2,
.card-title {
  font-family: Georgia, "Yu Mincho", "Hiragino Mincho ProN", serif;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  line-height: 1.2;
}

.site-header p {
  margin: 0.3rem 0 0;
}

.site-header .eyebrow,
.step-label {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.offline-badge,
.state-badge,
.count {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.offline-badge {
  flex: 0 0 auto;
  padding: 0.4rem 0.75rem;
  color: #245237;
  background: #dcebdd;
}

main {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(380px, 1.2fr);
  gap: 1.25rem;
  padding-bottom: 5rem;
  align-items: start;
}

.panel {
  padding: clamp(1rem, 3vw, 1.5rem);
  background: rgb(255 253 248 / 96%);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  box-shadow: 0 0.7rem 2rem rgb(67 54 35 / 9%);
}

.setup-panel {
  position: sticky;
  top: 1rem;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0.05rem 0 0;
  line-height: 1.25;
}

label,
legend {
  font-weight: 700;
}

.setup-panel > label,
.character-limit label {
  display: block;
  margin-top: 0.8rem;
  margin-bottom: 0.25rem;
}

fieldset {
  margin: 1rem 0 0;
  padding: 0;
  border: 0;
}

.split-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.split-options label {
  padding: 0.45rem 0.65rem;
  background: #f4eee3;
  border-radius: 0.4rem;
  cursor: pointer;
}

.character-limit input {
  max-width: 12rem;
}

.button {
  display: inline-flex;
  min-height: 2.6rem;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.85rem;
  border: 1px solid transparent;
  border-radius: 0.45rem;
  font-weight: 750;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  width: 100%;
  margin-top: 1.2rem;
  color: #fff;
  background: var(--accent);
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  color: var(--ink);
  background: #f8f4eb;
  border-color: #aca398;
}

.button.secondary:hover {
  background: #ebe3d5;
}

.button.danger {
  color: #7d211d;
  background: #fff6f4;
  border-color: #d7a49f;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.file-actions,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.file-label {
  user-select: none;
}

.visually-hidden:focus-visible + .file-label {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.count {
  padding: 0.2rem 0.55rem;
  vertical-align: middle;
  color: var(--muted);
  background: #eee6d8;
}

.search-row {
  display: grid;
  grid-template-columns: auto minmax(10rem, 1fr);
  align-items: center;
  gap: 0.5rem 0.8rem;
  margin-bottom: 1rem;
}

.help-text {
  display: none;
  grid-column: 2;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.help-text.visible {
  display: block;
}

.empty-state {
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: 0.6rem;
}

.card-list {
  display: grid;
  gap: 0.85rem;
}

.queue-card {
  overflow: hidden;
  background: #fff;
  border: 1px solid #c9bca8;
  border-left: 5px solid var(--gold);
  border-radius: 0.65rem;
  transition: box-shadow 120ms ease, opacity 120ms ease;
}

.queue-card[draggable="true"] {
  cursor: grab;
}

.queue-card.dragging {
  opacity: 0.45;
}

.queue-card.drag-over {
  box-shadow: 0 0 0 4px rgb(18 104 168 / 30%);
}

.queue-card.used {
  background: var(--used-bg);
  border-left-color: #716c63;
}

.queue-card.used .card-title {
  text-decoration: line-through;
}

.card-copy {
  display: block;
  width: 100%;
  padding: 1rem;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: copy;
}

.card-copy:hover {
  background: rgb(212 155 56 / 8%);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.card-title {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.3;
}

.state-badge {
  flex: 0 0 auto;
  padding: 0.2rem 0.5rem;
  color: #694b16;
  background: #f6e1b9;
}

.used .state-badge {
  color: #4f4b43;
  background: #d0cbc1;
}

.card-body {
  display: -webkit-box;
  margin: 0.7rem 0 0;
  overflow: hidden;
  color: #4c4943;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

.copy-hint {
  display: block;
  margin-top: 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.card-actions {
  padding: 0 1rem 1rem;
}

.card-actions .button {
  min-height: 2.25rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.88rem;
}

.edit-form {
  display: grid;
  gap: 0.45rem;
  padding: 1rem;
  background: #fbf7ef;
  border-top: 1px solid var(--line);
}

.edit-form textarea {
  min-height: 9rem;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.status {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: min(28rem, calc(100% - 2rem));
  padding: 0.8rem 1rem;
  color: #fff;
  background: #2d2a26;
  border-radius: 0.45rem;
  box-shadow: 0 0.4rem 1.2rem rgb(0 0 0 / 25%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 150ms ease, transform 150ms ease;
}

.status.visible {
  opacity: 1;
  transform: translateY(0);
}

.status.error {
  background: #8b2621;
}

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

@media (max-width: 800px) {
  main {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    position: static;
  }

  .queue-heading {
    display: block;
  }

  .file-actions {
    margin-top: 1rem;
  }
}

@media (max-width: 520px) {
  .site-header {
    align-items: flex-start;
  }

  .section-heading,
  .search-row {
    display: block;
  }

  .section-heading .button,
  .search-row input {
    margin-top: 0.5rem;
  }

  .file-actions .button,
  .file-actions .file-label {
    flex: 1 1 8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
