/* Page chrome: header, panels, rule editor, feedback, buttons, modal.
   The look of the tray itself lives in scene.css. */

:root {
  --bg: #fff4f8;
  --ink: #3b2a4a;
  --muted: #8a7896;
  --panel: #ffffff;
  --line: #f1d9e6;
  --pick: #2f8cff;
  --pick-soft: #e3f0ff;
  --style: #ff4f9a;
  --style-soft: #ffe6f1;
  --good: #23a058;
  --good-soft: #e2f7ea;
  --warn-soft: #fff3d6;
  --think-soft: #f1ebff;
  --code-bg: #2a2140;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
code, kbd { font-family: var(--mono); font-size: .95em; }
code { background: rgba(59,42,74,.08); padding: 1px 6px; border-radius: 6px; }
kbd { background: #fff; border: 1px solid #d8cfe2; border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; }

/* ---------- Header ---------- */
header.top {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 20px; background: #fff; border-bottom: 3px solid var(--line);
}
.brand { font-weight: 800; font-size: 21px; white-space: nowrap; }
.mission { flex: 1; min-width: 240px; }
.lvl { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.instr { font-size: 25px; font-weight: 800; line-height: 1.2; }
.stars { display: flex; gap: 2px; }
.star {
  background: none; border: 0; font-size: 24px; line-height: 1; padding: 3px; cursor: pointer;
  border-radius: 10px; filter: grayscale(1) opacity(.3); transition: transform .15s;
}
.star.done { filter: none; }
.star.current { outline: 3px solid var(--pick); outline-offset: -1px; }
.star:not(:disabled):hover { transform: scale(1.15); }
.star:disabled { cursor: default; }
.tools { display: flex; gap: 8px; align-items: center; }
.pill { font: inherit; font-weight: 800; border: 0; border-radius: 99px; padding: 6px 14px; background: var(--style); color: #fff; cursor: pointer; }
.link { background: none; border: 0; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.link:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Layout ----------
   Mobile first: panels stack and the page scrolls (tray, then her rule, then the HTML,
   so the tray stays close to where she types).
   Wide screens: tray on the left, HTML and rule on the right.
   Wide AND tall screens: everything fits on one screen, no page scroll. */
main.layout {
  flex: 1;
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: minmax(0, 1fr);
}
.panel { background: var(--panel); border: 3px solid var(--line); border-radius: 20px; padding: 12px 16px; min-width: 0; min-height: 0; }
.panelTitle { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 8px; }
.panelTitle .sub { text-transform: none; letter-spacing: 0; font-weight: 600; opacity: .8; }
.trayPanel { order: 1; display: flex; flex-direction: column; background: #fffaf3; }
.rulePanel { order: 2; }
.codePanel { order: 3; }
#scene { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 28px 4px 16px; overflow: auto; }

@media (min-width: 901px) {
  main.layout {
    gap: 14px; padding: 14px;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .trayPanel { grid-column: 1; grid-row: 1 / 3; }
  .codePanel { grid-column: 2; grid-row: 1; }
  .rulePanel { grid-column: 2; grid-row: 2; }
}

@media (min-width: 901px) and (min-height: 600px) {
  html, body { height: 100%; }
  body { min-height: 0; overflow: hidden; }
  main.layout { min-height: 0; }
}

/* ---------- HTML panel ---------- */
.codePanel { background: var(--code-bg); border-color: #3d3160; color: #e9e3f5; }
.codePanel .panelTitle { color: #a99bc9; }
#code { margin: 0; font: 15px/1.55 var(--mono); overflow-x: auto; padding-left: 12px; }
.line { position: relative; padding: 0 8px; border-radius: 6px; white-space: pre; cursor: default; transition: background .15s; }
.line.hl { background: rgba(255,255,255,.16); }
.line.picked::before { content: "●"; position: absolute; left: -12px; color: #6cb8ff; }
.line .t { color: #ff8fc7; font-weight: 700; }
.line .a { color: #ffd66b; }
.line .v { color: #8be0a4; }
.line .pu { color: #a99bc9; }

/* ---------- Rule panel ---------- */
.rulePanel { display: flex; flex-direction: column; overflow: auto; }
#levelUI, #freeUI { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.steps { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 800; font-size: 15px; }
.step { padding: 4px 12px; border-radius: 99px; border: 2px solid transparent; opacity: .45; }
.step.s1 { color: var(--pick); background: var(--pick-soft); }
.step.s2 { color: var(--style); background: var(--style-soft); }
.step.on { opacity: 1; border-color: currentColor; }
.step.ok { opacity: 1; }
.step.ok::after { content: " ✓"; }
.arrow { color: var(--muted); }

.rule { font: 18px/1.5 var(--mono); background: #fbf8ff; border: 2px dashed #e1d4ee; border-radius: 14px; padding: 10px 14px; }
.selRow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.selInput {
  font: 20px var(--mono); padding: 6px 10px; width: 250px; max-width: 100%;
  color: var(--ink); background: var(--pick-soft);
  border: 3px solid var(--pick); border-radius: 10px; outline: none;
}
.selInput:focus { box-shadow: 0 0 0 4px rgba(47,140,255,.25); }
.selInput[readonly] { opacity: .8; }
.brace { color: var(--muted); font-weight: 700; }
.count { font: 800 13px/1 ui-rounded, system-ui, sans-serif; color: var(--pick); background: var(--pick-soft); border-radius: 99px; padding: 4px 10px; }
.count:empty { display: none; }
.declRow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 8px 28px; }
.declRow select, .declRow input {
  font: 16px var(--mono); padding: 5px 8px; color: var(--ink);
  background: var(--style-soft); border: 3px solid var(--style); border-radius: 10px; outline: none;
}
.declRow select:focus, .declRow input:focus { box-shadow: 0 0 0 4px rgba(255,79,154,.22); }
.declRow input { width: 170px; }
.declRow.locked { opacity: .45; filter: grayscale(.7); }
.lockNote { font: 700 13px ui-rounded, system-ui, sans-serif; color: var(--muted); }
.declRow:not(.locked) .lockNote { display: none; }
.colon, .semi { color: var(--muted); font-weight: 700; }

.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 12px; font-size: 17px; line-height: 1.4; background: #f6f1fb; min-height: 48px; }
.feedback.good { background: var(--good-soft); }
.feedback.warn { background: var(--warn-soft); }
.feedback.think { background: var(--think-soft); }
.feedback .ask { margin-top: 8px; padding-top: 8px; border-top: 2px dashed rgba(0,0,0,.1); font-weight: 700; }
code.hint { font-size: 18px; background: #fff; }
.blank { display: inline-block; min-width: 1ch; border-bottom: 3px solid var(--style); color: var(--style); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { font: inherit; font-weight: 800; font-size: 16px; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.blue { background: var(--pick); color: #fff; }
.btn.pink { background: var(--style); color: #fff; }
.btn.green { background: var(--good); color: #fff; }
.btn.ghost { background: #f1ebf8; color: var(--ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.nudge { animation: nudge .8s ease-in-out 4; }
@keyframes nudge { 50% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(255,201,60,.6); } }

/* ---------- Free play ---------- */
#rules { flex: 1; min-height: 0; overflow: auto; padding-right: 4px; }
.card { font: 16px/1.5 var(--mono); background: #fbf8ff; border: 2px dashed #e1d4ee; border-radius: 14px; padding: 10px 12px; margin-bottom: 10px; }
.card .selInput { font-size: 17px; width: 210px; }
.card .declRow { margin: 6px 0 6px 22px; }
.x { background: none; border: 0; cursor: pointer; font-size: 15px; padding: 2px 6px; border-radius: 6px; color: var(--muted); }
.x:hover { background: #f1ebf8; color: var(--ink); }
.addDecl { color: var(--style); margin-left: 22px; font-family: ui-rounded, system-ui, sans-serif; }
.empty { color: var(--muted); font-size: 16px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(40,20,60,.45); }
.modalBox { background: #fff; border-radius: 20px; padding: 20px 22px; width: 100%; max-width: 560px; max-height: 85vh; overflow: auto; }
.modalBox h2 { margin: 0 0 6px; }
.modalBox p { margin: 0 0 12px; font-size: 17px; }
pre.sheet { margin: 0; background: var(--code-bg); color: #e9e3f5; padding: 14px 16px; border-radius: 12px; font: 15px/1.6 var(--mono); white-space: pre-wrap; }
.sheet .cs { color: #6cb8ff; font-weight: 700; }
.sheet .cp { color: #ff8fc7; }
.sheet .cv { color: #8be0a4; }
.sheet .cm { color: #a99bc9; }

.confetti { position: fixed; top: 0; z-index: 50; pointer-events: none; border-radius: 2px; }

/* Keep selects and inputs from pushing past the panel edge */
.declRow select, .declRow input, .selInput { max-width: 100%; min-width: 0; }

/* Tablets and small laptops */
@media (max-width: 1100px) {
  .instr { font-size: 22px; }
  #code { font-size: 14px; }
}

/* Short laptop screens: tighten vertical space so it still fits without scrolling */
@media (min-width: 901px) and (max-height: 760px) {
  header.top { padding: 6px 16px; }
  .instr { font-size: 21px; }
  main.layout { gap: 10px; padding: 10px; }
  .panel { padding: 8px 14px; }
  #code { font-size: 13px; line-height: 1.45; }
  .steps { margin-bottom: 6px; }
  .feedback { margin-top: 8px; padding: 8px 12px; font-size: 16px; min-height: 0; }
  .actions { margin-top: 8px; }
  .btn { padding: 8px 14px; }
}

/* Phones */
@media (max-width: 560px) {
  header.top { gap: 6px 10px; padding: 8px 12px; }
  .brand { font-size: 18px; flex: 1; }
  .mission { order: 3; flex-basis: 100%; min-width: 0; }
  .instr { font-size: 19px; }
  .stars { order: 4; flex-basis: 100%; justify-content: space-between; }
  .star { font-size: 22px; padding: 2px; }
  main.layout { gap: 10px; padding: 8px; }
  .panel { padding: 10px 12px; border-radius: 16px; }
  #code { font-size: 12.5px; padding-left: 10px; }
  .rule { font-size: 16px; padding: 8px 10px; }
  .selInput { font-size: 18px; width: calc(100% - 2ch); }
  .declRow { margin: 8px 0 8px 10px; }
  .feedback { font-size: 16px; }
  .actions .btn { flex: 1 1 auto; }
  .card .selInput { width: 100%; }
  .card .declRow { margin-left: 8px; }
  .addDecl { margin-left: 8px; }
  .modalBox { padding: 16px; }
  pre.sheet { font-size: 14px; }
}

/* Touch screens: bigger tap targets, no hover-only affordances */
@media (pointer: coarse) {
  .x { padding: 6px 10px; font-size: 17px; }
  .star { padding: 4px; }
  .codePanel .panelTitle .sub { display: none; }
}
