* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #ffe9c7 0%, #ffd9a8 100%);
  font-family: "Segoe UI", "Apple SD Gothic Neo", system-ui, sans-serif;
}

#wrap {
  text-align: center;
  padding: 20px;
}

h1 {
  color: #6b4a2f;
  margin: 0 0 12px;
  font-size: 28px;
  text-shadow: 0 2px 0 #fff8ec;
}

#stage {
  position: relative;
  display: inline-block;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  border: 4px solid #fff3de;
  max-width: 100%;
  touch-action: none;
}

canvas {
  display: block;
  background: #cdeafc;
  max-width: 100%;
  height: auto;
}

#wrap:fullscreen,
#wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
#wrap:fullscreen h1,
#wrap:-webkit-full-screen h1 {
  display: none;
}
#wrap:fullscreen #stage,
#wrap:-webkit-full-screen #stage {
  max-width: 100vw;
  max-height: 100vh;
}
#wrap:fullscreen canvas,
#wrap:-webkit-full-screen canvas {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
}

/* Fallback for platforms without real orientation-lock support (iOS Safari): fake
   a landscape, screen-filling layout by rotating the whole page 90deg via CSS. */
html:has(#wrap.forceLandscape), body:has(#wrap.forceLandscape) {
  overflow: hidden !important;
}
#wrap.forceLandscape {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  /* vh/vw fallback first, dvh/dvw override after — mobile browsers with a collapsing
     address bar report vh taller than what's actually visible, which cut the rotated
     layout off; dvh/dvw track the real visible viewport instead. */
  width: 100vh !important;
  height: 100vw !important;
  width: 100dvh !important;
  height: 100dvw !important;
  transform-origin: top left !important;
  transform: rotate(90deg) translateY(-100%) !important;
  background: #000 !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 2000 !important;
  overflow: hidden !important;
}
#wrap.forceLandscape h1 { display: none !important; }
#wrap.forceLandscape #stage {
  max-width: 100vh !important;
  max-height: 100vw !important;
  max-width: 100dvh !important;
  max-height: 100dvw !important;
}
#wrap.forceLandscape canvas {
  max-width: 100vh !important;
  max-height: 100vw !important;
  max-width: 100dvh !important;
  max-height: 100dvw !important;
  width: auto !important;
  height: auto !important;
}

#uiButtons {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 6;
}
#uiButtons button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.6);
  background: rgba(60, 40, 20, 0.4);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#uiButtons button:active { background: rgba(255,157,77,0.55); }

#touchControls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

@media (max-width: 820px), (pointer: coarse) {
  #touchControls { display: block; }
}

#restartBtn {
  display: none;
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%);
  z-index: 7;
  font-size: 16px;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 12px;
  border: none;
  background: #ff9d4d;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #d9782e;
}
#restartBtn.show { display: block; }
#restartBtn:active { transform: translate(-50%, -50%) translateY(2px); box-shadow: 0 2px 0 #d9782e; }

.padCluster, .atkCluster {
  position: absolute;
  /* 화면 맨 아래는 안드로이드 전체화면 알림이 지나가는 자리라 그만큼 띄웁니다 */
  bottom: 10%;
  display: grid;
  gap: 8px;
}
.padCluster {
  left: 2.5%;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 24%;
  max-width: 210px;
  aspect-ratio: 3 / 2;
}
.atkCluster {
  right: 2.5%;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 20%;
  max-width: 176px;
  aspect-ratio: 1 / 1;
}

.padBtn, .atkBtn {
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(255,255,255,0.6);
  background: rgba(60, 40, 20, 0.35);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.padBtn:active, .atkBtn:active { background: rgba(255,157,77,0.55); }

.padUp    { grid-column: 2; grid-row: 1; }
.padLeft  { grid-column: 1; grid-row: 2; }
.padRight { grid-column: 3; grid-row: 2; }
.padDown  { grid-column: 2; grid-row: 2; }

.atkBtn { font-size: 13px; }
.atkW { grid-column: 1; grid-row: 1; }
.atkA { grid-column: 2; grid-row: 1; }
.atkS { grid-column: 1; grid-row: 2; }
.atkD { grid-column: 2; grid-row: 2; }

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  overflow-y: auto;
  padding: 16px;
}

#overlay.hidden { display: none; }

#overlayCard {
  background: #fff8ec;
  border-radius: 18px;
  padding: 24px 32px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  max-width: 380px;
}

#kakaoWarning {
  display: none;
  background: #fff3cd;
  border: 1px solid #e0b84a;
  color: #6b4a2f;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
}
#kakaoWarning.show { display: block; }
#openExternalBtn {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: #e0b84a;
  color: #fff;
  cursor: pointer;
}

#overlayPortrait {
  display: block;
  height: 110px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  margin: 0 auto 6px;
}

#overlayTitle {
  font-size: 22px;
  font-weight: 700;
  color: #6b4a2f;
  margin-bottom: 14px;
}

.charPick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: #7a5a3a;
  margin-bottom: 14px;
}
.charBtn {
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 2px solid #ecd9b8;
  background: #fff;
  color: #7a5a3a;
  cursor: pointer;
}
.charBtn.active {
  border-color: #ff9d4d;
  background: #ffe6cc;
  color: #b8560f;
  font-weight: 700;
}

.controls {
  font-size: 14px;
  color: #7a5a3a;
  line-height: 1.8;
  margin-bottom: 18px;
}

#startBtn {
  font-size: 16px;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: 12px;
  border: none;
  background: #ff9d4d;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #d9782e;
}
#startBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #d9782e; }
#startBtn:disabled {
  background: #ccc;
  box-shadow: 0 4px 0 #999;
  cursor: default;
}

#loading {
  margin-top: 10px;
  color: #7a5a3a;
  font-size: 13px;
}

/* 가로 흉내(#wrap.forceLandscape) 중에는 배지가 #stage 안으로 들어와
   화면과 같이 돌아간다. body 에 붙어 있을 때 쓰던 fixed/top/left 를 덮어써야 한다.
   (game-home.js 가 넣는 규칙에는 !important 가 없어서 이쪽이 이긴다) */
#oreumHome.inStage {
  position: absolute !important;
  top: 6px !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%);
  z-index: 30;
}
