@import url("https://fonts.googleapis.com/css2?family=Black+Han+Sans&family=Noto+Sans+SC:wght@500;700;900&display=swap");

:root {
  --ink: #17140f;
  --paper: #f2e8cf;
  --cream: #fff8e8;
  --red: #e7472e;
  --yellow: #f4c542;
  --green: #3d8062;
  --blue: #265b6d;
  --road: #353638;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 20, 15, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 20, 15, .045) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-weight: 700;
}

button, input { font: inherit; }
button { color: inherit; }

.cabinet {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 22px 28px;
}

.marquee {
  min-height: 86px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  border-bottom: 4px solid var(--ink);
}

.back {
  color: var(--ink);
  text-decoration: none;
  justify-self: start;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  background: var(--cream);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-1deg);
}

.back:hover { transform: translate(2px, 2px) rotate(-1deg); box-shadow: 1px 1px 0 var(--ink); }

.title-wrap { text-align: center; line-height: 1; }
.kicker { display: block; margin-bottom: 3px; color: var(--red); font-size: 11px; letter-spacing: .28em; }

h1 {
  margin: 0;
  font-family: "Black Han Sans", "Noto Sans SC", sans-serif;
  font-size: clamp(28px, 5vw, 50px);
  font-weight: 900;
  letter-spacing: -.04em;
}

.header-actions { justify-self: end; display: flex; gap: 8px; }
.icon-btn {
  border: 2px solid var(--ink);
  background: transparent;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
}
.icon-btn:hover { background: var(--yellow); }

.scoreboard {
  display: grid;
  grid-template-columns: 1.5fr .75fr .65fr 1.1fr;
  border: 4px solid var(--ink);
  border-bottom: 0;
  margin-top: 18px;
  background: var(--cream);
}

.score-cell {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  padding: 9px 16px;
  border-right: 3px solid var(--ink);
  text-transform: uppercase;
}
.score-cell:last-child { border-right: 0; }
.score-cell span { font-size: 11px; letter-spacing: .14em; color: #716b5d; }
.score-cell strong { font-family: "Black Han Sans", monospace; font-size: 25px; line-height: 1; }
.main-score strong { color: var(--red); letter-spacing: .06em; }

.life { display: flex; gap: 5px; }
.life i {
  width: 25px;
  height: 12px;
  display: block;
  border: 2px solid var(--ink);
  background: var(--red);
  transform: skew(-12deg);
}
.life i.empty { background: #c9c0aa; }

.game-shell {
  position: relative;
  border: 4px solid var(--ink);
  background: #82a9aa;
  overflow: hidden;
  isolation: isolate;
  min-height: 620px;
}

#game { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; background: #83a8a8; }

.game-shell.shake { animation: cabinet-shake .28s steps(2); }
.game-shell.impact::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: var(--cream);
  animation: impact-flash .24s steps(2) both;
}

@keyframes cabinet-shake {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(-9px, 4px) rotate(-.35deg); }
  40% { transform: translate(8px, -5px) rotate(.3deg); }
  65% { transform: translate(-5px, -2px); }
  85% { transform: translate(4px, 3px); }
}
@keyframes impact-flash { 0% { opacity: .9; } 45%, 100% { opacity: 0; } }

.panel {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%) rotate(-.35deg);
  width: min(530px, calc(100% - 34px));
  padding: 26px 32px 22px;
  border: 4px solid var(--ink);
  background: var(--cream);
  box-shadow: 9px 9px 0 rgba(23, 20, 15, .8);
}
.panel[hidden] { display: none; }

.menu-panel { display: grid; grid-template-columns: 1fr 1.15fr; gap: 14px 24px; }
.stamp {
  position: absolute;
  right: 18px;
  top: 15px;
  border: 3px double var(--red);
  color: var(--red);
  padding: 5px 10px;
  font-size: 10px;
  text-align: center;
  transform: rotate(7deg);
  opacity: .82;
}
.warning { grid-column: 1 / -1; margin: 0; font-size: 22px; line-height: 1.35; }
.warning b { color: var(--red); font-size: 26px; }

.howto { display: grid; gap: 8px; align-content: center; }
.howto div { display: flex; align-items: center; gap: 5px; font-size: 12px; }
.howto span { margin-left: 4px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 3px 0 var(--ink);
  font-family: inherit;
}

.difficulty { margin: 0; padding: 5px 8px 7px; border: 2px solid var(--ink); }
.difficulty legend { font-size: 11px; padding: 0 5px; letter-spacing: .1em; }
.difficulty label { display: block; cursor: pointer; }
.difficulty input { position: absolute; opacity: 0; }
.difficulty label span { display: flex; justify-content: space-between; gap: 8px; padding: 5px 7px; border-left: 6px solid transparent; }
.difficulty label b { font-size: 12px; }
.difficulty label small { color: #746e62; font-size: 10px; align-self: center; }
.difficulty input:checked + span { border-left-color: var(--red); background: var(--yellow); }

.start-btn {
  grid-column: 1 / -1;
  border: 3px solid var(--ink);
  background: var(--red);
  color: #fff;
  padding: 13px 20px;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
  font-size: 17px;
  font-weight: 900;
}
.start-btn span { float: right; }
.start-btn:hover { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.tip { grid-column: 1 / -1; margin: -2px 0 0; text-align: center; color: #746e62; font-size: 10px; }

.count-in {
  position: absolute;
  z-index: 7;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  font-family: "Black Han Sans", sans-serif;
  font-size: clamp(80px, 16vw, 180px);
  color: var(--yellow);
  -webkit-text-stroke: 5px var(--ink);
  text-shadow: 8px 8px 0 var(--red);
  pointer-events: none;
}

.judge {
  position: absolute;
  z-index: 6;
  left: 50%; top: 30%;
  transform: translate(-50%, -50%) rotate(-4deg);
  color: var(--cream);
  font-family: "Black Han Sans", sans-serif;
  font-size: clamp(27px, 5vw, 55px);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 4px 4px 0 var(--red);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.judge.show { animation: judge-pop .48s cubic-bezier(.2, 1.4, .4, 1) both; }
.judge.bad { color: var(--red); text-shadow: 4px 4px 0 var(--ink); }
@keyframes judge-pop { 0% { opacity: 0; transform: translate(-50%, -35%) scale(.55) rotate(-7deg); } 25%, 72% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -65%) scale(1.08) rotate(-2deg); } }

.beat-rail {
  position: absolute;
  z-index: 5;
  left: 18px;
  right: 18px;
  bottom: 84px;
  height: 30px;
  border: 2px solid var(--ink);
  background: rgba(255, 248, 232, .86);
  overflow: hidden;
  pointer-events: none;
}
.beat-label { position: absolute; left: 8px; top: 5px; font-size: 9px; letter-spacing: .12em; }
.hit-mark { position: absolute; left: 50%; top: -2px; width: 4px; height: 32px; background: var(--red); transform: translateX(-50%); }
.beat-dots { position: absolute; inset: 0; }
.beat-dots i { position: absolute; top: 8px; width: 11px; height: 11px; border: 2px solid var(--ink); background: var(--yellow); transform: translateX(-50%) rotate(45deg); }
.beat-dots i.major { width: 15px; height: 15px; top: 6px; background: var(--red); }

.touch-controls {
  position: absolute;
  z-index: 6;
  left: 50%; bottom: 13px;
  transform: translateX(-50%);
  display: flex;
  gap: 9px;
}
.touch-controls button {
  width: 78px; height: 57px;
  display: grid; place-content: center;
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.touch-controls button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.touch-controls .brake { background: var(--yellow); color: var(--red); }
.touch-controls small { display: block; font-size: 8px; color: var(--ink); }

.small-panel, .result-panel { text-align: center; width: min(430px, calc(100% - 34px)); }
.panel-label { color: var(--red); font-size: 11px; letter-spacing: .15em; }
.small-panel h2, .result-panel h2 { margin: 5px 0 18px; font: 900 38px/1 "Black Han Sans", sans-serif; }
.small-panel .start-btn, .result-panel .start-btn { width: 100%; }
.text-btn { display: inline-block; margin-top: 16px; border: 0; background: transparent; text-decoration: underline; cursor: pointer; }
.result-score { margin-bottom: 14px; padding: 12px; border-block: 3px solid var(--ink); }
.result-score span { display: block; color: #746e62; font-size: 10px; letter-spacing: .14em; }
.result-score strong { color: var(--red); font: 900 46px/1 "Black Han Sans", sans-serif; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.result-grid div { padding: 8px 3px; background: #e9dec3; }
.result-grid strong, .result-grid span { display: block; }
.result-grid strong { font-size: 22px; }
.result-grid span { color: #746e62; font-size: 9px; }
.best-score { min-height: 18px; color: var(--green); font-size: 11px; }

.road-note {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 4px solid var(--ink);
  font-size: 11px;
}
.road-note p { margin: 0; }
.high-score { white-space: nowrap; color: var(--red); }

@media (max-width: 720px) {
  .cabinet { padding: 10px 10px 20px; }
  .marquee { grid-template-columns: auto 1fr; min-height: 68px; }
  .title-wrap { text-align: right; }
  .header-actions { grid-column: 1 / -1; justify-self: stretch; justify-content: flex-end; margin-top: -10px; }
  .scoreboard { grid-template-columns: 1fr 1fr 1fr; }
  .score-cell { padding: 8px 5px; gap: 6px; }
  .score-cell strong { font-size: 19px; }
  .life-cell { grid-column: 1 / -1; border-top: 3px solid var(--ink); justify-content: center; }
  .game-shell { min-height: 565px; }
  #game { height: 565px; aspect-ratio: auto; object-fit: cover; }
  .menu-panel { grid-template-columns: 1fr; padding: 22px 22px 18px; }
  .warning { padding-right: 50px; font-size: 18px; }
  .warning b { font-size: 21px; }
  .howto { grid-template-columns: repeat(3, 1fr); }
  .howto div { flex-wrap: wrap; align-content: start; }
  .howto span { width: 100%; margin: 2px 0 0; }
  .stamp { right: 10px; top: 10px; }
  .touch-controls button { width: 72px; }
  .road-note { align-items: flex-start; }
}

@media (max-width: 430px) {
  .back { font-size: 0; }
  .back::after { content: "←"; font-size: 18px; }
  .score-cell span { display: none; }
  .menu-panel { top: 47%; }
  .beat-rail { left: 8px; right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .game-shell.shake, .game-shell.impact::after, .judge.show { animation-duration: .01ms; }
}
