:root {
  --app-ink: #283547;
  --app-muted: #5b6672;
  --app-surface: #ffffff;
  --app-background: #f4f8f7;
  --app-primary: #187c70;
  --app-primary-dark: #0e5f56;
  --app-accent: #f3a340;
  --app-border: #c8d7d4;
  --app-success: #16734a;
  --app-error: #9f4a2c;
  --app-radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--app-background);
  color: var(--app-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  line-height: 1.55;
}

button { font: inherit; }

button:focus-visible {
  outline: 4px solid #1d6fd8;
  outline-offset: 3px;
}

.app-shell {
  width: min(100% - 32px, 1040px);
  margin: 0 auto;
  padding: 28px 0 48px;
}

.app-header, .story-nav, .status-bar, section[aria-labelledby], .actions, .result {
  margin-top: 18px;
}

.app-header { text-align: center; }
.app-header h1 { margin: 4px 0; font-size: clamp(1.7rem, 5vw, 2.5rem); }
.app-header p { margin: 0; font-size: clamp(1rem, 3vw, 1.2rem); }
.eyebrow { color: var(--app-primary-dark); font-weight: 700; }

.story-nav, .status-bar, section[aria-labelledby], .result {
  padding: 18px;
  background: var(--app-surface);
  border: 2px solid var(--app-border);
  border-radius: var(--app-radius);
}

.nav-label, .story-title, .attempts, .instruction { margin: 0; }
.nav-label, .instruction { color: var(--app-muted); }
.story-controls { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 10px; }
.story-select-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.story-select { width: 100%; min-height: 48px; padding: 10px 12px; border: 2px solid var(--app-primary); border-radius: 12px; background: #fff; color: var(--app-ink); font: inherit; font-weight: 700; }

.story-button, .button {
  min-height: 48px;
  padding: 10px 16px;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}

.story-button { background: #e7f0ee; color: var(--app-ink); }
.story-button[aria-current="true"] { background: var(--app-primary); color: #fff; border-color: var(--app-primary-dark); }
.status-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; }
.story-title { font-size: 1.2rem; font-weight: 800; }
.attempts { font-weight: 700; }

.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
h2 { margin: 0 0 8px; font-size: clamp(1.2rem, 3.5vw, 1.5rem); }
.section-heading h2 { margin: 0; }

.card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.comic-card, .empty-slot {
  min-width: 0;
  border-radius: 14px;
  overflow: hidden;
}

.comic-card {
  padding: 0;
  background: var(--app-surface);
  border: 3px solid var(--app-primary);
  color: var(--app-ink);
  cursor: pointer;
  text-align: left;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.comic-card:hover { border-color: var(--app-accent); }
.comic-card.is-dragging { opacity: .35; }
.comic-card img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: contain; background: #f5f5f0; }
.card-label { display: block; min-height: 2.8em; padding: 8px 9px; font-size: clamp(.78rem, 2.4vw, 1rem); font-weight: 700; }
.hint-hidden .card-label { display: none; }

.empty-slot {
  display: grid;
  min-height: 160px;
  place-items: center;
  padding: 12px;
  border: 3px dashed #94ada8;
  background: #edf4f2;
  color: var(--app-muted);
  text-align: center;
}
.drop-slot {
  position: relative;
  min-width: 0;
  min-height: 160px;
  border-radius: 14px;
  transition: border-color .15s, background-color .15s, transform .15s;
}
.available-cards {
  min-height: 72px;
  transition: outline-color .15s;
}
.drop-slot.is-drop-target {
  outline: 4px solid var(--app-accent);
  outline-offset: 3px;
  border-color: var(--app-accent);
  background: #fff7e9;
  transform: scale(1.02);
}
.available-cards.is-drop-target {
  outline: 4px solid var(--app-accent);
  outline-offset: 5px;
  border-radius: 14px;
}
.drag-preview {
  position: fixed;
  z-index: 10;
  width: var(--drag-width);
  pointer-events: none;
  opacity: .9;
  transform: translate(-50%, -50%);
  box-shadow: 0 12px 24px rgba(40, 53, 71, .24);
}
.slot-number {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 2;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 2px solid var(--app-primary);
  border-radius: 50%;
  background: rgba(255, 255, 255, .94);
  color: var(--app-primary-dark);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}
.slot-prompt { font-weight: 700; }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.button-primary { background: var(--app-primary); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--app-primary-dark); }
.button-secondary { background: #fff7e9; border-color: #d89131; color: #70400d; }
.button:disabled { cursor: not-allowed; opacity: .5; }

.result { font-size: 1.1rem; font-weight: 700; text-align: center; }
.result.is-correct { border-color: var(--app-success); color: var(--app-success); background: #eef9f1; }
.result.is-incorrect { border-color: var(--app-error); color: var(--app-error); background: #fff2ec; }
.next-button { display: block; margin: 12px auto 0; }

@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1040px); padding-top: 18px; }
  .story-nav, .status-bar, section[aria-labelledby], .result { padding: 14px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .empty-slot { min-height: 140px; }
  .drop-slot { min-height: 140px; }
  .story-controls { grid-template-columns: 1fr 1fr; }
  .story-select { grid-column: 1 / -1; grid-row: 1; }
  .story-controls .button { grid-row: 2; }
}
