@font-face {
  font-family: "CuteFantasy";
  src: url("assets/ui/font.ttf");
  font-display: block;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  background: #0d0b14;
  overflow: hidden;
  font-family: "CuteFantasy", monospace;
  color: #f4e9d8;
  -webkit-font-smoothing: none;
  cursor: default;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

/* 뷰포트: 월드 오버스캔 여백을 잘라내는 클리핑 창 (크기는 JS에서 지정) */
#viewport {
  position: relative;
  overflow: hidden;
  background: #1a2b1a;
}

/* 월드/HUD 캔버스는 뷰포트 안에 겹쳐 배치 (위치·크기는 JS에서 지정) */
#game, #ui {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}
#game { will-change: transform; }  /* 서브픽셀 스크롤: 합성 레이어로 승격 */
#ui { pointer-events: none; }

/* 시작 / 종료 화면 */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  background: rgba(8, 6, 14, 0.78);
  backdrop-filter: blur(2px);
  z-index: 10;
  overflow-y: auto;                       /* 작은 화면: 스크롤 허용 */
  -webkit-overflow-scrolling: touch;
}

/* 작은 화면(스마트폰): 위 정렬 + 컴팩트 카드로 스크롤 가능하게 */
@media (max-height: 560px) {
  .screen { justify-content: flex-start; padding: 14px 12px 28px; gap: 8px; }
  .screen h1 { font-size: 26px; }
  .screen .sub { font-size: 14px; }
  #classGrid { gap: 8px; max-width: 520px; }
  #classGrid .class-card { padding: 7px 10px; gap: 8px; }
  .class-card .cc-portrait { width: 36px; height: 36px; flex: 0 0 36px; }
  .class-card .cc-name { font-size: 16px; }
  .class-card .cc-desc { font-size: 11px; }
  .help { font-size: 12px; }
}
.screen.hidden { display: none; }
.hidden { display: none !important; }

#continueBtn {
  font-family: inherit;
  font-size: 20px;
  color: #2a1c0c;
  background: #8fe388;
  border: none;
  border-radius: 6px;
  padding: 10px 28px;
  cursor: pointer;
  box-shadow: 0 4px 0 #4f8a4a;
}
#continueBtn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4f8a4a; }

.screen h1 {
  font-size: 40px;
  letter-spacing: 2px;
  color: #ffd86b;
  text-shadow: 0 3px 0 #7a4a12;
}
.screen .sub { font-size: 18px; color: #c9b79c; }

.help {
  margin: 8px 0;
  line-height: 1.9;
  font-size: 15px;
  color: #e8dcc4;
}
.help b { color: #8fe388; }

/* 직업 선택 카드 */
#classGrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 560px;
  margin: 6px 0;
}
#classGrid .class-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: rgba(40, 30, 56, 0.85);
  border: 2px solid #4a3a5e;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: none;
  font-family: inherit;
  transition: transform .06s, border-color .06s, background .06s;
}
#classGrid .class-card:hover {
  transform: translateY(-2px);
  border-color: #ffd86b;
  background: rgba(60, 46, 84, 0.95);
}
#classGrid .class-card:active { transform: translateY(0); }
.class-card .cc-portrait {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  flex: 0 0 48px;
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
}
.class-card .cc-name { font-size: 20px; }
.class-card .cc-desc { font-size: 13px; color: #c9b79c; line-height: 1.35; margin-top: 2px; }

.screen button {
  margin-top: 10px;
  font-family: inherit;
  font-size: 22px;
  color: #2a1c0c;
  background: #ffd86b;
  border: none;
  border-radius: 6px;
  padding: 10px 34px;
  cursor: pointer;
  box-shadow: 0 4px 0 #a9761d;
  transition: transform .05s, box-shadow .05s;
}
.screen button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #a9761d;
}

/* ── 모바일 터치 컨트롤 ── */
#touchUI {
  position: fixed;
  inset: 0;
  pointer-events: none;   /* 게임 탭은 통과, 컨트롤만 받음 */
  z-index: 8;
}
#touchUI.hidden { display: none; }

#joyZone {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(20, 14, 30, 0.35);
  border: 2px solid rgba(202, 161, 90, 0.5);
  pointer-events: auto;
  touch-action: none;
}
#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(202, 161, 90, 0.65);
  border: 2px solid rgba(255, 233, 168, 0.8);
}

#btnCol {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
.tbtn-row { display: flex; gap: 10px; align-items: flex-end; pointer-events: none; }
.tbtn {
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(202, 161, 90, 0.6);
  border-radius: 50%;
  background: rgba(20, 14, 30, 0.45);
  color: #ffe9a8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}
.tbtn:active { background: rgba(202, 161, 90, 0.55); }
.tbtn-sm { width: 46px; height: 46px; font-size: 20px; }
.tbtn-md { width: 60px; height: 60px; font-size: 26px; }
.tbtn-lg { width: 78px; height: 78px; font-size: 34px; }

/* 세로 모드 안내 (터치 기기 + 세로일 때만) */
#rotateHint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 6, 14, 0.92);
  color: #ffe9a8;
  font-size: 22px;
  align-items: center;
  justify-content: center;
  text-align: center;
}
@media (pointer: coarse) and (orientation: portrait) {
  #rotateHint { display: flex; }
}
