:root {
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
}

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

html, body {
  width: 100dvw;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background-color: #090d16;
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

#game-area,
#ad-area {
  width: 100%;
  overflow: hidden;
}

#game-area {
  position: relative;
  flex: 1;
  height: 100%;
  padding-top: var(--safe-area-inset-top);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
  padding-left: var(--safe-area-inset-left);
}

#ad-area {
  display: none;
  height: 60px;
  margin-top: 10px;
}

@media (min-width: 800px) {
  #ad-area {
    height: 90px;
  }
}

#assets {
  display: none;
}

/* 言語切り替え */
html[lang="ja"] .lang-en,
html:not([lang="ja"]) .lang-ja {
  display: none;
}

/****************************************
** Ad Container
*/

body.has-ad-area {
  padding-bottom: 0;
  padding-bottom: var(--safe-area-inset-bottom);
}

body.has-ad-area #game-area {
  padding-bottom: 0;
}

body.has-ad-area #ad-area {
  display: block;
}

#ad-area .adsbygoogle {
  display: block;
  width: 100%;
  height: 100%;
}

/****************************************
** Screen Switcher
*/

.title-screen,
.game-screen {
  width: 100%;
  height: 100%;
}

body:not(.title-screen-active) .title-screen,
body:not(.game-screen-active) .game-screen {
  display: none;
}

/****************************************
** Title Screen
*/

.title-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 28%, rgba(56, 189, 248, 0.18) 0%, rgba(16, 185, 129, 0.08) 32%, rgba(9, 13, 22, 0.96) 72%),
    #090d16;
}

.title-close-button {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.title-close-button:hover {
  transform: scale(1.06);
  background: rgba(239, 68, 68, 0.95);
}

body:not(.is-web-page) .title-close-button {
  display: none;
}

.title-close-button img {
  width: 22px;
  height: 22px;
  filter: brightness(0) invert(1);
}

.title-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 440px;
  width: 100%;
}

.title-icon-frame {
  width: 152px;
  height: 152px;
  border-radius: 34px;
  overflow: hidden;
  border: 2px solid rgba(56, 189, 248, 0.55);
  box-shadow:
    0 0 36px rgba(56, 189, 248, 0.28),
    0 18px 40px rgba(0, 0, 0, 0.65);
  margin-bottom: 24px;
  background: #090d16;
}

.title-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-eyebrow {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: #38bdf8;
  margin-bottom: 6px;
}

.title-heading {
  font-size: clamp(1.75rem, 5vw, 2.35rem);
  font-weight: 900;
  letter-spacing: 2.5px;
  color: #ffffff;
  text-shadow: 0 0 24px rgba(56, 189, 248, 0.45);
  margin-bottom: 14px;
}

.title-subtitle {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #cbd5e1;
  margin-bottom: 30px;
  max-width: 340px;
}

.title-action-button {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #06121f;
  border: 2px solid rgba(186, 230, 253, 0.75);
  padding: 14px 48px;
  border-radius: 32px;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 0 28px rgba(56, 189, 248, 0.45);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.title-action-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 38px rgba(56, 189, 248, 0.65);
  filter: brightness(1.06);
}

.title-action-button:active {
  transform: translateY(0);
}

/****************************************
** Game Screen
*/

.game-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 54px;
  padding: 0 14px;
  background-color: #0b1120;
  border-bottom: 1px solid rgba(56, 189, 248, 0.2);
  z-index: 20;
}

.game-header-left,
.game-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 96px;
}

.game-header-right {
  justify-content: flex-end;
}

.game-header-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #e2e8f0;
  white-space: nowrap;
}

.sound-button {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.sound-button:hover {
  background: rgba(51, 65, 85, 0.95);
}

.sound-button img {
  width: 18px;
  height: 18px;
  filter: brightness(0) invert(1);
}

body.sound-enabled .sound-button.sound-disabled-button,
body.sound-disabled .sound-button.sound-enabled-button {
  display: none;
}

.game-sub-button {
  background-color: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, transform 0.1s ease;
}

.game-sub-button:hover {
  background-color: #334155;
  transform: translateY(-1px);
}

.game-viewport {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

#canvas-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: none;
}

body.is-dragging #canvas-container {
  cursor: grabbing;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/****************************************
** Game HUD Overlay
*/

.ui-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  z-index: 10;
}

.info-header {
  background: rgba(15, 23, 42, 0.92);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  align-self: flex-start;
  pointer-events: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transition: padding 0.2s ease, border-radius 0.2s ease, background 0.2s ease;
  max-width: 310px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.header-title-wrap {
  display: flex;
  flex-direction: column;
}

.room-tag {
  font-size: 0.72rem;
  letter-spacing: 1.5px;
  color: #38bdf8;
  font-weight: 700;
}

.stage-title {
  font-size: 1.2rem;
  letter-spacing: 1.5px;
  color: #ffffff;
  margin: 0;
  line-height: 1.2;
}

.toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #94a3b8;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

body.panel-minimized .info-header {
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 30px;
}

body.panel-minimized .stage-title {
  font-size: 1rem;
}

body.panel-minimized .header-body {
  display: none;
}

body:not(.panel-minimized) .toggle-icon-closed,
body.panel-minimized .toggle-icon-open {
  display: none;
}

.header-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.status-bar {
  font-size: 0.86rem;
  color: #cbd5e1;
  margin-bottom: 3px;
}

.target-count-value {
  color: #38bdf8;
  font-weight: 700;
}

.header-btns {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-sm {
  background: #334155;
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-sm:hover {
  background: #475569;
  transform: translateY(-1px);
}

/* 扉解放バナー */
.door-opened-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: rgba(16, 185, 129, 0.95);
  border: 2px solid #34d399;
  color: #ffffff;
  padding: 9px 26px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 2px;
  white-space: nowrap;
  box-shadow: 0 0 35px rgba(16, 185, 129, 0.6);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

body.door-unlocked .door-opened-banner {
  transform: translateX(-50%) translateY(0);
}

/* クリアモーダル */
.clear-modal {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid #10b981;
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.4);
  border-radius: 12px;
  padding: 16px 22px;
  text-align: right;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: calc(100% - 32px);
}

body.clear-modal-visible .clear-modal {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.clear-modal-title {
  font-size: 1.25rem;
  color: #10b981;
  margin-bottom: 4px;
}

.clear-modal-text {
  color: #cbd5e1;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.btn-primary {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
  border: none;
  padding: 9px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

/* 画面ホワイトアウト閃光 */
.flash-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, #38bdf8 0%, #ffffff 50%, #ffffff 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
  z-index: 99;
}

body.warp-flash-active .flash-overlay {
  opacity: 1;
  transition: opacity 0.3s ease-in;
}

/* 新フロア開始カットイン */
.room-cutin {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 5px;
  color: #ffffff;
  text-shadow: 0 0 25px rgba(56, 189, 248, 0.9), 0 0 50px rgba(56, 189, 248, 0.5);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1), transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

body.room-cutin-visible .room-cutin {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.05);
}
