:root {
  --orange: #ff8c42;
  --orange-dark: #d76624;
  --yellow: #ffd166;
  --yellow-soft: #fff0b8;
  --cream: #fff8ec;
  --paper: #fef3d8;
  --ink: #4a3520;
  --ink-soft: #6b5238;
  --green: #6abe6a;
  --green-soft: #eaf7e4;
  --pink: #e85d8a;
  --pink-soft: #fce8f0;
  --purple: #a67bd4;
  --purple-soft: #f3e9fc;
  --gray: #8b7d6b;
  --shadow: 0 3px 0 rgba(74, 53, 32, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  line-height: 1.55;
}

.loading {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-soft);
}

.loading .cat {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--orange-dark);
  font-size: 1.15rem;
  line-height: 1.2;
  margin-bottom: 1rem;
}

#loading-text { font-size: 1.05rem; margin: 0.5rem 0 0.25rem; }
.loading-note { color: var(--gray); font-size: 0.9rem; }

.game {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px dashed var(--orange);
  padding-bottom: 0.6rem;
  margin-bottom: 1.2rem;
}

h1 {
  font-size: 1.6rem;
  color: var(--orange-dark);
  margin: 0;
  letter-spacing: 0.5px;
}

h2 {
  color: var(--orange-dark);
  font-size: 1.05rem;
  margin: 0 0 0.75rem;
  letter-spacing: 0.5px;
}

section {
  background: var(--paper);
  border: 2px solid var(--orange);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.cat-panel {
  text-align: center;
  background: var(--yellow-soft);
  border-color: var(--yellow);
}

.cat-panel .cat {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--orange-dark);
  font-size: 1.05rem;
  line-height: 1.15;
  margin: 0;
  white-space: pre;
}

.chapter-label {
  font-weight: 700;
  color: var(--orange-dark);
  font-size: 1.1rem;
  margin-top: 0.5rem;
}

#story-text,
#lesson-text,
#challenge-instructions,
#ending-text {
  white-space: pre-wrap;
  font-size: 1rem;
  color: var(--ink);
}

pre.code-example,
.editor textarea,
.output {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
}

pre.code-example {
  background: #2b1f10;
  color: #ffd166;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0.75rem 0 0.5rem;
  white-space: pre;
}

.editor { margin: 0.75rem 0 0.25rem; }

.editor label {
  display: block;
  font-size: 0.85rem;
  color: var(--gray);
  margin-bottom: 0.35rem;
}

.editor textarea {
  width: 100%;
  background: #2b1f10;
  color: #ffd166;
  border: 2px solid var(--orange);
  border-radius: 10px;
  padding: 0.8rem;
  resize: vertical;
  min-height: 180px;
  outline: none;
  tab-size: 4;
}

.editor textarea:focus {
  border-color: var(--orange-dark);
  box-shadow: 0 0 0 3px rgba(255, 140, 66, 0.25);
}

.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0 0;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.05s, background 0.15s;
}

button:hover { background: var(--orange-dark); }
button:active { transform: translateY(1px); box-shadow: none; }

button.secondary {
  background: var(--yellow);
  color: var(--ink);
}
button.secondary:hover { background: #f0b942; }

.output {
  white-space: pre-wrap;
  padding: 0.75rem 0.9rem;
  background: white;
  border: 1px dashed var(--gray);
  border-radius: 10px;
  min-height: 1.6rem;
  margin-top: 0.75rem;
  color: var(--ink-soft);
}

.output.success {
  background: var(--green-soft);
  border-color: var(--green);
  border-style: solid;
  color: #2d6a2d;
}
.output.error {
  background: var(--pink-soft);
  border-color: var(--pink);
  border-style: solid;
  color: #a3284e;
}
.output.hint {
  background: var(--purple-soft);
  border-color: var(--purple);
  border-style: solid;
  color: #5b3989;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.chapter-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.9rem;
  border: 2px solid var(--orange);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  transition: background 0.15s;
}

.chapter-item:hover { background: var(--yellow-soft); }

.chapter-item .badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green);
}

footer {
  text-align: center;
  color: var(--gray);
  font-size: 0.85rem;
  padding: 1rem;
}

footer a { color: var(--orange-dark); }

@media (max-width: 600px) {
  h1 { font-size: 1.3rem; }
  .game { padding: 0.65rem; }
  section { padding: 0.85rem 1rem; }
  .cat-panel .cat { font-size: 0.95rem; }
  button { padding: 0.5rem 1rem; font-size: 0.9rem; }
}
