*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #0d0d0d;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, a { font-family: inherit; }
button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}
button:focus-visible, a:focus-visible {
  outline: 2px solid #e0a050;
  outline-offset: 2px;
}
#app {
  height: 100%;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #140e0a;
  box-shadow: 0 0 0 1px #2a2118;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
#top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 4px;
  min-height: 52px;
}
#btn-back, #btn-sound {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #241810;
  border: 1px solid #3a2a1e;
  color: #e7d2b4;
  font-size: 18px;
  flex: 0 0 auto;
}
#btn-back { font-size: 16px; text-decoration: none; display: grid; place-items: center; }
#title-block { flex: 1; min-width: 0; }
#kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a8845c;
}
#title {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#geometry {
  margin: 0 12px 6px;
  color: #cbb89a;
  font-size: 12.5px;
  line-height: 1.35;
}
#coach {
  margin: 0 10px 8px;
  background: #24180f;
  border: 1px solid #4a3524;
  border-radius: 14px;
  padding: 10px 12px 8px;
}
#coach p { margin: 0 0 8px; color: #f0e2d0; font-size: 14px; line-height: 1.4; }
.coach-actions { display: flex; justify-content: flex-end; gap: 8px; }
.coach-actions button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  background: #1a120c;
  border: 1px solid #3a2a1e;
  color: #cbb89a;
  font-size: 14px;
}
.coach-actions .primary {
  background: #3a2a18;
  border-color: #e0a050;
  color: #f3ddb8;
  font-weight: 650;
}
#steps {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  list-style: none;
  margin: 0;
  padding: 0 10px 6px;
  scrollbar-width: none;
}
#steps::-webkit-scrollbar { display: none; }
#steps li {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #8d7964;
  border: 1px solid #3a2a1e;
  background: #1c140f;
  border-radius: 999px;
  padding: 5px 9px;
}
#steps li.now { color: #ffe7c2; border-color: #e0a050; background: #2a1c12; }
#steps li.done { color: #b7d7a8; }
#steps li.bad { color: #f0b2aa; border-color: #8a4038; }
#steps li.replay { box-shadow: inset 0 0 0 1px #e74c3c; }
#stage { flex: 1; position: relative; min-height: 120px; }
#section {
  flex: 0 0 auto;
  margin: 0 10px 6px;
  background: #1c140f;
  border: 1px solid #3a2a1e;
  border-radius: 16px;
  overflow: hidden;
}
#section p {
  margin: 0;
  padding: 7px 12px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a8845c;
}
#section canvas {
  width: 100%;
  height: 196px;
  display: block;
  touch-action: none;
  background: #f4efe4;
}
#c { width: 100%; height: 100%; display: block; touch-action: none; }
#menu {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding: 4px 14px 28px;
  background: #140e0a;
}
#menu h2 {
  margin: 4px 0 4px;
  font-size: 28px;
  letter-spacing: -0.04em;
}
.lede { margin: 0 0 16px; color: #b9a48c; font-size: 14px; line-height: 1.45; max-width: 38em; }
.level {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: #1c140f;
  border: 1px solid #3a2a1e;
  border-radius: 16px;
  padding: 8px;
  margin: 0 0 10px;
  color: #fff;
}
.level:active { background: #2a1c14; }
.level canvas {
  width: 78px;
  height: 102px;
  border-radius: 10px;
  background: #2a1a10;
  display: block;
}
.level h3 { margin: 6px 0 2px; font-size: 16px; font-weight: 700; }
.level p { margin: 0; color: #b9a48c; font-size: 13px; line-height: 1.35; }
.level .meta {
  margin-top: 6px;
  font-size: 12px;
  color: #e2b15a;
  letter-spacing: 0.04em;
}
.level .meta span { color: #8d7964; margin-left: 6px; }
.hard-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e7b2ab;
}
#dock {
  padding: 6px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #2a1d14;
  background: #140e0a;
}
#instruction {
  margin: 0 0 2px;
  min-height: 2.5em;
  color: #f0e2d0;
  font-size: 14px;
  line-height: 1.35;
}
#seat-flag {
  margin: 0 0 6px;
  min-height: 1.1em;
  color: #d7b56a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.play-actions { display: flex; gap: 8px; align-items: stretch; }
#btn-restart, #btn-hint, #btn-action, #btn-replay {
  min-height: 52px;
  border-radius: 14px;
  background: #241810;
  border: 1px solid #3a2a1e;
  color: #f0e2d0;
  font-size: 15px;
  font-weight: 750;
}
#btn-restart, #btn-hint { padding: 0 12px; }
#btn-hint .cost { color: #e2b15a; margin-left: 2px; }
#btn-action { flex: 1; }
#btn-action.ready, #btn-next.primary, .result-actions .primary {
  background: #3a2a18;
  border-color: #e0a050;
  color: #ffe7c2;
}
#btn-action:disabled { opacity: 0.35; }
#btn-replay { width: 100%; margin: 0 0 8px; font-size: 14px; }
#result-ui { text-align: center; }
#result-ui h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.03em;
}
#result-stats { margin: 2px 0 4px; color: #e7d2b4; font-size: 14px; }
#replay-note { margin: 0 0 6px; color: #cbb89a; font-size: 13px; line-height: 1.35; }
.stars { display: flex; justify-content: center; gap: 8px; font-size: 32px; line-height: 1; margin: 2px 0; }
.star { color: #3a2e24; }
.star.on { color: #e2b15a; }
#new-best { margin: 0 0 6px; color: #e2b15a; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; min-height: 1em; }
.result-actions { display: flex; gap: 8px; }
.result-actions button {
  flex: 1;
  min-height: 52px;
  border-radius: 14px;
  background: #241810;
  border: 1px solid #3a2a1e;
  color: #f0e2d0;
  font-size: 16px;
  font-weight: 700;
}
.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  .star.on { animation: none; }
}
