:root {
  color-scheme: dark;
  font-family: Inter, "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: #12151b;
  color: #f4f7fb;
}

* { box-sizing: border-box; }

html, body, #app, #viewport {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body { background: #12151b; }

#app { position: relative; }

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.panel {
  position: absolute;
  z-index: 5;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(18, 21, 27, .86);
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.loading-panel {
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  padding: 38px 34px;
  border-radius: 22px;
  text-align: center;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}

.loading-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.08);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: .03em;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.15;
}

p { margin: 8px 0; }
.sub { opacity: .55; font-size: 13px; }
.note { margin-top: 20px; opacity: .64; font-size: 12px; line-height: 1.6; }

button {
  appearance: none;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 11px;
  padding: 10px 15px;
  background: rgba(255,255,255,.10);
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: rgba(255,255,255,.16); }
button:active { transform: translateY(1px); }

.hud {
  top: 16px;
  left: 16px;
  width: min(390px, calc(100% - 32px));
  padding: 14px;
  border-radius: 15px;
}

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

.hud-title { justify-content: space-between; }
#modelName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-row {
  margin-top: 7px;
  opacity: .72;
  font-size: 12px;
}

.badge {
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(255,255,255,.07);
  font-size: 10px;
  letter-spacing: .05em;
}

.controls-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 10px;
  margin-top: 13px;
  align-items: center;
  font-size: 12px;
  opacity: .88;
}

.key {
  min-width: 50px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.15);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 3px 6px;
  background: rgba(255,255,255,.07);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.button-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.button-row button {
  flex: 1;
  padding: 8px 10px;
  font-size: 12px;
}

.hidden { display: none !important; }

@media (max-width: 640px) {
  .loading-panel { padding: 28px 22px; }
  .hud { top: 10px; left: 10px; width: calc(100% - 20px); }
  .controls-grid { display: none; }
}


/* v1.0.0 title */
.app-title {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  gap: 9px;
  white-space: nowrap;
}

.app-title small {
  position: relative;
  bottom: 2px;
  font-size: 0.34em;
  font-weight: 700;
  letter-spacing: .04em;
  opacity: .62;
}

.hud-app-title {
  display: inline-flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
}

.hud-app-title small {
  position: relative;
  bottom: 1px;
  flex: 0 0 auto;
  font-size: 9px;
  font-weight: 700;
  opacity: .58;
}

.button-row {
  justify-content: stretch;
}

.button-row button {
  flex: 1 1 100%;
}

@media (max-width: 520px) {
  .app-title {
    white-space: normal;
    flex-wrap: wrap;
    gap: 5px 8px;
  }
}


/* v1.1.0: Shift + W / Shift + S の表示幅 */
.key {
  min-width: 78px;
}


/* v1.0.0 RELEASE: image logo */
.loading-panel {
  padding: 30px 34px 28px;
  overflow: hidden;
}

.loading-logo-wrap {
  position: relative;
  width: 100%;
  max-width: 470px;
  height: 150px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.title-logo {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 150px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,.22));
}

.title-version {
  position: absolute;
  right: 8px;
  bottom: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(18,21,27,.70);
  border: 1px solid rgba(255,255,255,.22);
  color: rgba(255,255,255,.86);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1.2;
}

.hud-title-compact {
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .loading-panel { padding: 24px 20px 22px; }
  .loading-logo-wrap { max-width: 430px; height: 126px; }
  .title-logo { max-height: 126px; }
}


/* v1.0.0 mobile controls / portrait + landscape */
html, body, #app, #viewport {
  min-height: 100%;
}

@supports (height: 100dvh) {
  html, body, #app, #viewport {
    height: 100dvh;
  }
}

.mobile-controls {
  display: none;
  position: absolute;
  z-index: 8;
  inset: auto 0 0 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mobile-dpad,
.mobile-actions {
  pointer-events: none;
}

.mobile-control {
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 4px;
  border: 1px solid rgba(255,255,255,.27);
  border-bottom-width: 2px;
  border-radius: 16px;
  background: rgba(18,21,27,.72);
  box-shadow: 0 5px 18px rgba(0,0,0,.28);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  color: #fff;
  line-height: 1;
  transition: transform .06s ease, background .06s ease, border-color .06s ease;
}

.mobile-control.is-held,
.mobile-control:active {
  transform: scale(.94);
  background: rgba(255,255,255,.24);
  border-color: rgba(255,255,255,.52);
}

.mobile-control.mode-active {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.58);
  box-shadow: 0 0 0 2px rgba(255,255,255,.08), 0 5px 18px rgba(0,0,0,.28);
}

.mobile-symbol {
  font-size: 24px;
  font-weight: 900;
}

.mobile-action-main {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .03em;
}

.mobile-label {
  margin-top: 3px;
  font-size: 8px;
  font-weight: 700;
  opacity: .76;
  white-space: nowrap;
}

.touch-ui .mobile-controls:not(.hidden) {
  display: block;
}

.touch-ui .controls-grid,
.touch-ui .hud .button-row {
  display: none;
}

.touch-ui .hud {
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  width: min(310px, calc(100% - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  padding: 9px 10px;
  border-radius: 12px;
  pointer-events: none;
}

.touch-ui .status-row {
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.35;
}

.touch-ui .badge {
  font-size: 8px;
  padding: 3px 6px;
}

/* Portrait: D-pad on lower left, action pad on lower right. */
@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  .mobile-controls {
    height: 244px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .mobile-dpad {
    position: absolute;
    left: max(10px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 154px;
    height: 154px;
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 5px;
  }

  .mobile-forward { grid-column: 2; grid-row: 1; }
  .mobile-left { grid-column: 1; grid-row: 2; }
  .mobile-right { grid-column: 3; grid-row: 2; }
  .mobile-back { grid-column: 2; grid-row: 3; }

  .mobile-actions {
    position: absolute;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(180px, 46vw);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .mobile-actions .mobile-control {
    height: 52px;
  }

  .mobile-jump {
    grid-column: 1 / -1;
    height: 58px !important;
  }
}

/* Narrow portrait phones: make the pads slightly smaller so they never overlap. */
@media (hover: none) and (orientation: portrait) and (max-width: 390px),
       (pointer: coarse) and (orientation: portrait) and (max-width: 390px) {
  .mobile-dpad {
    width: 137px;
    height: 137px;
    grid-template-columns: repeat(3, 43px);
    grid-template-rows: repeat(3, 43px);
    gap: 4px;
  }
  .mobile-actions {
    width: 164px;
    gap: 5px;
  }
  .mobile-actions .mobile-control { height: 47px; }
  .mobile-jump { height: 52px !important; }
  .mobile-symbol { font-size: 21px; }
  .mobile-action-main { font-size: 11px; }
}

/* Landscape: keep the character center clear and place compact pads in both lower corners. */
@media (hover: none) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  .mobile-controls {
    height: 172px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .touch-ui .hud {
    width: min(285px, 38vw);
    max-height: 88px;
    overflow: hidden;
  }

  .mobile-dpad {
    position: absolute;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(7px, env(safe-area-inset-bottom));
    width: 142px;
    height: 142px;
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 5px;
  }

  .mobile-forward { grid-column: 2; grid-row: 1; }
  .mobile-left { grid-column: 1; grid-row: 2; }
  .mobile-right { grid-column: 3; grid-row: 2; }
  .mobile-back { grid-column: 2; grid-row: 3; }

  .mobile-actions {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(7px, env(safe-area-inset-bottom));
    width: 250px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .mobile-actions .mobile-control {
    height: 53px;
    border-radius: 14px;
  }

  .mobile-jump {
    grid-column: auto;
    height: 53px !important;
  }
}

@media (hover: none) and (orientation: landscape) and (max-height: 430px),
       (pointer: coarse) and (orientation: landscape) and (max-height: 430px) {
  .mobile-controls { height: 140px; }
  .mobile-dpad {
    width: 118px;
    height: 118px;
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(3, 36px);
    gap: 5px;
  }
  .mobile-actions { width: 226px; gap: 5px; }
  .mobile-actions .mobile-control,
  .mobile-jump { height: 43px !important; }
  .mobile-symbol { font-size: 18px; }
  .mobile-action-main { font-size: 10px; }
  .mobile-label { font-size: 7px; margin-top: 2px; }
  .touch-ui .hud { max-height: 67px; }
}

/* Loading panel also stays inside portrait / landscape phone viewports. */
@media (hover: none), (pointer: coarse) {
  .loading-panel {
    width: min(560px, calc(100% - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

/* Extra-small portrait phones and camera button footprint. */
@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  .mobile-camera {
    grid-column: 1 / -1;
    height: 42px !important;
  }
}

@media (hover: none) and (orientation: portrait) and (max-width: 350px),
       (pointer: coarse) and (orientation: portrait) and (max-width: 350px) {
  .mobile-dpad {
    width: 116px;
    height: 116px;
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(3, 36px);
    gap: 4px;
  }
  .mobile-actions {
    width: 146px;
    gap: 4px;
  }
  .mobile-actions .mobile-control { height: 44px; }
  .mobile-jump { height: 48px !important; }
  .mobile-camera { height: 38px !important; }
  .mobile-symbol { font-size: 18px; }
  .mobile-action-main { font-size: 9px; }
  .mobile-label { font-size: 6.5px; }
}
