@font-face {
  font-family: 'PixelCJK';
  src: url('img/zpix.ttf') format('truetype');
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #3a1220;
  color: #eaf1ff;
  font-family: 'PixelCJK', "Fixedsys", "Courier New", monospace;
  user-select: none; -webkit-user-select: none;
}

#fade-overlay {
  position: fixed; inset: 0;
  background: #3a1220;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#fade-overlay.on { opacity: 1; }

#corner-label {
  position: fixed;
  left: 8px; top: calc(8px + env(safe-area-inset-top));
  z-index: 40;
  font-family: 'PixelCJK', "Fixedsys", monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: rgba(255,255,255,.6);
  pointer-events: none;
}

.mute-btn {
  position: fixed;
  right: 12px; top: calc(10px + env(safe-area-inset-top));
  z-index: 40;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.4);
  background: rgba(88,22,48,.6);
  color: #fff;
  font-family: 'PixelCJK', "Fixedsys", monospace;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-btn.muted { color: #f44552; border-color: rgba(255,107,107,.6); }
.mute-btn.muted::after {
  content: '';
  position: absolute;
  width: 24px; height: 2px;
  background: #f44552;
  transform: rotate(-45deg);
}

canvas#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  display: block;
  z-index: 2;
}

.screen {
  position: fixed; inset: 0;
  display: none;
  z-index: 10;
  overflow: hidden;
}
.screen.active { display: block; }
.hidden { display: none !important; }

#screen-game { pointer-events: none; }

#bgVideo {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #000;
  display: none;
  pointer-events: none;
}

#launchVideo {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 3;
  background: #000;
  display: none;
  pointer-events: none;
}

.skip-hint {
  position: fixed;
  left: 50%; bottom: 26%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 18px;
  border-radius: 20px;
  background: rgba(88,22,48,.55);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
}

.launch-caption {
  position: fixed;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  text-align: center;
  pointer-events: none;
}
.launch-caption p {
  color: #ffffff;
  font-size: 17px; font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0,0,0,.95), 0 0 4px rgba(0,0,0,.8);
  margin: 5px 0;
  opacity: 0;
  animation: capFade 0.6s ease forwards;
}
.launch-caption p:nth-child(2) { animation-delay: 0.3s; }
@keyframes capFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- buttons ---------- */
.btn {
  width: 100%;
  padding: 14px 18px;
  border: none; border-radius: 14px;
  font-size: 17px; font-weight: 600;
  cursor: pointer;
  margin: 8px 0;
}
.btn-primary {
  background: linear-gradient(135deg, #e8364c, #b0203a);
  color: #fff;
  box-shadow: 0 6px 20px rgba(47,123,255,.35);
}
.btn-primary:active { transform: scale(.97); }
.btn-ghost {
  background: rgba(255,255,255,.08);
  color: #dbe6ff;
  border: 1px solid rgba(255,255,255,.18);
}

/* ---------- splash ---------- */
#screen-splash {
  background: #000 url('img/enter.png') center/cover no-repeat;
}
#screen-splash.active { display: block; }
.btn-start {
  position: absolute;
  left: 23.5%; right: 24%;
  bottom: 10%; height: 4.3%;
  background: transparent;
  border: none;
  cursor: pointer;
}
.btn-howto {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(88,22,48,.55);
  color: #fff; font-size: 18px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- config ---------- */
#screen-config { flex-direction: column; background: #000 url('img/start.jpg') center/cover no-repeat; }
#screen-config.active { display: flex; }
.btn-back {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  background: rgba(88,22,48,.55);
  color: #dbe6ff; border: 1px solid rgba(255,255,255,.3);
  padding: 8px 14px; border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
}
.btn-start-task {
  position: absolute;
  left: 70%; right: 2%;
  bottom: 7.5%; height: 3.5%;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 2;
}
.head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px calc(10px + env(safe-area-inset-top));
  background: rgba(88,22,48,.9);
  border-bottom: 1px solid rgba(120,160,255,.15);
}
.btn-back {
  background: rgba(255,255,255,.08);
  color: #dbe6ff; border: none;
  padding: 8px 14px; border-radius: 10px;
  font-size: 14px;
}
.head-title { font-size: 18px; font-weight: 700; letter-spacing: 2px; }

.cfg-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
}
.cfg-group { margin-bottom: 18px; }
.cfg-title { font-size: 15px; font-weight: 700; color: #9db8ff; margin-bottom: 10px; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.cards-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.part-card {
  background: rgba(96,24,52,.82);
  border: 1.5px solid rgba(120,160,255,.18);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all .15s;
}
.cards-2 .part-card { display: flex; flex-direction: column; }
.part-card .pc-head { display: flex; align-items: center; gap: 10px; }
.pc-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  flex: none;
}
.pc-name { font-size: 15px; font-weight: 700; color: #fff; }
.pc-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px; color: #7fc0ff;
  background: rgba(47,123,255,.18);
  padding: 2px 8px; border-radius: 20px;
  align-self: flex-start;
}
.pc-desc { font-size: 12px; color: #b9c6ea; margin: 8px 2px 0; line-height: 1.5; }
.part-card.sel {
  border-color: #4f8bff;
  background: rgba(47,123,255,.14);
  box-shadow: 0 0 0 3px rgba(47,123,255,.22), 0 4px 18px rgba(47,123,255,.2);
}
.part-card.sel .pc-dot { background: #4f8bff; border-color: #9ec1ff; }

.cfg-summary {
  background: rgba(96,24,52,.82);
  border: 1px solid rgba(120,160,255,.2);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 8px;
}
.cfg-summary .s-title { font-size: 13px; color: #9db8ff; margin-bottom: 8px; font-weight: 600; }
.s-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: #c9d6ff; }
.s-row b { color: #fff; }

.cfg-footer {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(88,22,48,.92);
  border-top: 1px solid rgba(120,160,255,.15);
}
.btn-launch { margin: 0; }

/* ---------- game overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(64,12,32,.55);
  pointer-events: none;
}
.overlay-box {
  text-align: center;
  padding: 22px 28px;
  border-radius: 18px;
  background: rgba(88,22,48,.9);
  border: 1px solid rgba(120,160,255,.3);
}
.overlay-box h3 { font-size: 22px; color: #fff; margin-bottom: 8px; }
.overlay-box p { font-size: 14px; color: #b9c6ea; }

/* ---------- result ---------- */
#screen-result { flex-direction: column; background: #3a1220; }
#screen-result.active { display: flex; }
#screen-result::before {
  content: '';
  position: fixed; inset: 0;
  background: #3a1220 url('img/endgame.png') center/cover no-repeat;
  opacity: 0.6;
  z-index: 0;
  pointer-events: none;
}
.result-video { display: none; }
.result-scroll {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 1;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(30px + env(safe-area-inset-bottom));
}
.finish-card {
  background: rgba(106,26,56,.55);
  border: 1px solid rgba(120,160,255,.3);
  border-radius: 20px;
  padding: 18px 18px 16px;
  margin-bottom: 12px;
  text-align: center;
  backdrop-filter: blur(4px);
}
.fin-rocket {
  display: block;
  margin: 0 auto;
  height: 140px;
  width: auto;
}
.fin-sub {
  font-size: 20px; font-weight: 800; letter-spacing: 2px;
  color: #ffffff;
  margin: 10px 0 4px;
}
.fin-rating {
  font-size: 58px; font-weight: 900;
  line-height: 1.1;
  color: #ffffff;
  text-shadow: 0 0 18px rgba(255,255,255,.95), 0 0 42px rgba(255,255,255,.55);
  margin: 4px 0 2px;
}
.fin-prec {
  font-size: 13px;
  color: #c3d2ff;
  margin-bottom: 6px;
}
.fin-score {
  margin: 6px 0 4px;
  font-size: 62px; font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, #f44552, #d72b3b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.fin-score-unit { font-size: 20px; font-weight: 700; margin-left: 4px; }
.res-detail {
  background: rgba(116,28,60,.55);
  border: 1px solid rgba(120,160,255,.2);
  border-radius: 14px;
  padding: 12px 16px;
  margin: 10px 0 4px;
  text-align: left;
}
.d-row { display: flex; justify-content: space-between; font-size: 14px; padding: 5px 0; color: #c9d6ff; }
.d-row b { color: #fff; }
.d-row.d-offset {
  margin: 4px -8px;
  padding: 9px 8px;
  border-radius: 10px;
  background: rgba(255,209,102,0.12);
  border: 1px solid rgba(255,209,102,0.35);
}
.d-row.d-offset span { color: #ffd166; font-weight: 700; }
.d-row.d-offset b { color: #ffd166; font-size: 16px; }
.d-row.ok { color: #7dffb0; }
.d-row.bad { color: #ff8a8a; }

.res-name { display: flex; align-items: center; gap: 10px; margin-top: 10px; text-align: left; }
.res-name label { font-size: 13px; color: #9db8ff; }
.res-name input {
  flex: 1;
  background: rgba(116,28,60,.9);
  border: 1px solid rgba(120,160,255,.3);
  color: #fff;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 15px;
  outline: none;
}

.res-btns { display: flex; gap: 10px; margin: 4px 0 10px; }
.res-btns .btn { flex: 1; margin: 0; }

.lb-title { margin: 14px 0 10px; font-size: 16px; color: #9db8ff; }
.lb { background: rgba(116,28,60,.9); border-radius: 14px; overflow: hidden; border: 1px solid rgba(120,160,255,.15); }
.lb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid rgba(120,160,255,.08);
}
.lb-item:last-child { border-bottom: none; }
.lb-rank { width: 26px; text-align: center; font-weight: 800; color: #8fa3d9; }
.lb-rank.top { color: #ffd166; }
.lb-name { flex: 1; color: #eaf1ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-rating {
  font-size: 11px; font-weight: 800;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255,255,255,.8);
  padding: 1px 6px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 8px;
}
.lb-score { font-weight: 800; color: #fff; }
.lb-meta { font-size: 11px; color: #6c7ba6; width: 110px; text-align: right; }
.lb-empty { padding: 20px; text-align: center; color: #6c7ba6; font-size: 13px; }
.lb-loading { padding: 16px; text-align: center; color: #9db8ff; font-size: 13px; }

.credit-logos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  margin-top: 18px;
}
.credit-logo {
  height: 34px;
  width: auto;
  opacity: 0.5;
}
.credit-music {
  text-align: center;
  font-size: 10px;
  color: #6c7ba6;
  margin: 10px 0 4px;
  letter-spacing: 1px;
}

/* ---------- howto ---------- */
.howto { align-items: center; justify-content: center; }
.howto.active { display: flex; }
.howto-box {
  width: 90%; max-width: 440px;
  background: rgba(106,26,56,.94);
  border: 1px solid rgba(120,160,255,.25);
  border-radius: 20px;
  padding: 24px;
  overflow-y: auto;
  max-height: 90%;
}
.howto-box h3 { font-size: 20px; margin-bottom: 14px; }
.howto-box p { font-size: 14px; color: #c3d2ff; line-height: 1.7; margin-bottom: 12px; }
.howto-box b { color: #fff; }
