* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  background: #fafafa;
  color: #2c2c2c;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
}
h1 { font-size: 1.4rem; font-weight: 600; }

.modes, .actions { display: flex; gap: 0.4rem; }
.actions { margin-left: auto; }

button {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}
button:hover:not(:disabled) { background: #f0f0f0; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.mode { font-size: 1.05rem; padding: 0.5rem 1.1rem; }
.mode.active { background: #ffd54f; border-color: #f9a825; font-weight: 600; }

.examples {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
  font-size: 0.95rem;
  position: relative;
  flex-wrap: wrap;
  row-gap: 0.3rem;
}
.examples-label {
  color: #888;
  font-style: italic;
  margin-right: 0.2rem;
}
button.example {
  padding: 0.35rem 0.85rem;
  font-size: 0.95rem;
  border-radius: 999px;
  background: #f5f5f5;
  border-color: #ccc;
}
button.example:hover:not(:disabled) {
  background: #ffd54f;
  border-color: #f9a825;
}
#save-script { margin-left: auto; }

.popover {
  position: absolute;
  top: 100%;
  margin-top: 0.4rem;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0.7rem;
  font-size: 0.9rem;
  min-width: 16rem;
  z-index: 10;
}
/* `left` is a fallback only -- anchorPopover() in app.js positions each panel
   under the button that opened it, which is why Quest used to open on the far
   left while its button sat on the far right. */
#save-popover, #dirty-confirm, #scripts-panel, #animal-panel,
#quest-panel { left: 1rem; }
#quest-panel { max-width: 25rem; }
#quest-panel .popover-hint { white-space: nowrap; }
#animal-panel { max-width: 26rem; }
#scripts-panel { max-width: 22rem; }

.popover-label {
  display: block;
  margin-bottom: 0.3rem;
  color: #555;
  font-size: 0.85rem;
}
.popover-message {
  margin-bottom: 0.5rem;
  color: #333;
}
.popover input[type=text] {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}
.popover input[type=text]:focus {
  outline: none;
  border-color: #f9a825;
}
.popover-actions {
  display: flex;
  gap: 0.4rem;
}
.popover-actions button {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 4px;
}
.popover-primary {
  background: #4caf50;
  color: white;
  border-color: #388e3c;
}
.popover-primary:hover:not(:disabled) { background: #43a047; }
.popover-primary:disabled {
  background: #c8e6c9;
  border-color: #a5d6a7;
}
.danger-btn {
  background: #ffb74d;
  border-color: #f57c00;
  color: #4a2c00;
}
.danger-btn:hover:not(:disabled) { background: #ffa726; }

.popover-hint {
  margin-top: 0.4rem;
  color: #888;
  font-size: 0.8rem;
  font-style: italic;
}

/* Animal picker: a grid of emoji you can click to become. */
.animal-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.3rem;
}
.animal-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.35rem 0.15rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f5f5f5;
  cursor: pointer;
}
.animal-choice:hover { background: #ffd54f; border-color: #f9a825; }
.animal-choice.current { background: #fff3c4; border-color: #f9a825; }
.animal-glyph { font-size: 1.6rem; line-height: 1.1; }
.animal-name {
  font-size: 0.6rem;
  color: #666;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scripts-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 18rem;
  overflow-y: auto;
}
.scripts-empty {
  padding: 0.5rem 0.2rem;
  color: #888;
  font-style: italic;
  text-align: center;
}
.script-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem;
  border-radius: 4px;
}
.script-row:hover { background: #fff9c4; }
.script-load {
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.script-load:hover:not(:disabled) { background: #ffd54f; }
.script-row.current .script-load::before {
  content: "🐔 ";
}
.script-row:not(.current) .script-load { padding-left: 1.7rem; }
.script-delete {
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid transparent;
  color: #888;
  border-radius: 4px;
}
.script-delete:hover:not(:disabled) {
  background: #ffe0e0;
  border-color: #ef9a9a;
  color: #c62828;
}
.script-row.confirming {
  background: #fff3cd;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  gap: 0.4rem;
}
.script-row.confirming .confirm-text {
  flex: 1;
  color: #6d4c41;
}
.script-row.confirming button {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

#run { background: #4caf50; color: white; border-color: #388e3c; }
#run:hover:not(:disabled) { background: #43a047; }

#stop { background: #ef5350; color: white; border-color: #c62828; }
#stop:hover:not(:disabled) { background: #e53935; }

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.editor {
  width: 40%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #ddd;
}
/* The editor is a stack: highlight bands underneath, transparent textarea on
   top. Both share one padding and line-height, and the textarea never wraps,
   so a line number maps straight to a row offset. */
.code-area {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #1e1e2e;
}
#code-marks {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.mark {
  position: absolute;
  left: 0;
  right: 0;
  border-left: 5px solid transparent;
}
.mark.error   { background: rgba(229, 57, 53, 0.30);  border-left-color: #e53935; }
.mark.running { background: rgba(255, 213, 79, 0.20); border-left-color: #ffd54f; }

#code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  font-family: "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 1.2rem;
  padding: 1rem;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: #cdd6f4;
  line-height: 1.7rem;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

/* The one place the kid is already looking when a program fails. */
.code-banner {
  padding: 0.7rem 1rem;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 600;
  border-bottom: 3px solid;
}
.code-banner[hidden] { display: none; }
.code-banner.error { background: #ffebee; color: #b71c1c; border-color: #e53935; }
.code-banner.win   { background: #e8f5e9; color: #1b5e20; border-color: #43a047; }
.code-banner.retry { background: #fff8e1; color: #7a4a00; border-color: #f9a825; }

.cheatsheet {
  background: #fff9c4;
  color: #5d4037;
  border-top: 3px solid #f9a825;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  max-height: 55%;
  flex-shrink: 0;
}
.cheatsheet-toggle {
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6d4c41;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.cheatsheet-toggle:hover:not(:disabled) { background: rgba(0,0,0,0.05); }
.cheatsheet-chevron { font-size: 0.85rem; color: #8b6f47; }
.cheatsheet-body {
  padding: 0 1rem 0.5rem;
  overflow-y: auto;
}
.cheatsheet-body[hidden] { display: none; }
.cheatsheet-body table { width: 100%; border-collapse: collapse; }
.cheatsheet-body td { padding: 0; vertical-align: top; }
.cheatsheet-body td:first-child {
  white-space: nowrap;
  padding-right: 1rem;
  color: #1e1e2e;
  font-weight: 600;
}
.cheatsheet-body tr.spacer td { padding-top: 0.25rem; }

.coop {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f0d8;
  padding: 0.6rem;
  min-width: 0;
  min-height: 0;
}
/* Fill the pane, whatever shape it is. This used to also carry
   `aspect-ratio: 1/1` and `max-height: 100%`, which fought each other: the
   aspect-ratio wanted height == width, max-height clamped the height back
   down, and `width: 100%` is a definite size so it never shrank to match.
   The element ended up oblong while the backing store stayed 600x600, and the
   browser stretched one into the other -- which is what made the compass an
   oval. The canvas now has no intrinsic shape; coop.js keeps the backing
   store matched to whatever size this rule produces. */
#canvas {
  background: #fffdf5;
  border: 3px solid #8b6f47;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: block;
  width: 100%;
  height: 100%;
}

footer {
  padding: 0.5rem 1rem;
  background: #fff;
  border-top: 1px solid #ddd;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 1rem;
  color: #555;
  min-height: 2rem;
}
#status.error { color: #c62828; }

/* Quest mode: the level picker, and the button that says which one you're on. */
.quest-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 28rem;
  overflow-y: auto;
}
.quest-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #f5f5f5;
  font-family: inherit;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}
.quest-row:hover { background: #ffd54f; border-color: #f9a825; }
.quest-row.current { background: #fff3c4; border-color: #f9a825; }
.quest-name { color: #333; }
.quest-stars {
  color: #ccc;
  letter-spacing: 0.05em;
  font-size: 1.15rem;
  white-space: nowrap;
}
.quest-stars.earned { color: #f9a825; }

