:root {
  --ink: #e8f4ff;
  --ink-dim: #8fb4d4;
  --cyan: #3de8ff;
  --gold: #ffd56a;
  --danger: #ff6b8a;
  --ok: #5dffb0;
  --panel: rgba(8, 28, 48, 0.82);
  --stroke: rgba(61, 232, 255, 0.35);
  --font-display: "Oxanium", "Outfit", sans-serif;
  --font-body: "Outfit", "Pretendard", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: #041018;
  overflow-x: hidden;
}

/* Android rotation-lock: CSS landscape fallback (same as prism-tycoon). */
html.force-landscape,
html.force-landscape body {
  overflow: hidden;
  touch-action: none;
}
html.force-landscape input,
html.force-landscape textarea,
html.force-landscape button,
html.force-landscape a {
  touch-action: manipulation;
}
/* 돌리는 규칙은 화면이 실제로 세로일 때만. 기기를 눕히는 순간 CSS가 먼저 풀려 한 번 더 돌아간 화면이 번쩍이지 않는다 */
@media (orientation: portrait) {
html.force-landscape #game-container {
  position: fixed;
  inset: auto;
  right: auto;
  bottom: auto;
  top: 0;
  left: 100vw;
  left: 100dvw;
  width: 100vh;
  width: 100dvh;
  height: 100vw;
  height: 100dvw;
  max-width: none;
  margin: 0;
  transform: rotate(90deg);
  transform-origin: top left;
  background: #041018;
}
/* 반대쪽으로 눕혀 든 경우(game.js가 기기 기울기로 고른다) */
html.force-landscape.force-landscape-ccw #game-container {
  top: 100vh;
  top: 100dvh;
  left: 0;
  transform: rotate(-90deg);
}
}
/* game.js도 상자에 직접 회전을 건다. 가로가 된 순간에는 스크립트가 풀기 전이라도 CSS가 먼저 제자리로.
   단 이름을 쓰는 중(fl-typing)에는 자판 때문에 화면이 가로처럼 줄었을 뿐이라 풀지 않는다 */
@media (orientation: landscape) {
html.force-landscape:not(.fl-typing) #game-container {
  position: relative !important; inset: auto !important; top: auto !important; left: auto !important;
  width: 100% !important; height: 100dvh !important; max-width: none !important; margin: 0 !important; transform: none !important;
}
}
/* 돌려서 보는 세로 폰: 게임 상자의 높이 = 화면 폭(100vw). 예전에는 가로 길이로 계산해 그림판이 상자보다 높아져 아래가 잘렸다(2026-10-24) */
html.force-landscape body.hud-overlay-mobile .canvas-wrapper.world-wrap {
  width: min(100%, calc(100vw * 960 / 520));
  width: min(100%, calc(100dvw * 960 / 520));
  max-width: 100%;
  max-height: 100%;
}
html.force-landscape .lab-bg {
  display: none;
}
html.force-landscape .modal-backdrop {
  align-items: flex-start;
  overflow: auto;
  height: 100%;
  max-height: 100%;
  -webkit-overflow-scrolling: touch;
}
html.force-landscape .modal-card {
  max-height: none;
}

.lab-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(61, 232, 255, 0.12), transparent 55%),
    linear-gradient(180deg, #061820 0%, #041018 100%);
  pointer-events: none;
  z-index: 0;
}

.game-container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 14px 28px;
}

.game-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.game-header .user-profile-card {
  order: 2;
}
.header-hud-slot {
  display: flex;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
  order: 3;
}
.header-left {
  order: 1;
}

.game-title-group h1 {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 2.2vw, 1.35rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--cyan);
}

.play-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.play-hud-slot {
  display: none;
}

.user-profile-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 6px 8px;
}
.profile-text { display: flex; flex-direction: column; line-height: 1.2; }
.profile-name { font-size: 0.85rem; font-weight: 700; }
.profile-id { font-size: 0.7rem; color: var(--ink-dim); }
.btn-small-edit {
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 8px;
}

.btn-sound,
.btn-fullscreen {
  position: absolute;
  top: max(8px, env(safe-area-inset-top, 0px));
  z-index: 31; /* 첫 화면(.title-screen z 30) 위에도 */
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(61, 232, 255, 0.35);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  background: rgba(4, 14, 24, 0.82);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.btn-sound {
  right: max(8px, env(safe-area-inset-right, 0px));
}
.btn-sound.muted { opacity: 0.55; }
.btn-sound:hover,
.btn-fullscreen:hover { border-color: var(--accent-cyan); }
.btn-fullscreen {
  right: max(52px, calc(env(safe-area-inset-right, 0px) + 44px));
}
.btn-fullscreen.hidden { display: none !important; }
html.force-landscape .btn-fullscreen { display: none !important; }

.tool-slots {
  display: flex;
  gap: 6px;
}
.tool-slot {
  min-width: 64px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px dashed var(--stroke);
  font-size: 0.75rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
}
.tool-slot.filled {
  border-style: solid;
  background: rgba(61, 232, 255, 0.12);
  color: var(--cyan);
  font-weight: 700;
}
.tank-pips {
  display: flex;
  gap: 5px;
}
.tank-pip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--stroke);
  background: rgba(255, 107, 138, 0.35);
}
.tank-pip.current { outline: 2px solid var(--gold); }
.tank-pip.fixed { background: rgba(93, 255, 176, 0.55); border-color: var(--ok); }

.time-gauge {
  position: absolute;
  top: max(8px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 280px;
  max-width: min(280px, 46%);
  padding: 5px 10px 5px 8px;
  background: rgba(4, 14, 24, 0.82);
  border: 1px solid rgba(61, 232, 255, 0.38);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.time-gauge-track {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(61, 232, 255, 0.35);
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.35);
}
.time-gauge-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff6b8a 0%, #ffd56a 35%, #3de8ff 100%);
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 0.15s linear;
}
.time-gauge-fill.low {
  background: linear-gradient(90deg, #ff3d5e, #ff8a5c);
}
.time-gauge-label {
  flex-shrink: 0;
  min-width: 44px;
  text-align: right;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--gold);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.mission-toast {
  position: absolute;
  left: 50%;
  top: 50px;
  transform: translateX(-50%);
  z-index: 6;
  width: max-content;
  max-width: calc(100% - 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(6, 18, 32, 0.9);
  border: 1px solid rgba(255, 213, 106, 0.55);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.2s ease;
}
.mission-toast.in-scene {
  border-color: rgba(61, 232, 255, 0.5);
}
.mission-toast.dim {
  opacity: 0.25;
  transform: translateX(-50%) scale(0.98);
}
.mission-text {
  font-weight: 800;
  font-size: clamp(0.95rem, 2.6vw, 1.15rem);
  line-height: 1.35;
  color: #fff;
  text-align: center;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  max-width: min(640px, 92vw);
}

.canvas-section { margin-bottom: 8px; }
.canvas-wrapper.world-wrap {
  position: relative;
  width: min(100%, calc((100dvh - var(--chrome-h, 200px)) * 960 / 520));
  margin-inline: auto;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  background: #0a1a24;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 520;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.scene-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  z-index: 8;
}
.scene-chrome-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  pointer-events: auto;
}
.btn-scene {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(6, 22, 36, 0.92);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn-scene:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-scene-primary {
  background: linear-gradient(135deg, #1ec8e0, #0a8fb8);
  border-color: transparent;
  color: #031018;
  font-family: var(--font-display);
  font-weight: 800;
}

.side-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: min(280px, calc(100% - 24px));
  background: rgba(6, 22, 36, 0.94);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 14px;
  z-index: 5;
  backdrop-filter: blur(8px);
}
.side-panel h3 {
  font-family: var(--font-display);
  color: var(--cyan);
  margin-bottom: 6px;
  font-size: 1rem;
}
.side-panel-hint {
  font-size: 0.8rem;
  color: var(--ink-dim);
  margin-bottom: 12px;
  line-height: 1.4;
}
.pick-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.pick-btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(61, 232, 255, 0.08);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
}
.pick-btn:hover { background: rgba(61, 232, 255, 0.18); }
.pick-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.app-footer {
  text-align: center;
  margin-top: 16px;
}
.privacy-link {
  color: var(--ink-dim);
  font-size: 0.75rem;
  text-decoration: none;
}
.privacy-link:hover { color: var(--cyan); }

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 8, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(520px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  background: linear-gradient(165deg, #0c2438 0%, #081828 100%);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.btn-modal-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(61, 232, 255, 0.1);
  color: var(--ink);
  font-weight: 800;
  font-family: var(--font-display);
  cursor: pointer;
  text-decoration: none;
  margin-top: 8px;
}
.btn-modal-action.btn-primary {
  background: linear-gradient(135deg, #1ec8e0, #0a8fb8);
  border-color: transparent;
  color: #031018;
}
.btn-modal-action.btn-secondary {
  background: transparent;
}

/* ===== 첫 화면 (2026-10-24 사용자: 게임에 맞춰 다시 디자인) =====
   게임 장면(.world-wrap) 안에 첫 화면 그림(title-bg: 조용한 실험실, 금 간 수조에서 물이 가늘게 새고 양순이가 자를 물고 올려다본다)을 깔고, 그림 속 빨간 경고등을 깜빡이며,
   위에 큰 제목, 아래 게임 속 하늘색 계기판 같은 막대에 1위·이름·수리 시작을 둔다.
   글자 크기는 장면 폭을 따라간다(cqw, 안 되는 브라우저는 vw로 대신) */
.title-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  container-type: inline-size;
  background: #041018;
  color: var(--ink);
}
.ts-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  filter: brightness(0.82) saturate(1.05);
}
.ts-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(2, 10, 18, 0.88) 0%, rgba(2, 10, 18, 0.5) 22%, rgba(2, 10, 18, 0) 44%),
    linear-gradient(0deg, rgba(2, 10, 18, 0.9) 0%, rgba(2, 10, 18, 0.45) 16%, rgba(2, 10, 18, 0) 32%);
}
/* 그림 속 벽 경고등(가로 63%·세로 37%, 장면 2:1에 맞춰 위아래가 조금 잘린 자리) 둘레로 붉은 빛이 번졌다 줄었다 한다 */
.ts-alarm {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  background:
    radial-gradient(circle at 63.3% 37%, rgba(255, 60, 40, 0.75), rgba(255, 60, 40, 0.18) 4%, rgba(255, 60, 40, 0) 13%);
  animation: ts-alarm 1.6s ease-in-out infinite;
}
@keyframes ts-alarm {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 1; }
}
.ts-alert {
  position: absolute;
  left: 2.4%;
  top: 4%;
  display: flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.4em 0.8em;
  border: 1px solid rgba(255, 107, 90, 0.55);
  border-radius: 999px;
  background: rgba(40, 6, 6, 0.55);
  color: #ffb3a8;
  font: 800 clamp(11px, 1.1vw, 14px)/1 var(--font-body);
  letter-spacing: 0.06em;
}
.ts-alert i {
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: #ff5a4a;
  box-shadow: 0 0 8px #ff5a4a;
  animation: ts-blink 1s steps(2, start) infinite;
}
@keyframes ts-blink {
  to { visibility: hidden; }
}
.ts-title {
  position: absolute;
  left: 0;
  right: 0;
  top: 7%;
  text-align: center;
  pointer-events: none;
}
.ts-title h2 {
  margin: 0;
  font-family: "Pretendard", var(--font-body);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.ts-line1 {
  display: block;
  font-size: clamp(32px, 4.8vw, 66px);
  color: #fff;
  text-shadow: 0 0 18px rgba(61, 232, 255, 0.55), 0 4px 0 rgba(2, 10, 18, 0.85);
}
.ts-line2 {
  display: block;
  margin-top: 0.12em;
  font-size: clamp(22px, 3vw, 42px);
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(61, 232, 255, 0.6), 0 3px 0 rgba(2, 10, 18, 0.85);
}
.ts-rule {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  margin: 0.8em auto 0;
  padding: 0.4em 1em;
  border: 1px solid rgba(61, 232, 255, 0.35);
  border-radius: 999px;
  background: rgba(4, 16, 28, 0.6);
  color: #e8f4ff;
  font-size: clamp(12px, 1.25vw, 17px);
  font-weight: 700;
}
/* 측정 기회 세 번 */
.ts-pips { display: inline-flex; gap: 0.3em; }
.ts-pips i {
  width: 0.62em;
  height: 0.62em;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(255, 213, 106, 0.8);
}
@supports (container-type: inline-size) {
  .ts-alert { font-size: clamp(11px, 1.15cqw, 14px); }
  .ts-line1 { font-size: 5.2cqw; }
  .ts-line2 { font-size: 3.3cqw; }
  .ts-rule { font-size: clamp(12px, 1.35cqw, 17px); }
}

/* 아래 계기판 막대
   2026-10-24 사용자: 막대가 너무 얇고 시작 단추가 잘 안 보였으며, 안내 문구가 그림 위(고양이 발밑)에 떠 있었다.
   → 막대를 두툼하게, 안내는 막대 안 입력칸 바로 위로, 「수리 시작」은 가운데 크게 노란 경고색으로 은은하게 빛나게 */
.ts-console {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 2.4% max(16px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(4, 18, 30, 0.82), rgba(3, 12, 22, 0.96));
  border-top: 2px solid rgba(61, 232, 255, 0.55);
  box-shadow: 0 -2px 18px rgba(61, 232, 255, 0.18), 0 -14px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}
.ts-champ {
  justify-self: start;
  min-width: 0;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.65em 0.95em;
  border: 1px solid rgba(255, 213, 106, 0.55);
  border-radius: 12px;
  background: rgba(40, 30, 8, 0.45);
  color: #fff;
  font: 700 15px/1.1 var(--font-body);
  cursor: pointer;
}
.ts-champ:hover { border-color: var(--gold); }
.ts-champ-label { color: var(--gold); font-weight: 800; white-space: nowrap; }
.ts-champ .champ-name {
  min-width: 0;
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ts-champ .champ-id { font-size: 0.85em; color: var(--ink-dim); white-space: nowrap; }
.ts-champ .champ-score {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.ts-champ .champ-score small { display: none; }
.ts-champ-caret { color: var(--ink-dim); transition: transform 0.15s; }
.ts-champ[aria-expanded="true"] .ts-champ-caret { transform: rotate(-90deg); }

/* 가운데: 안내(또는 오류) 한 줄 위에, 이름 칸과 시작 단추를 나란히 */
.title-screen .profile-form {
  display: grid;
  grid-template-areas: "msg msg" "fields start";
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
  min-width: 0;
}
.ts-fields {
  grid-area: fields;
  min-width: 0;
  display: flex;
  gap: 10px;
}
.title-screen .profile-form label {
  display: flex;
  align-items: center;
  gap: 0.5em;
  min-width: 0;
  color: var(--ink-dim);
  font: 700 15px var(--font-body);
  white-space: nowrap;
}
.title-screen .profile-form input {
  width: 12em;
  min-width: 5em;
  padding: 0.7em 0.9em;
  border: 1px solid rgba(61, 232, 255, 0.5);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--ink);
  font-size: 17px;
}
.title-screen #input-student-id { width: 8.5em; }
/* 안내와 오류는 같은 자리에 쓴다(오류가 있으면 안내를 가린다) */
.title-screen .profile-lead,
.title-screen .profile-err {
  grid-area: msg;
  margin: 0;
  min-height: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}
.title-screen .profile-lead { color: rgba(232, 244, 255, 0.78); }
.title-screen .profile-err { color: #ffb4c0; }
.title-screen .profile-err:empty { visibility: hidden; }
.title-screen .profile-err:not(:empty) + .profile-lead { visibility: hidden; }
.ts-start {
  grid-area: start;
  padding: 0.62em 1.6em;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffe08a, #ffb02e);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), 0 5px 0 #b86a00, 0 0 22px rgba(255, 190, 70, 0.55);
  color: #2a1600;
  font: 900 22px/1 var(--font-body);
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  animation: ts-start-glow 1.8s ease-in-out infinite;
}
.ts-start:hover { filter: brightness(1.06); }
.ts-start:active { transform: translateY(3px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), 0 2px 0 #b86a00, 0 0 22px rgba(255, 190, 70, 0.55); }
@keyframes ts-start-glow {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), 0 5px 0 #b86a00, 0 0 14px rgba(255, 190, 70, 0.35); }
  50% { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), 0 5px 0 #b86a00, 0 0 30px rgba(255, 190, 70, 0.85); }
}

/* 순위표: 1위 막대를 누르면 그 위로 펼친다 */
.title-screen .opening-leaderboard-box {
  position: absolute;
  left: 2.4%;
  bottom: 124px;
  z-index: 2;
  width: min(420px, 46%);
  max-height: 52%;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid rgba(61, 232, 255, 0.4);
  border-radius: 14px;
  background: rgba(4, 16, 28, 0.95);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  text-align: left;
}
.title-screen .opening-leaderboard-box .leaderboard-table-wrapper { max-height: none; margin: 0; }
.opening-leaderboard-box.hidden { display: none; }

/* 좁은 장면(폰 가로·돌려 본 폰·작은 창): 칸 이름과 안내는 빼고(입력칸 안 안내 글로 대신) 한 줄로 */
@media (max-width: 900px), (max-height: 480px) {
  .ts-console {
    grid-template-columns: auto 1fr;
    gap: 10px;
    padding-top: 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  .ts-champ { padding: 0.6em 0.75em; font-size: 13px; }
  .ts-champ .champ-name { max-width: 5.5em; }
  .ts-champ .champ-id { display: none; }
  .title-screen .profile-form { justify-self: end; grid-template-areas: "fields start"; column-gap: 8px; position: relative; }
  .ts-fields { gap: 6px; }
  .title-screen .profile-form label { font-size: 0; gap: 0; }
  .title-screen .profile-form input { width: 9em; padding: 0.6em 0.75em; font-size: 16px; }
  .title-screen #input-student-id { width: 8.2em; }
  .title-screen .profile-lead { display: none; }
  .title-screen .profile-err { position: absolute; left: 0; right: 0; bottom: calc(100% + 12px); font-size: 12px; text-shadow: 0 1px 3px #000; }
  .ts-start { padding: 0.6em 1.15em; font-size: 18px; }
  .title-screen .opening-leaderboard-box { bottom: 74px; width: min(380px, 60%); max-height: 60%; }
}

body.mode-dorms #label-student-id,
body.mode-dorms #display-profile-id,
body.mode-dorms #result-locked-id-wrap,
body.mode-dorms #th-leaderboard-id,
body.mode-dorms #th-opening-id,
body.mode-dorms #opening-champ-id {
  display: none !important;
}

.quiz-header, .result-header, .gameover-header { text-align: center; margin-bottom: 12px; }
.quiz-header h2, .result-header h2, .gameover-header h2 {
  font-family: var(--font-display);
  color: var(--cyan);
}
.quiz-prompt { text-align: center; margin-bottom: 12px; color: var(--ink-dim); }
.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choice {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(61, 232, 255, 0.08);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.quiz-feedback { text-align: center; margin-top: 10px; min-height: 1.2em; font-weight: 700; }

.hinge-angle-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 4px;
}
.hinge-angle-field input {
  width: 7.5rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(6, 22, 36, 0.9);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
}
.hinge-angle-unit {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--gold);
}
.hinge-angle-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.hinge-angle-actions .btn-modal-action {
  min-width: 7rem;
}

.assemble-fail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.assemble-fail-actions .btn-modal-action {
  width: 100%;
}

.result-score-badge {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 8px;
}
.result-subtitle, .result-hint {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-bottom: 6px;
}

.final-score-display { text-align: center; margin-bottom: 14px; }
.score-circle {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 12px;
}
.score-num {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 800;
  color: var(--gold);
}
.round-scores-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  font-size: 0.75rem;
}
.round-score-cell {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 6px 4px;
  border: 1px solid var(--stroke);
}
.highscore-banner {
  text-align: center;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 10px;
}
.send-action-box { margin-bottom: 14px; }
.result-locked-player-box {
  font-size: 0.85rem;
  color: var(--ink-dim);
  text-align: center;
  margin-bottom: 8px;
}
.api-status-msg { text-align: center; font-size: 0.8rem; margin-top: 6px; min-height: 1.2em; }
.leaderboard-section h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--cyan);
}
.leaderboard-table-wrapper { overflow: auto; max-height: 200px; margin-bottom: 12px; }
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.leaderboard-table th, .leaderboard-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(61, 232, 255, 0.15);
  text-align: left;
}

@keyframes lb-skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.lb-skeleton-row td {
  vertical-align: middle;
}

.lb-skeleton-bar {
  display: block;
  height: 0.85em;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    rgba(61, 232, 255, 0.12) 25%,
    rgba(61, 232, 255, 0.28) 37%,
    rgba(61, 232, 255, 0.12) 63%
  );
  background-size: 400% 100%;
  animation: lb-skeleton-shimmer 1.15s ease-in-out infinite;
}

.lb-skeleton-bar.w-xs { width: 22%; }
.lb-skeleton-bar.w-sm { width: 36%; }
.lb-skeleton-bar.w-md { width: 58%; }
.lb-skeleton-bar.w-lg { width: 44%; }

.champ-name .lb-skeleton-bar,
.champ-id .lb-skeleton-bar,
.champ-score .lb-skeleton-bar {
  margin: 0.15em 0;
}
.gameover-actions { display: flex; flex-direction: column; gap: 4px; }
.gameover-subtitle { color: var(--ink-dim); font-size: 0.85rem; }

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.intro-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;
}
.intro-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}
.intro-alert {
  align-self: flex-start;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--danger);
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  text-shadow: 0 0 12px rgba(255, 107, 138, 0.6);
}
.intro-alert.success-alert {
  color: #5dffb0;
  text-shadow: 0 0 12px rgba(93, 255, 176, 0.55);
}
.intro-alert.timeout-alert {
  color: #7ec8ff;
  text-shadow: 0 0 12px rgba(126, 200, 255, 0.55);
}
/* 영상이 화면을 덮는 동안에도 소리를 끌 수 있게 영상 위에 둔다 (게임의 🔊와 같은 상태) */
.btn-video-sound {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  pointer-events: auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}
.btn-video-sound.muted { opacity: 0.6; }

.btn-skip-intro {
  pointer-events: auto;
  align-self: flex-end;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.measure-ref-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 10, 20, 0.72);
  padding: 16px;
}
.measure-ref-overlay.hidden { display: none; }
.measure-ref-card {
  background: rgba(8, 24, 40, 0.96);
  border: 1px solid rgba(61, 232, 255, 0.35);
  border-radius: 14px;
  padding: 14px 16px 12px;
  max-width: 100%;
}
.measure-ref-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.measure-ref-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--cyan);
}
.measure-ref-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--ink-dim);
  text-align: center;
}
#measure-ref-canvas {
  display: block;
  width: min(560px, 92vw);
  height: auto;
  border-radius: 10px;
  background: #061420;
}

@media (max-width: 720px) {
  .scene-chrome-actions { flex-wrap: wrap; }
  .round-scores-grid { grid-template-columns: repeat(3, 1fr); }
  .game-container { padding: 6px 8px 12px; }
}

/* Portrait phones/tablets: block play until landscape (JS toggles .needs-landscape). */
.rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(61, 232, 255, 0.14), transparent 60%),
    rgba(2, 8, 14, 0.94);
  backdrop-filter: blur(6px);
}
.rotate-gate.hidden { display: none !important; }
.rotate-gate-card {
  text-align: center;
  max-width: 280px;
  pointer-events: auto;
}
#btn-rotate-lock {
  margin-top: 14px;
  touch-action: manipulation;
}
.rotate-phone {
  width: 46px;
  height: 76px;
  margin: 0 auto 18px;
  border: 3px solid var(--cyan);
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(61, 232, 255, 0.25);
  position: relative;
  animation: rotate-phone-hint 1.7s ease-in-out infinite;
}
.rotate-phone::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  background: rgba(61, 232, 255, 0.7);
  transform: translateX(-50%);
}
@keyframes rotate-phone-hint {
  0%, 18% { transform: rotate(0deg); }
  42%, 62% { transform: rotate(90deg); }
  86%, 100% { transform: rotate(0deg); }
}
.rotate-gate-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  color: #fff;
  margin-bottom: 8px;
}
.rotate-gate-desc {
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink-dim);
}
body.needs-landscape {
  overflow: hidden;
}

/* Mobile/tablet landscape: viewport contain fullscreen (keep 960:520). */
body.hud-overlay-mobile {
  overflow: hidden;
  width: 100%;
  height: 100dvh;
  overscroll-behavior: none;
}
body.hud-overlay-mobile .game-header {
  display: none;
}
body.hud-overlay-mobile .app-footer {
  display: none;
}
body.hud-overlay-mobile .game-container {
  max-width: none;
  width: 100%;
  height: 100dvh;
  margin: 0;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
body.hud-overlay-mobile .game-main,
body.hud-overlay-mobile .canvas-section {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.hud-overlay-mobile .canvas-wrapper.world-wrap {
  width: min(
    100%,
    calc((100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 960 / 520)
  );
  max-width: 100%;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  height: auto;
  aspect-ratio: 960 / 520;
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
}
body.hud-overlay-mobile #game-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 520;
}
/* 마우스로 하는 컴퓨터: 제빵냥처럼 폭 1280을 넘게 키우지 않아 큰 모니터에서도 장면이 가운데에 알맞게 놓인다 */
@media (any-hover: hover) and (any-pointer: fine) {
  body.hud-overlay-mobile .canvas-wrapper.world-wrap {
    width: min(
      100%,
      1280px,
      calc((100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 960 / 520)
    );
  }
}
body.hud-overlay-mobile .play-hud-slot {
  display: block;
  position: absolute;
  left: max(8px, env(safe-area-inset-left, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  z-index: 7;
  pointer-events: none;
}
body.hud-overlay-mobile .play-hud {
  pointer-events: auto;
  width: 100%;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(4, 14, 24, 0.82);
  border: 1px solid rgba(61, 232, 255, 0.35);
  backdrop-filter: blur(6px);
}
body.hud-overlay-mobile .tool-slot {
  min-width: 52px;
  padding: 4px 6px;
  font-size: 0.7rem;
}
body.hud-overlay-mobile .mission-toast {
  top: max(48px, calc(env(safe-area-inset-top, 0px) + 42px));
  padding: 7px 14px;
}
body.hud-overlay-mobile .mission-text {
  font-size: clamp(0.92rem, 2.8vw, 1.08rem);
  max-width: min(620px, 90vw);
}
body.hud-overlay-mobile .time-gauge {
  top: max(8px, env(safe-area-inset-top, 0px));
  width: 240px;
  max-width: min(240px, 42%);
  padding: 3px 8px 3px 6px;
}
body.hud-overlay-mobile .time-gauge-track {
  height: 10px;
}
body.hud-overlay-mobile .time-gauge-label {
  font-size: 0.85rem;
  min-width: 40px;
}
body.hud-overlay-mobile .scene-chrome {
  padding:
    12px
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
}
body.hud-overlay-mobile .scene-chrome-actions {
  margin-bottom: 52px;
}
/* 2026-10-24: 작업대·수조 장면에서는 버튼이 조립판 오른쪽 아래를 가리지 않게 아래 막대 줄로 내린다.
   그동안 막대는 왼쪽 도구 칸만 보이고, 수조 진행 칸(오른쪽)은 복도로 돌아오면 다시 보인다 */
body.hud-overlay-mobile.in-scene .play-hud { width: fit-content; }
body.hud-overlay-mobile.in-scene .tank-pips { display: none; }
body.hud-overlay-mobile.in-scene .scene-chrome-actions { margin-bottom: 0; }

/* 함께 풀기(?teach=1): 선생님 화면 하나로 설명할 때는 이름·시간·수조 진행 표시를 숨긴다 */
html.teach-on #profile-modal,
html.teach-on .user-profile-card,
html.teach-on .time-gauge,
html.teach-on #tank-pips {
  display: none !important;
}

/* 2026-10-24 사용자: 폰 가로 화면(높이 390 안팎)에서 게임 끝 창이 화면보다 길어 아래로 내려야 했다 → 낮은 화면에서는 두 칸으로.
   (돌려서 보는 세로 폰은 화면 폭이 게임의 높이가 되므로 max-width로 같은 경우를 잡는다) */
@media (orientation: landscape) and (max-height: 560px), (orientation: portrait) and (max-width: 560px) {
  /* 게임 끝 창도 같은 이유로 두 칸: 왼쪽에 결과·기록 등록·다시 도전하기, 오른쪽에 순위표 */
  #gameover-modal { padding: 10px; }
  .modal-card.gameover-card {
    width: min(760px, 100%);
    max-height: 100%;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
    align-content: start;
  }
  .gameover-card > * { grid-column: 1; }
  .gameover-card > .leaderboard-section { grid-column: 2; grid-row: 1 / span 6; min-height: 0; }
  .gameover-card .leaderboard-table-wrapper { max-height: calc(100vh - 110px); margin-bottom: 0; }
  /* 돌려서 보는 세로 폰은 화면 폭이 게임의 높이다 */
  html.force-landscape .gameover-card .leaderboard-table-wrapper { max-height: calc(100vw - 110px); max-height: calc(100dvw - 110px); }
  .gameover-card .gameover-header { margin-bottom: 6px; }
  .gameover-card .final-score-display { margin-bottom: 6px; }
  .gameover-card .send-action-box { margin-bottom: 6px; }
}
