:root {
  --bg: #1b0f0f;
  --panel: rgba(255, 247, 226, 0.96);
  --ink: #2a1713;
  --muted: #6d554b;
  --red: #e23b34;
  --blue: #2387e0;
  --gold: #ffd166;
  --orange: #f77f00;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 209, 102, .36), transparent 22rem),
    radial-gradient(circle at 80% 10%, rgba(226, 59, 52, .32), transparent 25rem),
    linear-gradient(135deg, #2b1111 0%, #1b0f0f 52%, #371409 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.035) 25%, transparent 25%);
  background-size: 42px 42px;
  pointer-events: none;
}

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 18px 14px 26px;
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff7e2;
  padding: 14px 4px 18px;
}

.logo-mark {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 40px;
  background: linear-gradient(135deg, var(--red), var(--orange));
  box-shadow: 0 10px 28px rgba(0,0,0,.35), inset 0 0 0 5px rgba(255,255,255,.22);
}

.eyebrow {
  margin: 0 0 2px;
  color: #ffdca2;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 56px);
  line-height: 1;
  letter-spacing: .04em;
  text-shadow: 0 4px 0 rgba(0,0,0,.25);
}

.subtitle {
  margin: 8px 0 0;
  color: #ffe9be;
  font-weight: 700;
}

.panel {
  background: var(--panel);
  border: 4px solid #ffdf88;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(16px, 4vw, 26px);
}

.hidden { display: none !important; }

.start-panel h2,
.result-panel h2 {
  margin: 0 0 14px;
  font-size: 28px;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  appearance: none;
  border: 3px solid #f0b547;
  border-radius: 16px;
  padding: 13px 14px;
  color: var(--ink);
  background: #fff8e6;
  font-size: 17px;
  font-weight: 900;
}

.howto {
  background: #fff8e6;
  border: 2px dashed #e9a830;
  border-radius: 20px;
  padding: 12px 14px;
  margin: 16px 0;
}

.howto h3 { margin: 0 0 8px; }
.howto p { margin: 7px 0; line-height: 1.65; }
.howto strong:first-of-type { color: var(--red); }
.howto strong:nth-of-type(2) { color: var(--blue); }

kbd {
  display: inline-block;
  min-width: 1.8em;
  text-align: center;
  padding: 2px 6px;
  border-radius: 7px;
  background: #33201a;
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(255,255,255,.16);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

button {
  user-select: none;
  -webkit-user-select: none;
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 1000;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:active { transform: translateY(2px) scale(.99); }

.primary {
  color: #2a1208;
  background: linear-gradient(180deg, #ffe17a, #ff9f1c);
  box-shadow: 0 8px 0 #a5480f, 0 16px 20px rgba(0,0,0,.18);
}

.secondary {
  color: #fff8e6;
  background: linear-gradient(180deg, #5b3731, #2c1714);
  box-shadow: 0 8px 0 #120908, 0 16px 20px rgba(0,0,0,.14);
}

.small {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 14px;
  box-shadow: none;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.stat {
  background: #fff8e6;
  border: 2px solid #f5cb66;
  border-radius: 16px;
  padding: 10px 12px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.stat strong {
  display: block;
  font-size: clamp(22px, 5vw, 34px);
  line-height: 1.1;
}

.lane-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  background: linear-gradient(180deg, #593126, #2d1715);
  border: 5px solid #ffc857;
  box-shadow: inset 0 0 0 5px rgba(0,0,0,.2);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: clamp(240px, 44svh, 380px);
  max-height: none;
  touch-action: none;
}

.judge-text {
  position: absolute;
  left: 50%;
  top: 32%;
  transform: translate(-50%, -50%);
  font-size: clamp(28px, 8vw, 66px);
  font-weight: 1000;
  color: #fff;
  text-shadow: 0 5px 0 rgba(0,0,0,.35), 0 0 24px rgba(255, 209, 102, .9);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 5;
  opacity: 0;
}


.judge-text.show {
  animation: popJudge .45s ease-out;
}

@keyframes popJudge {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.65); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

.drum-area {
  display: grid;
  grid-template-columns: 1fr 1fr 150px 1fr 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.hit-btn {
  position: relative;
  z-index: 10;
  min-height: 86px;
  color: #fff;
  font-size: clamp(24px, 6.5vw, 34px);
  border: 4px solid rgba(255,255,255,.45);
  box-shadow: 0 8px 0 rgba(0,0,0,.35);
}

.hit-btn.don { background: linear-gradient(180deg, #ff695f, #d52e2b); }
.hit-btn.ka { background: linear-gradient(180deg, #52a8ff, #1465c4); }

.hit-btn.hitflash {
  filter: brightness(1.3);
  transform: translateY(3px) scale(.98);
}

.drum-face {
  width: 150px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fff2cf 0 48%, #d84f40 49% 65%, #4b2520 66% 100%);
  display: grid;
  place-items: center;
  color: #5a1c15;
  font-weight: 1000;
  border: 6px solid #2d1715;
  box-shadow: 0 10px 0 rgba(0,0,0,.3), inset 0 0 0 5px rgba(255,255,255,.26);
}

.drum-inner {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.62);
  border: 3px solid rgba(88,34,27,.2);
}

.result-panel { text-align: center; }
.rank {
  width: 130px;
  height: 130px;
  margin: 8px auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #2a1208;
  font-size: 66px;
  font-weight: 1000;
  background: linear-gradient(180deg, #fff4a8, #ffb703);
  border: 6px solid #bf5c00;
  box-shadow: 0 12px 0 rgba(0,0,0,.25);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  text-align: left;
}

.result-grid div {
  border-radius: 18px;
  background: #fff8e6;
  border: 2px solid #f2ca68;
  padding: 12px;
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.result-grid strong {
  font-size: 26px;
}

footer {
  color: #ffe9be;
  text-align: center;
  font-size: 13px;
  margin-top: 16px;
}

@media (max-width: 760px) {
  .app { padding: 8px 8px 18px; }
  .hero { align-items: flex-start; padding: 8px 2px 10px; }
  .logo-mark { width: 52px; height: 52px; font-size: 29px; flex: 0 0 auto; }
  .subtitle { font-size: 13px; }
  .panel { padding: 12px; border-width: 3px; }
  .setting-grid { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
  .topbar .small { grid-column: 1 / -1; min-height: 38px; }
  .lane-wrap { border-width: 4px; border-radius: 22px; }
  #gameCanvas { height: clamp(270px, 48svh, 420px); }
  .judge-text { top: 24%; font-size: clamp(36px, 12vw, 74px); }
  .drum-area {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 12px;
  }
  .drum-face { display: none; }
  .hit-btn {
  position: relative;
  z-index: 10;
    min-height: clamp(92px, 18svh, 132px);
    padding-inline: 4px;
    font-size: clamp(30px, 9vw, 44px);
  }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
  .app { padding-inline: 6px; }
  .panel { border-radius: 20px; }
  .stat { padding: 7px 5px; }
  .stat span { font-size: 10px; }
  .stat strong { font-size: 22px; }
  #gameCanvas { height: clamp(285px, 50svh, 430px); }
  .result-grid { grid-template-columns: 1fr; }
}
