:root {
  --orange: #e4741d;
  --orange-deep: #c85f12;
  --green: #3b7a57;
  --crust: #e8b872;
  --cream: #fbefd8;
  --ink: #2a2018;
  --bg: #1c140e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
}
body {
  font-family:
    system-ui,
    -apple-system,
    "Apple SD Gothic Neo",
    sans-serif;
  background: var(--bg);
  color: var(--cream);
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.screen.active {
  display: flex;
}

/* 시작 */
.logo-mark {
  position: relative;
  margin-bottom: 8px;
  line-height: 0;
}
.logo-mark img {
  width: 96px;
  height: 96px;
  filter: drop-shadow(0 0 18px rgba(228, 116, 29, 0.45));
}
.logo-mark .badge {
  position: absolute;
  right: -6px;
  bottom: 4px;
  background: var(--green);
  color: var(--cream);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 2px solid var(--bg);
}
h1 {
  font-size: 34px;
  line-height: 1.2;
  color: var(--orange);
  text-shadow: 0 0 24px rgba(228, 116, 29, 0.35);
}
h1 span {
  color: var(--cream);
  font-size: 24px;
}
.tag {
  margin: 16px 0 32px;
  color: var(--crust);
}
.fine {
  margin-top: 20px;
  font-size: 12px;
  color: #8a7a66;
}

/* 버튼 */
.btn {
  border: none;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 700;
  padding: 14px 34px;
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: var(--orange);
  color: #2a1a08;
}

/* 인트로 컷신 */
#introScreen {
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}
.intro-stage {
  position: absolute;
  inset: 0;
}
/* 바 뒤 벽 — 선반 바틀 + 맥주탭 + 테라조까지 한 장면 (화면 꽉 채움) */
.bar-wall {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #faf6ee url("assets/intro-scene-bg.png") center / cover no-repeat;
}
.boss {
  position: absolute;
  bottom: 41%; /* JS가 위치별 사선 높이로 덮어씀 (bossBottom) */
  left: 50%;
  width: 62%;
  max-width: 290px;
  height: auto;
  z-index: 2;
  opacity: 0;
  transform: translate(-50%, 120%);
  transition:
    left 0.45s cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.35s ease,
    filter 0.3s ease;
  will-change: transform, left, opacity;
  pointer-events: none;
}
/* 바 카운터 (전경 — 테라조 상판만 투명 레이어, 사장님 하반신을 가림)
   .bar-wall과 동일한 프레임 크기 + center/cover 라 테라조가 항상 정확히 겹침 */
.bar-counter {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: center / cover no-repeat url("assets/intro-scene-front.png");
  pointer-events: none;
}
/* 하단 게임 대사 박스 (화면 하단 가로 고정) */
.intro-box {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 20px;
  margin: 0 auto;
  max-width: 420px;
  z-index: 4;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 16px 20px 30px;
  box-shadow: 0 6px 0 rgba(58, 42, 26, 0.18);
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  pointer-events: none;
}
.intro-box.active {
  opacity: 1;
  transform: translateY(0);
}
.intro-box-text {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
  text-align: left;
  min-height: 1.5em;
  white-space: pre-wrap;
}
.intro-cont {
  position: absolute;
  right: 16px;
  bottom: 8px;
  font-size: 13px;
  color: #8a7a66;
  pointer-events: none;
  animation: tapPulse 1.2s ease-in-out infinite;
  transition: opacity 0.15s ease;
}
.intro-box.typing .intro-cont {
  opacity: 0;
}
@keyframes tapPulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.9;
  }
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.1);
  color: var(--cream);
}
.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* 게임 */
#gameScreen {
  padding: 0;
  justify-content: flex-start;
}
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 16px 18px;
  pointer-events: none;
}
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
#roundLabel {
  font-weight: 700;
  color: var(--orange);
  font-size: 18px;
}
#timer {
  font-weight: 800;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}
#timer.danger {
  color: #ff5a4d;
}
#orderText {
  margin-top: 4px;
  color: var(--crust);
  font-size: 15px;
}

#game {
  width: 100%;
  height: 100dvh;
  display: block;
  touch-action: none;
}

.bubble {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  background: var(--cream);
  color: var(--ink);
  padding: 14px 20px;
  border-radius: 18px;
  max-width: 80%;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.bubble.active {
  opacity: 1;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 40px;
  border: 8px solid transparent;
  border-top-color: var(--cream);
}

#doneBtn {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: var(--cream);
  z-index: 6;
}
#doneBtn:active {
  transform: translateX(-50%) scale(0.96);
}

/* 라운드 점수 팝업 */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: flex-end;
  justify-content: center;
  /* 위쪽(피자/표정)은 비우고 아래쪽만 딤 처리 */
  background: linear-gradient(
    to top,
    rgba(20, 14, 8, 0.9) 0%,
    rgba(20, 14, 8, 0.85) 32%,
    rgba(20, 14, 8, 0) 58%
  );
}
.overlay.active {
  display: flex;
}
.rs-card {
  background: var(--ink);
  border: 2px solid var(--orange);
  border-radius: 20px;
  padding: 18px 24px;
  margin: 0 16px 40px;
  width: calc(100% - 32px);
  max-width: 420px;
  /* 가로로 넓은 카드: [공평도/점수 | 보너스/코멘트], 힌트는 하단 전폭 */
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 20px;
  row-gap: 8px;
  text-align: left;
  animation: pop 0.18s ease-out;
}
.rs-main {
  text-align: center;
  padding-right: 20px;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}
.rs-side {
  min-width: 0;
}
.rs-hint {
  grid-column: 1 / -1;
  text-align: center;
}
@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.rs-fair {
  color: var(--crust);
  font-size: 16px;
}
.rs-fair b {
  color: var(--cream);
  font-size: 22px;
}
.rs-score {
  color: var(--orange);
  font-size: 56px;
  font-weight: 800;
  margin: 6px 0;
}
.rs-bonus {
  color: var(--green);
  font-weight: 700;
  height: 22px;
}
.rs-comment {
  margin-top: 10px;
  color: var(--cream);
  font-size: 15px;
}
.rs-hint {
  margin-top: 16px;
  font-size: 12px;
  color: #8a7a66;
}

/* 결과 */
h2 {
  font-size: 40px;
  color: var(--green);
}
.comment {
  margin: 8px 0 20px;
  color: var(--crust);
}
.total {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 20px;
}
.total b {
  font-size: 72px;
  color: var(--orange);
}
.total span {
  font-size: 18px;
  color: var(--crust);
}
.bars {
  width: 100%;
  max-width: 340px;
  margin-bottom: 20px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 13px;
}
.bar-row span {
  width: 78px;
  text-align: left;
  color: var(--crust);
}
.bar-row b {
  width: 34px;
  text-align: right;
}
.bar {
  flex: 1;
  height: 14px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  overflow: hidden;
}
.bar .fill {
  height: 100%;
  background: var(--orange);
}

.nick-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
#nickInput {
  flex: 1;
  padding: 12px 16px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--cream);
  font-size: 16px;
}
#nickInput::placeholder {
  color: #8a7a66;
}

/* 랭킹 */
.rank-list {
  width: 100%;
  max-width: 360px;
  max-height: 60dvh;
  overflow-y: auto;
  margin-bottom: 16px;
}
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
}
.rank-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}
.rank-row.me {
  background: rgba(242, 140, 40, 0.2);
}
.rank-row .rk {
  width: 32px;
  font-weight: 800;
  color: var(--orange);
}
.rank-row .nm {
  flex: 1;
  text-align: left;
}
.rank-row b {
  font-variant-numeric: tabular-nums;
}
