@font-face {
  font-family: "PangWaPixel";
  src: url("./assets/PangWa.woff2?v=20261201i") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-deep: #1b1528;
  --bg-panel: #28203a;
  --bg-inner: #1e172d;
  --border-col: #473966;
  --don-red: #e8503a;
  --ka-blue: #3ec2de;
  --gold: #ffd24a;
  --text-main: #fcf8f2;
  --text-sub: #bfb3d6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: "PangWaPixel", "Microsoft YaHei", sans-serif;
  font-weight: normal;
  font-synthesis: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1b1528;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
  touch-action: none;
  overscroll-behavior: none;
}

.brand-title,
.top-restart-btn,
.stat-num,
.phase-prompt,
.judge-popup,
.beat-dot,
.modal-title,
.summary-title {
  text-shadow: 0 2px 0 #120d1c;
}

/* Startup Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #1b1528;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.loading-overlay.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  width: 100%;
  max-width: 280px;
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 16px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.loading-title {
  font-size: 26px;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 2px 0 #120d1c;
}

.loading-bar-track {
  width: 100%;
  height: 12px;
  background: #151021;
  border: 2px solid var(--border-col);
  border-radius: 99px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 10%;
  height: 100%;
  background: linear-gradient(90deg, #ff7e5f 0%, #ffd24a 100%);
  transition: width 0.15s ease;
}

.loading-status {
  font-size: 14px;
  color: var(--text-sub);
}

.app-shell {
  width: 100%;
  max-width: 450px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 1. Top Header Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 12px;
  padding: 7px 10px;
  height: 50px;
  flex-shrink: 0;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  image-rendering: pixelated;
  display: block;
}

.brand-title {
  font-size: 22px;
  line-height: 1;
  color: var(--gold);
  letter-spacing: 1px;
  transform: translateY(1px);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.top-restart-btn,
.top-stop-btn {
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 2px solid #161022;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 0 #161022;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.top-restart-btn {
  background: linear-gradient(180deg, #ffd859 0%, #f09c18 100%);
  color: #261600;
  text-shadow: none;
}

.top-stop-btn {
  background: linear-gradient(180deg, #f25f4c 0%, #b8291d 100%);
  color: #fff8f5;
  text-shadow: 0 1px 0 #4d0d08;
}

.top-stop-btn:disabled {
  background: #33294a;
  color: #796b96;
  border-color: #3f335c;
  text-shadow: none;
  box-shadow: none;
  cursor: default;
}

.top-restart-btn:active,
.top-stop-btn:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--bg-inner);
  border: 2px solid var(--border-col);
  color: var(--text-main);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.93);
}

/* 2. Status Strip — 3 pills evenly spread across full width */
.status-strip {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 8px;
  flex-shrink: 0;
}

.stat-pill {
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.stat-label {
  font-size: 14px;
  color: var(--text-sub);
}

.stat-num {
  font-size: 18px;
  color: #fff;
}

.bpm-badge {
  font-size: 15px;
  color: #9beeff;
  background: #1f2d40;
  border: 2px solid #386b88;
  padding: 6px 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.hearts-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.heart-sprite {
  width: 26px;
  height: 28px;
  image-rendering: pixelated;
  display: block;
}

/* 3. Pure Listening Stage Card */
.stage-card {
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 14px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.beat-lamps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.beat-dot {
  height: 28px;
  border-radius: 7px;
  background: var(--bg-inner);
  border: 2px solid var(--border-col);
  font-size: 16px;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s ease, background 0.06s ease;
}

.beat-dot.active-listen {
  background: var(--ka-blue);
  border-color: #c8f6ff;
  color: #0e242c;
  text-shadow: none;
  transform: scale(1.04);
}

.beat-dot.active-countdown {
  background: #ff9f2e;
  border-color: #fff1cf;
  color: #291200;
  text-shadow: none;
  transform: scale(1.08);
}

.beat-dot.active-play {
  background: var(--gold);
  border-color: #fff8d6;
  color: #261800;
  text-shadow: none;
  transform: scale(1.04);
}

.character-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-wrap {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(62, 194, 222, 0.52) 0%, transparent 72%);
  opacity: 0;
  pointer-events: none;
}

.avatar-wrap.speaking .avatar-halo {
  opacity: 1;
}

.char-sprite {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  transition: transform 0.06s ease;
}

.char-sprite.bounce-don {
  transform: scale(1.22) translateY(-3px);
}

.char-sprite.bounce-ka {
  transform: scale(1.22) translateY(-3px);
}

.speech-bubble {
  flex: 1;
  background: var(--bg-inner);
  border: 2px solid var(--border-col);
  border-radius: 11px;
  padding: 7px 13px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.speech-bubble.mode-listen {
  border-color: var(--ka-blue);
}

.speech-bubble.mode-countdown {
  border-color: #ff9f2e;
}

.speech-bubble.mode-play {
  border-color: var(--gold);
}

.phase-prompt-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.clear-crown-icon {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  display: block;
  flex-shrink: 0;
}

.phase-prompt {
  font-size: 22px;
  line-height: 1.05;
  color: var(--gold);
  letter-spacing: 1px;
  white-space: nowrap;
}

.pattern-tag-text {
  font-size: 14px;
  line-height: 1.15;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.speech-bubble.mode-listen .phase-prompt {
  color: #7ee8ff;
}

.speech-bubble.mode-countdown .phase-prompt {
  color: #ffb84d;
}

.speech-bubble.mode-play .phase-prompt {
  color: var(--gold);
}

/* 3 Clear Result Text Styles: 全良(彩虹), 全连(金色), 过关(银色) */
.speech-bubble.mode-clear-ap {
  border-color: #ff8ef0;
}

.speech-bubble.mode-clear-ap .phase-prompt {
  background: linear-gradient(90deg, #ff5f6d 0%, #ffd24a 25%, #3be87a 50%, #4ab8ff 75%, #c77dff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 0 #120d1c);
}

.speech-bubble.mode-clear-fc {
  border-color: #ffd24a;
}

.speech-bubble.mode-clear-fc .phase-prompt {
  color: #ffd84a;
}

.speech-bubble.mode-clear-pass {
  border-color: #b7d5df;
}

.speech-bubble.mode-clear-pass .phase-prompt {
  color: #d4e8ef;
}

/* Judge Feedback Row: Hearts left, Counters right */
.judge-banner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.judge-popup {
  font-size: 16px;
  color: var(--gold);
  min-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.judge-popup.good { color: #ffd447; }
.judge-popup.ok { color: #90f1ef; }
.judge-popup.bad { color: #6c8eff; }

.mini-counters {
  display: flex;
  gap: 10px;
  font-size: 16px;
  white-space: nowrap;
  flex-shrink: 0;
}

.cnt-good { color: #ffd447; }
.cnt-ok { color: #e2ddf0; }
.cnt-bad { color: #6c8eff; }

/* 3.5 Middle Mode Switcher & Static Pixel Score Showcase (outer card border removed, only chart border kept!) */
.hell-mid-card {
  width: 100%;
  flex: 1;
  min-height: 98px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.hell-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  white-space: nowrap;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #151021;
  border: 1.5px solid #35294e;
  border-radius: 8px;
  padding: 2px;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 13px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.mode-pill.active {
  background: linear-gradient(180deg, #ff7e5f 0%, #d93c28 100%);
  color: #fff8f2;
  text-shadow: 0 1px 0 #4d0d08;
}

.hell-streak-text {
  font-size: 13px;
  color: var(--gold);
}

.hell-chart-stage {
  position: relative;
  flex: 1;
  min-height: 66px;
  background: #151021;
  border: 1.5px solid #35294e;
  border-radius: 10px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-listen-mask {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.chart-listen-mask.mask-hidden {
  opacity: 0;
  visibility: hidden;
}

.listen-wave-dot {
  width: 7px;
  height: 7px;
  background: #ff7b59;
  box-shadow: 0 0 8px rgba(255, 123, 89, 0.65);
}

.listen-mask-label {
  font-size: 14px;
  color: #b7a9d4;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 32px);
}

.static-chart-bar {
  position: relative;
  width: 100%;
  height: 58px;
  opacity: 1;
  transition: opacity 0.12s ease;
}

.static-chart-bar.chart-hidden {
  opacity: 0;
  visibility: hidden;
}

/* 8th-note pixel marker dots perched cleanly above the notes */
.chart-dots-row {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  height: 8px;
  pointer-events: none;
}

.eighth-dot {
  position: absolute;
  top: 50%;
  width: 4px;
  height: 4px;
  background: #7c6ba3;
  transform: translate(-50%, -50%);
}

/* Quarter-beat downbeat dots (Beats 1, 2, 3, 4) are slightly brighter/bigger 6x6 pixel squares */
.eighth-dot.quarter-dot {
  width: 6px;
  height: 6px;
  background: var(--gold);
}

.chart-notes-layer {
  position: absolute;
  left: 0;
  right: 0;
  top: 16px;
  height: 36px;
  pointer-events: none;
}

/* Pixel don.png / ka.png centered directly below the 8th-note dots!
   25px icon on ~330px bar (~20.6px per 16th slot) gives just a slight ~4px crisp overlap on 16th runs */
.chart-note-icon {
  position: absolute;
  top: 14px;
  width: 25px;
  height: 25px;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  display: block;
}

/* Per-note post-round hit feedback markers (matching top 8th-note pixel squares: green=good, blue=early, red=late, gray=miss) */
.hit-mark {
  position: absolute;
  top: 32px;
  width: 6px;
  height: 6px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hit-good {
  background: #3be87a;
  box-shadow: 0 0 4px rgba(59, 232, 122, 0.75);
}

.hit-early {
  background: #4ab8ff;
  box-shadow: 0 0 4px rgba(74, 184, 255, 0.75);
}

.hit-late {
  background: #ff4f4f;
  box-shadow: 0 0 4px rgba(255, 79, 79, 0.75);
}

.hit-miss {
  background: #7d748f;
}

/* 4. Interactive Pixel Taiko Drum Arena
      Anchored snugly at the bottom below static-chart-wrap so there's no wasted vertical gap! */
.drum-arena {
  position: relative;
  width: 100%;
  height: 344px;
  flex-shrink: 0;
  background: var(--bg-inner);
  border: 2px solid var(--border-col);
  border-radius: 18px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
}

/* Left & Right independent outer Ka visual feedback panels */
.ka-half {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(50% - 2px);
  pointer-events: auto;
  touch-action: none;
  will-change: opacity;
}

.ka-left {
  left: 0;
  border-radius: 16px 0 0 16px;
}

.ka-right {
  right: 0;
  border-radius: 0 16px 16px 0;
}

.ka-half.active {
  background: rgba(62, 194, 222, 0.20);
  box-shadow: inset 0 0 24px rgba(62, 194, 222, 0.45);
}

/* Clear vertical left/right boundary extending across the outer Ka touch zone (aligning with the center slit of drum_face.png!) */
.arena-center-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  background: #2c2242;
  pointer-events: none;
  z-index: 1;
}

/* Exact 297x297 px = 9x integer multiple of 33x33 native pixel grid, shifted down by ~25% (-74px) for generous upper Ka rim! */
.drum-face-box {
  position: relative;
  width: 297px;
  height: 297px;
  margin-bottom: -74px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.drum-face-img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
}

/* Independent Left & Right Don flash overlays & native touch targets clipped strictly to each half of the pixel drum face */
.face-flash {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: calc(50% - 10px);
  opacity: 0;
  pointer-events: auto;
  touch-action: none;
  will-change: opacity;
}

.left-flash {
  left: 10px;
  border-radius: 150px 0 0 150px;
  background: rgba(255, 255, 255, 0.34);
}

.right-flash {
  right: 10px;
  border-radius: 0 150px 150px 0;
  background: rgba(255, 255, 255, 0.34);
}

.face-flash.active {
  opacity: 1;
}

/* Modals */
.hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 8, 20, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 370px;
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 16px;
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 20px;
  color: var(--gold);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 16px;
}

.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.setting-hint {
  font-size: 13px;
  color: var(--text-sub);
}

.toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.best-record {
  background: var(--bg-inner);
  border: 1.5px solid var(--border-col);
  border-radius: 10px;
  padding: 9px;
  font-size: 15px;
  color: var(--gold);
  text-align: center;
}

.summary-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-badge {
  align-self: center;
  background: #3a2d56;
  border: 2px solid var(--gold);
  color: var(--gold);
  font-size: 16px;
  padding: 4px 14px;
  border-radius: 99px;
}

.summary-title {
  font-size: 26px;
  color: #fff;
}

.summary-sub {
  font-size: 15px;
  color: var(--text-sub);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 4px 0 6px;
}

.sum-box {
  background: var(--bg-inner);
  border: 1.5px solid var(--border-col);
  border-radius: 10px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sum-box span {
  font-size: 14px;
  color: var(--text-sub);
}

.sum-box b {
  font-size: 20px;
  color: var(--gold);
}

.summary-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 9px;
}

.modal-secondary-btn {
  width: 100%;
  height: 44px;
  border-radius: 11px;
  border: 2px solid var(--border-col);
  background: var(--bg-inner);
  color: var(--text-main);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #120d1c;
}

.modal-secondary-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.modal-primary-btn {
  width: 100%;
  height: 44px;
  border-radius: 11px;
  border: 2px solid #161022;
  background: linear-gradient(180deg, #ffd859 0%, #f09c18 100%);
  color: #261600;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #161022;
}

.modal-primary-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

@media (max-height: 760px) {
  /* Startup Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #1b1528;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.loading-overlay.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  width: 100%;
  max-width: 280px;
  background: var(--bg-panel);
  border: 2px solid var(--border-col);
  border-radius: 16px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.loading-title {
  font-size: 26px;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 2px 0 #120d1c;
}

.loading-bar-track {
  width: 100%;
  height: 12px;
  background: #151021;
  border: 2px solid var(--border-col);
  border-radius: 99px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 10%;
  height: 100%;
  background: linear-gradient(90deg, #ff7e5f 0%, #ffd24a 100%);
  transition: width 0.15s ease;
}

.loading-status {
  font-size: 14px;
  color: var(--text-sub);
}

.app-shell { gap: 7px; padding-top: 7px; padding-bottom: 8px; }
  .drum-arena { height: 296px; padding-bottom: 0; }
  .drum-face-box { width: 264px; height: 264px; margin-bottom: -66px; }
}

@media (max-height: 680px) {
  .drum-arena { height: 256px; padding-bottom: 0; }
  .drum-face-box { width: 231px; height: 231px; margin-bottom: -58px; }
}
