html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: -webkit-fill-available;
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --game-viewport-width: 100vw;
  --game-viewport-height: 100vh;
}

@supports (height: 100dvh) {
  :root {
    --game-viewport-width: 100dvw;
    --game-viewport-height: 100dvh;
  }
}

#unity-container {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

/*
 * Letterbox 适配：
 * canvas 的内部渲染尺寸由 performance.js 控制，最高为 1280×720。
 * 下面的 CSS 控制显示尺寸：先按窗口宽度算 16:9 高度；如果算出的高度超过窗口高度，
 * 改用 max-height 限制并按 16:9 反算宽度。结果就是窗口里居中显示一块固定 16:9
 * 的画面，多余空间是黑边（letterbox）。CanvasScaler 继续按参考分辨率等比排版。
 */
#unity-canvas {
  width: min(
    calc(var(--game-viewport-width) - env(safe-area-inset-left) - env(safe-area-inset-right)),
    calc((var(--game-viewport-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9)
  );
  height: min(
    calc((var(--game-viewport-width) - env(safe-area-inset-left) - env(safe-area-inset-right)) * 9 / 16),
    calc(var(--game-viewport-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom))
  );
  background: #07181e;
  display: block;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#unity-loading-bar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, calc(100vw - 64px));
  padding: 32px;
  box-sizing: border-box;
  color: #edf4f1;
  background: #0d2028;
  border-top: 3px solid #60cdb0;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Segoe UI", sans-serif;
  text-align: left;
}

#unity-loading-bar[hidden] { display: none; }
.loading-eyebrow { margin: 0 0 22px; color: #60cdb0; font-size: 12px; letter-spacing: .04em; }
#loading-title { margin: 0 0 14px; font-size: clamp(19px, 3vw, 25px); line-height: 1.4; }
#loading-status { min-height: 24px; margin: 0 0 20px; font-size: 14px; line-height: 1.7; }
#loading-progress-text { margin: 8px 0 20px; color: #60cdb0; font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
#loading-help { margin: 0; min-height: 44px; font-size: 13px; line-height: 1.7; color: #b4c7c9; }
#loading-version { margin: 20px 0 0; color: #829d9f; font-size: 10px; }
#loading-retry {
  width: 100%;
  min-height: 48px;
  margin-top: 20px;
  border: 0;
  border-radius: 3px;
  background: #60cdb0;
  color: #082b29;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
#loading-retry:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
#loading-retry:disabled { opacity: .6; cursor: wait; }
#unity-loading-bar[data-state="failed"] { border-top-color: #edbd85; }
#unity-loading-bar[data-state="failed"] #loading-progress-text { color: #edbd85; }

#unity-progress-bar-empty {
  width: 100%;
  height: 6px;
  background: #29424a;
  border-radius: 3px;
  overflow: hidden;
}

#unity-progress-bar-full {
  width: 0%;
  height: 100%;
  background: #60cdb0;
  transition: width 0.2s ease;
}

@media (max-height: 450px) {
  #unity-loading-bar { padding: 18px 24px; width: min(500px, calc(100vw - 64px)); }
  .loading-eyebrow { margin-bottom: 10px; }
  #loading-title { font-size: 20px; margin-bottom: 8px; }
  #loading-status { margin-bottom: 12px; }
  #loading-progress-text { margin-bottom: 10px; }
  #loading-retry { margin-top: 12px; }
  #loading-version { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  #unity-progress-bar-full { transition: none; }
}

#unity-warning {
  position: absolute;
  left: 50%;
  top: 5%;
  transform: translate(-50%, 0);
  background: white;
  padding: 10px;
  display: none;
  z-index: 1000;
}

#orientation-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    calc(env(safe-area-inset-top) + 24px)
    calc(env(safe-area-inset-right) + 24px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 24px);
  box-sizing: border-box;
  background: #111;
  color: #f7f4ee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
}

#orientation-overlay.is-visible {
  display: flex;
}

.orientation-card {
  max-width: 320px;
}

.orientation-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 20px;
}

.orientation-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 10px;
}

.orientation-body {
  font-size: 15px;
  line-height: 1.5;
  color: #cfc8bd;
}

/* 保護者同意: a scrollable document above the loading game. Shown only while the
   html element carries .guardian-consent-pending (set by guardian-consent.js). */
#guardian-consent {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2500;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  box-sizing: border-box;
  background: #07181e;
  color: #1f2d31;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html.guardian-consent-pending #guardian-consent { display: block; }

.consent-sheet {
  max-width: 760px;
  margin: 24px auto 40px;
  padding: 28px clamp(18px, 5vw, 48px) 36px;
  box-sizing: border-box;
  background: #fbfaf6;
  border-top: 4px solid #60cdb0;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.85;
  overflow-wrap: anywhere;
}
.consent-sheet[hidden] { display: none; }
.consent-sheet p { margin: 0 0 12px; }
.consent-sheet a { color: #0d6b58; }
.consent-sheet h1 {
  margin: 0 0 4px;
  font-size: clamp(20px, 3.4vw, 26px);
  line-height: 1.45;
  outline: none;
}
.consent-subtitle { color: #4a5d61; font-weight: 600; margin-bottom: 20px !important; }
.consent-lead {
  padding: 10px 14px;
  margin-bottom: 20px !important;
  border-left: 4px solid #60cdb0;
  background: #e5f4ef;
  font-weight: 600;
}
.consent-sheet h2 {
  margin: 28px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid #d6dedb;
  font-size: 17px;
  line-height: 1.5;
}
.consent-sheet ul { margin: 0 0 12px; padding: 0; list-style: none; }
.consent-sheet li { position: relative; padding-left: 1.2em; margin-bottom: 4px; }
.consent-sheet li::before { content: "・"; position: absolute; left: 0; }

.consent-form {
  margin-top: 32px;
  padding: 4px 0 0;
  border-top: 3px double #b9c8c4;
}
.consent-form fieldset { margin: 0 0 18px; padding: 0; border: 0; min-width: 0; }
.consent-form legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.consent-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 8px;
  padding: 0 14px;
  border: 1px solid #b9c8c4;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.consent-option:has(input:checked) { border-color: #1f8f74; background: #eef8f4; }
.consent-option input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: #1f8f74; }
.consent-field { display: block; margin: 0 0 6px; font-weight: 600; }
.consent-field span { display: block; margin-bottom: 6px; }
.consent-field input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  box-sizing: border-box;
  border: 1px solid #9fb3b6;
  border-radius: 6px;
  background: #fff;
  color: #1f2d31;
  font: inherit;
  font-size: 17px;
  font-weight: 400;
  -webkit-user-select: text;
  user-select: text;
}
.consent-field input[aria-invalid="true"] { border-color: #b3261e; }
.consent-form input:focus-visible, .consent-button:focus-visible, .consent-sheet a:focus-visible {
  outline: 3px solid #1f8f74;
  outline-offset: 2px;
}
.consent-error { margin: 4px 0 14px !important; color: #b3261e; font-size: 14px; font-weight: 600; }
.consent-error[hidden] { display: none; }
.consent-date { margin-top: 18px !important; font-weight: 600; }
.consent-note { color: #4a5d61; font-size: 14px; }
.consent-button {
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  border: 0;
  border-radius: 6px;
  background: #60cdb0;
  color: #082b29;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.consent-button-secondary { background: transparent; border: 1px solid #1f8f74; color: #0d6b58; }
.consent-button:disabled { opacity: .45; cursor: not-allowed; }
.consent-hint { margin: 8px 0 0 !important; color: #4a5d61; font-size: 14px; text-align: center; }
.consent-hint[hidden] { display: none; }
/* 生徒の同意 */
.consent-people { color: #4a5d61; font-size: 14px; line-height: 1.7; margin-bottom: 18px !important; }
#student-consent-form { margin-top: 20px; }
#student-consent-form .consent-option { align-items: flex-start; padding: 12px 14px; line-height: 1.6; }
#student-consent-form .consent-option input { margin-top: 2px; }
#student-consent-decline { margin-top: 24px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

@media (max-width: 600px) {
  .consent-sheet { margin: 0; border-radius: 0; min-height: 100%; }
}
