:root {
  --ink: #e9fbff;
  --cyan: #39fff0;
  --pink: #ff3df2;
  --green: #3dffc0;
  --red: #ff3355;
  --glass: rgba(8, 10, 28, 0.72);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #05030f;
  color: var(--ink);
  font-family: "Noto Sans KR", sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

body { display: grid; place-items: center; }

button, input { font: inherit; }

#stage {
  position: relative;
  width: min(100vw, calc(100dvh * 720 / 960));
  height: min(100dvh, calc(100vw * 960 / 720));
  margin: auto;
  overflow: hidden;
  background: #07041a;
  box-shadow: 0 0 40px rgba(57, 255, 240, 0.12);
}

#game-root, #ui { position: absolute; inset: 0; }
#ui { pointer-events: none; z-index: 2; }
.screen { pointer-events: auto; }

#game-root canvas { display: block; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  overflow: auto;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 61, 242, 0.18), transparent 32%),
    linear-gradient(180deg, rgba(5, 3, 16, 0.2), rgba(5, 3, 16, 0.78));
}

.hidden { display: none !important; }

.back {
  align-self: flex-start;
  color: white;
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(8, 12, 32, 0.55);
}

.brand { text-align: center; margin-top: 8px; }
.kicker, .hud-k {
  margin: 0;
  letter-spacing: 0.22em;
  font-family: Orbitron, sans-serif;
  font-size: 11px;
  color: var(--cyan);
}
h1 {
  margin: 4px 0;
  font-family: Orbitron, sans-serif;
  font-size: clamp(40px, 10vw, 58px);
  line-height: 0.95;
  background: linear-gradient(180deg, #ffffff, #7dfff6 45%, #ff3df2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(57, 255, 240, 0.45));
}
.tag { margin: 0; font-weight: 700; color: #d7f7ff; }

.glass {
  background: var(--glass);
  border: 1px solid rgba(157, 255, 248, 0.35);
  border-radius: 18px;
  box-shadow: 0 0 24px rgba(57, 255, 240, 0.12), inset 0 0 20px rgba(255, 61, 242, 0.05);
  backdrop-filter: blur(10px);
  padding: 12px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-family: Orbitron, sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #b8fff6;
}

input {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(57, 255, 240, 0.45);
  background: rgba(4, 8, 20, 0.72);
  color: white;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  outline: none;
  user-select: text;
}

input:focus { box-shadow: 0 0 0 3px rgba(57, 255, 240, 0.25); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

button {
  border: 0;
  border-radius: 12px;
  min-height: 46px;
  font-family: Orbitron, "Noto Sans KR", sans-serif;
  font-weight: 800;
  cursor: pointer;
}

#btn-start, #over-retry, .primary {
  color: #04140f;
  background: linear-gradient(180deg, #d9fff4, #3dffc0);
  box-shadow: 0 0 16px rgba(61, 255, 192, 0.45);
}

#btn-rank, #btn-hud-rank, #over-rank-btn, #rank-close, .ghost {
  color: #ffe56a;
  background: rgba(255, 214, 80, 0.08);
  border: 1px solid rgba(255, 214, 80, 0.7);
}

.best {
  margin: 8px 0 0;
  text-align: center;
  font-family: Orbitron, sans-serif;
  color: #ffe56a;
}

.board-preview h2, .how h2, .modal-card h2 {
  margin: 0 0 8px;
  font-family: Orbitron, "Noto Sans KR", sans-serif;
  font-size: 14px;
  letter-spacing: 0.06em;
}

#preview-list { margin: 0; padding-left: 18px; font-weight: 800; }
#preview-list li { margin: 4px 0; }
.how p { margin: 4px 0; font-size: 13px; font-weight: 700; line-height: 1.45; color: #d9f6ff; }

#hud {
  position: absolute;
  left: 10px;
  right: 10px;
  top: calc(8px + env(safe-area-inset-top));
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
#hud button { pointer-events: auto; }

.hud-top {
  display: grid;
  grid-template-columns: 42px 1fr auto 42px 42px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border-radius: 16px;
  background: rgba(6, 10, 24, 0.72);
  border: 1px solid rgba(157, 255, 248, 0.28);
}
#hud-chapter { font-size: 12px; font-weight: 800; color: var(--cyan); }
#hud-name { font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-score { font-family: Orbitron, sans-serif; font-size: 18px; color: white; }
#hud-mult { display: block; text-align: right; color: #ffe56a; font-size: 11px; }
#btn-back, #btn-sound, #btn-hud-rank {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#q-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 8px;
}
#q-card, #status-banner, #hint {
  pointer-events: none;
  text-align: center;
  border-radius: 16px;
  padding: 8px 10px;
  background: rgba(6, 10, 24, 0.94);
  border: 1px solid rgba(157, 255, 248, 0.4);
  box-shadow: 0 0 18px rgba(57, 255, 240, 0.16);
}
#q-card { background: rgba(6, 10, 24, 0.78); padding: 4px 8px; }
#q-prompt { font-weight: 900; font-size: 14px; margin-bottom: 2px; }
.q-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.opt {
  border-radius: 12px;
  padding: 6px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.3;
  word-break: keep-all;
}
.opt b { font-family: Orbitron, sans-serif; display: block; font-size: 12px; }
.opt em { display: block; font-style: normal; opacity: 0.8; font-size: 11px; }
.opt-a { background: rgba(53, 242, 255, 0.14); color: #d8fffd; border: 1px solid rgba(53, 242, 255, 0.7); }
.opt-b { background: rgba(255, 61, 242, 0.12); color: #ffd6fb; border: 1px solid rgba(255, 61, 242, 0.7); }
#hud-combo { min-height: 18px; text-align: center; font-family: Orbitron, sans-serif; color: #ffe56a; text-shadow: 0 0 8px rgba(255, 214, 80, 0.8); }
#status-banner.good { color: #c8ffe9; border-color: rgba(61, 255, 192, 0.8); box-shadow: 0 0 18px rgba(61, 255, 192, 0.35); }
#status-banner.bad { color: #ffd0dc; border-color: rgba(255, 51, 85, 0.9); box-shadow: 0 0 18px rgba(255, 51, 85, 0.4); animation: shake 0.35s linear infinite; }
#hint { font-weight: 800; }

#chapter-card {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  width: min(86%, 420px);
  text-align: center;
  padding: 18px 12px;
  border-radius: 20px;
  background: rgba(6, 8, 22, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 30px rgba(57, 255, 240, 0.35);
}
#chapter-card h2 {
  margin: 4px 0;
  font-family: Orbitron, sans-serif;
  font-size: 34px;
  color: white;
  text-shadow: 0 0 16px rgba(57, 255, 240, 0.8);
}
#ch-sub { margin: 0; font-weight: 800; }

#screen-over, #screen-rank {
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 16, 0.62);
}
.modal-card { width: min(100%, 460px); }
.modal-card h2 { text-align: center; }
#over-score {
  margin: 4px 0;
  text-align: center;
  font-family: Orbitron, sans-serif;
  font-size: 40px;
  color: #ffe56a;
}
#over-name, #over-meta, #over-rank, #rank-note {
  margin: 4px 0 10px;
  text-align: center;
  font-weight: 800;
  line-height: 1.45;
}
.actions { display: grid; gap: 8px; margin-top: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  font-family: Orbitron, sans-serif;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: #8ef6e4;
  text-align: left;
  padding: 4px;
}
td { padding: 5px 4px; border-top: 1px solid rgba(57, 255, 240, 0.16); font-weight: 700; }
tr.me td { color: #ffe56a; }
.table-wrap { overflow-x: auto; }

#boot-error { color: #ffb4c0; font-weight: 800; }

@keyframes shake {
  50% { transform: translateX(2px); }
}

@media (prefers-reduced-motion: reduce) {
  #status-banner.bad { animation: none; }
}
