:root {
  --bg: #14261b; --bg2: #1b3324; --panel: #233f2d; --line: rgba(255,255,255,0.12);
  --text: #f1f5ea; --dim: #a9bba9; --accent: #ffd34d; --go: #43d17a; --stop: #ff6b5f;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #22432f, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
}
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line); color: var(--text);
  text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.back-btn:hover { background: rgba(255,255,255,0.15); }
.total { margin-left: auto; font-weight: 700; }
.total small { color: var(--dim); font-weight: 500; }
.tools { display: flex; gap: 6px; }
.mini {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255,255,255,0.08); font-weight: 700;
}

.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 6px 0 14px; }
.logo-train { font-size: 3rem; animation: chug 1.4s ease-in-out infinite; display: inline-block; }
@keyframes chug { 0%,100% { transform: translateX(-6px); } 50% { transform: translateX(6px) translateY(-2px); } }
.logo h1 { margin: 2px 0 4px; font-size: 1.6rem; letter-spacing: -0.5px; }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }

.chapters { max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }
.chapter { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.chapter h2 { margin: 0 0 2px; font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.chapter h2 small { margin-left: auto; color: var(--accent); font-size: 0.85rem; }
.chapter p { margin: 0 0 10px; color: var(--dim); font-size: 0.82rem; }
.lv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .lv-grid { grid-template-columns: repeat(6, 1fr); } }
.lv-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 74px;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.lv-btn b { font-size: 1rem; }
.lv-btn span { font-size: 0.7rem; color: var(--dim); text-align: center; line-height: 1.2; }
.lv-btn i { font-style: normal; font-size: 0.75rem; letter-spacing: 1px; color: var(--accent); }
.lv-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.lv-btn.cleared { background: #2b5139; }

#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.p-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.p-title { font-size: 1rem; }
.p-title b { color: var(--accent); }
.p-info { margin-left: auto; font-size: 0.8rem; color: var(--dim); }
.p-info b { color: var(--text); }
.hint { margin: 6px 0; font-size: 0.82rem; color: #d7e6d2; background: rgba(255,255,255,0.06); border-radius: 10px; padding: 6px 10px; line-height: 1.4; }
.board { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
#board { touch-action: none; display: block; cursor: crosshair; }
.msg {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(30,12,12,0.92); border: 1px solid var(--stop); color: #ffd9d4;
  padding: 8px 14px; border-radius: 12px; font-size: 0.88rem; text-align: center; max-width: 92%;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.msg.ok { background: rgba(14,40,24,0.92); border-color: var(--go); color: #d8ffe6; }

.toolbar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; padding-top: 8px; }
.tool {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 1.15rem; min-height: 52px;
}
.tool span { font-size: 0.68rem; color: var(--dim); }
.tool.on { border-color: var(--accent); background: #3a5a2e; }
.tool.go { background: #1f6b3d; border-color: var(--go); }
.tool.go span { color: #d8ffe6; }
.tool.go.stop { background: #6b231f; border-color: var(--stop); }
.tool:disabled { opacity: 0.4; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 16px; font-weight: 700;
}
.btn.small { padding: 6px 10px; font-size: 0.82rem; }
.btn.primary { background: #1f6b3d; border-color: var(--go); }
.btn:hover { filter: brightness(1.15); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; max-width: 440px; width: 100%; max-height: 90vh; overflow-y: auto; }
.panel h2 { margin: 0 0 10px; }
.panel p, .panel li { color: #dbe7d6; font-size: 0.9rem; line-height: 1.55; }
.panel ul { padding-left: 18px; margin: 6px 0; }
.panel .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.result { text-align: center; }
.stars { font-size: 2.4rem; letter-spacing: 6px; margin: 4px 0; }
.stars .off { filter: grayscale(1); opacity: 0.3; }
.err h2 { color: var(--stop); }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 420px) {
  .back-txt { display: none; }
  .hint { font-size: 0.76rem; }
}
