@import url('https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic:wght@500;700;900&family=JetBrains+Mono:wght@400;700&display=swap');

:root {
  --paper: #fff8ec;
  --ink: #1d1a2e;
  --sub: #5d5870;
  --line: #e7dcc6;
  --tomato: #ff4d2e;
  --teal: #00a29a;
  --sun: #ffc53d;
  --violet: #6c4bff;
  --sky: #bfe9ff;
  --code-bg: #1d1a2e;
  --code-ink: #f6f1ff;
  --ok: #00a25a;
  --ng: #e0322a;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', system-ui, sans-serif;
  font-weight: 500;
  line-height: 1.8;
}
a { color: var(--violet); }

/* 上の帯 */
.bar { background: var(--ink); color: #fff; }
.bar-in {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { color: #fff; text-decoration: none; font-weight: 900; font-size: 20px; letter-spacing: .02em; }
.brand b { color: var(--sun); }
.brand small {
  margin-left: 8px; font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: var(--tomato); vertical-align: 3px;
}
.stats { display: flex; gap: 10px; }
.stat { background: rgba(255,255,255,.1); padding: 2px 12px; border-radius: 99px; font-size: 14px; }
.stat i { font-style: normal; color: #cfc8e6; margin-right: 6px; font-size: 12px; }
.stat b { font-family: var(--mono); font-size: 16px; color: var(--sun); }

/* 2列 */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 20px 16px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px;
}

/* 店の絵 */
.scene { border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; background: var(--sky); }
.scene svg { display: block; width: 100%; height: auto; }
.sky { fill: var(--sky); }
.sun { fill: var(--sun); }
.neighbor rect { fill: #d9d3c4; stroke: var(--ink); stroke-width: 2; }
.neighbor .shutter { fill: #c4bdac; }
.neighbor text { font-size: 12px; text-anchor: middle; fill: var(--sub); font-weight: 700; }
.wall { fill: #fff; stroke: var(--ink); stroke-width: 3; }
.signboard { fill: var(--ink); }
.sign-text { fill: var(--sun); font-size: 17px; font-weight: 900; text-anchor: middle; }
.sign-text.empty { fill: #8a84a3; font-size: 13px; font-weight: 700; }
.aw-base { fill: #fff; stroke: var(--ink); stroke-width: 2.5; }
.aw-stripe { fill: var(--tomato); }
.window { fill: #e8f7ff; stroke: var(--ink); stroke-width: 2.5; }
.shelf { stroke: var(--ink); stroke-width: 3; }
.door { fill: var(--teal); stroke: var(--ink); stroke-width: 2.5; }
.tag rect { fill: var(--sun); stroke: var(--ink); stroke-width: 1.5; }
.tag text { font-size: 10px; text-anchor: middle; font-weight: 900; fill: var(--ink); }
.register rect { fill: var(--violet); stroke: var(--ink); stroke-width: 2; }
.register text { fill: #fff; font-family: var(--mono); font-size: 11px; text-anchor: middle; font-weight: 700; }
.closed rect { fill: #fff; stroke: var(--tomato); stroke-width: 2; }
.closed text { fill: var(--tomato); font-size: 13px; text-anchor: middle; font-weight: 900; }
.street { fill: #8b8698; }
.nb-window, .nb-door { display: none; }
.neighbor.opened rect:first-child { fill: #fff; }
.neighbor.opened .shutter { display: none; }
.neighbor.opened .nb-window { display: inline; fill: #e8f7ff; }
.neighbor.opened .nb-door { display: inline; fill: var(--sun); }
.neighbor.opened text { fill: var(--ink); font-size: 13px; font-weight: 900; }
#nb1.opened .nb-door { fill: var(--violet); }
.good rect { stroke: var(--ink); stroke-width: 1.5; }
.good text { font-size: 10px; text-anchor: middle; font-weight: 900; fill: var(--ink); }
.sale circle { fill: var(--tomato); stroke: var(--ink); stroke-width: 2.5; }
.sale text { fill: #fff; font-size: 11px; font-weight: 900; text-anchor: middle; }
.sale text.small { font-size: 8px; }
.ledger {
  margin: 0; padding: 6px 14px; background: #fff; border-top: 3px solid var(--ink);
  font-size: 14px; font-weight: 700;
}
.ledger b { color: var(--violet); margin-right: 8px; }
.ledger + .board { border-top: 1px dashed var(--line); }
.board b { color: var(--tomato); }
.lanterns path, .lanterns line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.lanterns ellipse { stroke: var(--ink); stroke-width: 1.5; }
.lanterns .r { fill: var(--tomato); }
.lanterns .w { fill: #fff; }
.stage-list li.chapter { grid-column: 1 / -1; font-weight: 900; font-size: 14px; color: var(--violet); margin-top: 4px; }
.pop { animation: pop .5s ease; transform-box: fill-box; transform-origin: center; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }

/* ステージの説明 */
.card {
  margin-top: 16px; background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 18px 20px;
}
.stage-no { margin: 0; font-family: var(--mono); font-weight: 700; color: var(--tomato); font-size: 13px; letter-spacing: .1em; }
.card h1 { margin: 2px 0 8px; font-size: 26px; font-weight: 900; line-height: 1.4; }
.story { margin: 0 0 12px; color: var(--sub); }
.task { background: #fff3c4; border-radius: 10px; padding: 10px 14px; }
.task b { display: inline-block; background: var(--ink); color: var(--sun); font-size: 12px; padding: 0 10px; border-radius: 99px; }
.task p { margin: 6px 0 0; }
.term { margin-top: 12px; border: 2px solid var(--violet); border-radius: 10px; padding: 8px 14px; }
.term summary {
  cursor: pointer; font-weight: 900; color: var(--violet);
  list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;
}
.term summary::-webkit-details-marker { display: none; }
#term-title { flex: 1 1 12em; }
.tap {
  flex: none; font-size: 12px; font-weight: 700; color: var(--ink);
  background: #efe9ff; border-radius: 99px; padding: 1px 10px;
}
.term[open] .tap-o, .term:not([open]) .tap-c { display: none; }
.term.nudge { animation: nudge 1.8s ease-in-out 4; }
.term.nudge .tap { background: var(--sun); }
@keyframes nudge { 50% { box-shadow: 0 0 0 5px rgba(108,75,255,.25); } }
.term summary::before { content: '📖 '; }
.term p { margin: 8px 0 0; }
code, .inline, .code, .output {
  font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'calt' 0;
}
code, .inline {
  font-family: var(--mono); background: #efe9ff; color: var(--violet);
  padding: 0 5px; border-radius: 4px; font-size: .92em;
}

/* エディタ */
.right { display: flex; flex-direction: column; min-width: 0; }
.editor-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--code-bg); color: #cfc8e6; border-radius: 14px 14px 0 0;
  padding: 8px 14px; font-size: 13px; border: 3px solid var(--ink); border-bottom: 0;
}
.file { font-family: var(--mono); color: var(--sun); }
.py-status.ready { color: #7ef0b0; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 18px; height: 14px; border-radius: 4px; background: var(--sun); }
.editor {
  display: flex; background: var(--code-bg);
  border: 3px solid var(--ink); border-top: 1px solid #3a3550; border-radius: 0 0 14px 14px;
  overflow: hidden;
}
.editor:focus-within { box-shadow: 0 0 0 4px rgba(108,75,255,.35); }
.gutter, .code { font-family: var(--mono); font-size: 16px; line-height: 1.7; }
.gutter {
  margin: 0; padding: 14px 8px 14px 10px; min-width: 3em; text-align: right;
  color: #6f6890; background: #26223b; user-select: none; overflow: hidden;
}
.gutter span { display: block; padding: 0 4px; border-radius: 4px; }
.gutter span.mark { background: var(--sun); color: var(--ink); font-weight: 700; }
.code {
  flex: 1; min-width: 0; min-height: 230px; resize: vertical;
  background: var(--code-bg); color: var(--code-ink); border: 0;
  padding: 14px; white-space: pre; overflow: auto;
  tab-size: 4; outline: none;
}

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.btn {
  font: inherit; font-weight: 900; cursor: pointer; border-radius: 99px;
  padding: 8px 18px; border: 3px solid var(--ink);
}
.btn:disabled { opacity: .45; cursor: wait; }
.btn.run { background: var(--tomato); color: #fff; font-size: 17px; padding: 8px 26px; }
.btn.run:not(:disabled):hover { transform: translateY(-1px); }
.btn.ghost { background: #fff; color: var(--ink); font-size: 14px; }
.btn.next { background: var(--teal); color: #fff; font-size: 17px; align-self: flex-start; margin-top: 12px; }

.out-head { font-size: 13px; font-weight: 700; color: var(--sub); }
.output {
  margin: 4px 0 0; min-height: 64px; background: #fff; border: 2px dashed var(--line);
  border-radius: 10px; padding: 10px 14px; font-family: var(--mono); font-size: 15px;
  white-space: pre-wrap; word-break: break-all;
}
.output .err { color: var(--ng); }
.vpart, .lit { border-radius: 4px; padding: 0 3px; font-weight: 900; }
.vpart { background: #c9f5dc; color: #00744a; }
.lit { background: #ffd9d1; color: #c2261c; }
code .vpart, code .lit { padding: 0 1px; }
.parts-legend { display: block; margin-top: 6px; font-size: 12px; color: var(--sub); }
.trace { margin-top: 10px; background: #fff; border: 2px solid var(--violet); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.trace-head { font-weight: 900; color: var(--violet); }
.trace-lead { margin: 2px 0 8px; font-size: 13px; color: var(--sub); }
.trace table { border-collapse: collapse; width: 100%; font-size: 14px; }
.trace th, .trace td { border-bottom: 1px solid var(--line); padding: 4px 8px; text-align: left; white-space: nowrap; }
.trace thead th { font-size: 12px; color: var(--sub); font-weight: 700; }
.trace tbody th { color: var(--tomato); font-family: var(--mono); font-size: 13px; }
.trace .none { color: #b0a9c4; }
.trace td:last-child { white-space: normal; min-width: 9em; }
.feedback { margin-top: 12px; border-radius: 12px; padding: 12px 16px; border: 3px solid var(--ink); }
.feedback.ok { background: #d9f8e6; }
.feedback.ng { background: #ffe3dd; }
.feedback.hint { background: #efe9ff; }
.hint-step { display: block; margin-top: 8px; padding-top: 8px; border-top: 2px dashed rgba(108,75,255,.3); }
.hint-step:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.hint-step > b { display: block; color: var(--violet); }
.hint-more { display: block; margin-top: 8px; font-size: 13px; color: var(--sub); }
.ans {
  margin: 6px 0; background: var(--code-bg); color: var(--code-ink); border-radius: 8px;
  padding: 8px 12px; font-family: var(--mono); font-size: 14px; white-space: pre; overflow-x: auto;
  font-variant-ligatures: none;
}
.ans .vpart, .ans .lit { padding: 0 1px; }
.feedback b.head { display: block; font-size: 17px; }
.feedback p { margin: 4px 0 0; }

/* 地図 */
.map { max-width: 1180px; margin: 0 auto; padding: 4px 16px 24px; }
.map h2 { font-size: 18px; margin: 0 0 8px; }
.stage-list {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
}
.stage-list li button {
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px;
}
.stage-list li small { display: block; font-family: var(--mono); font-size: 11px; color: var(--sub); }
.stage-list li span { font-weight: 900; }
.stage-list li em { display: block; font-style: normal; font-size: 12px; color: var(--sub); }
.stage-list li.current button { background: var(--sun); }
.stage-list li.done button { border-color: var(--teal); }
.stage-list li.done small::after { content: ' ✔ クリア'; color: var(--teal); font-weight: 700; }
.stage-list li.locked button { opacity: .5; cursor: not-allowed; background: #f1ebdd; }

/* 道具箱 */
.tb-btn {
  font: inherit; font-size: 14px; cursor: pointer; color: #fff;
  background: var(--violet); border: 0; border-radius: 99px; padding: 2px 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tb-btn b { font-family: var(--mono); background: #fff; color: var(--violet); border-radius: 99px; padding: 0 7px; font-size: 13px; }
.tb-btn.pulse { animation: pulse 1s ease 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,197,61,.8); } }
.toolbox {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 3px solid var(--ink); border-radius: 16px; background: var(--paper); color: var(--ink);
}
.toolbox::backdrop { background: rgba(29,26,46,.55); }
.tb-head {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  background: var(--ink); color: #fff; padding: 10px 16px;
}
.tb-head h2 { margin: 0; font-size: 20px; }
.tb-lead { margin: 12px 18px 0; font-size: 14px; color: var(--sub); }
.tb-list { list-style: none; margin: 0; padding: 12px 18px 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tb-list li { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px; }
.tb-list li.locked { background: #f1ebdd; border-style: dashed; color: var(--sub); }
.tb-list li.focus { box-shadow: 0 0 0 4px var(--sun); }
.tb-list h3 { margin: 0 0 6px; font-size: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.tb-term { font-size: 11px; font-weight: 700; color: var(--violet); background: #efe9ff; border-radius: 99px; padding: 0 8px; }
.tb-list p.like { margin-bottom: 4px; color: var(--ink); font-weight: 700; }
.tb-list pre {
  margin: 0 0 6px; background: var(--code-bg); color: var(--code-ink); border-radius: 8px;
  padding: 6px 10px; font-family: var(--mono); font-size: 13px; white-space: pre; overflow-x: auto;
  font-variant-ligatures: none;
}
.tb-list p { margin: 0; font-size: 13px; line-height: 1.7; }
.tb-list small { display: block; margin-top: 6px; font-size: 11px; color: var(--teal); font-weight: 700; }
.got { display: block; margin-top: 8px; padding-top: 8px; border-top: 2px dashed rgba(29,26,46,.25); font-size: 14px; }
.uses { display: block; margin-top: 10px; }
.uses > b { display: block; font-size: 13px; margin-bottom: 4px; }
.use-chip {
  font: inherit; font-size: 13px; cursor: pointer; margin: 0 6px 6px 0;
  background: #fff; border: 2px solid var(--violet); border-radius: 10px; padding: 2px 10px;
}
.use-chip code { background: none; padding: 0; }

.foot { text-align: center; font-size: 12px; color: var(--sub); padding: 16px; border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .gutter, .code { font-size: 15px; }
  .code { min-height: 190px; }
  .card h1 { font-size: 22px; }
  .stats .stat i { display: none; }
  .tb-label { display: none; }
  .stats { gap: 6px; }
  .bar-in { padding: 8px 12px; }
  .brand { font-size: 17px; white-space: nowrap; }
  .brand small { display: none; }
  .stat { padding: 2px 8px; white-space: nowrap; }
  .tb-btn { padding: 2px 8px; white-space: nowrap; }
}
