* { box-sizing: border-box; }

:root {
  --bg: #1a1a2e;
  --panel: #2b2b4a;
  --panel-light: #3a3a5c;
  --ink: #f4f4f8;
  --accent: #ffcb3d;   /* 노랑 */
  --accent2: #ff6b6b;  /* 빨강 */
  --green: #7bd88f;
  --wood: #b5744a;     /* 선반 나무색 */
  --wood-dark: #7c4a2a;
  --sky: #9fe3ff;      /* 창문 하늘색 */
  --line: #000;
  /* 픽셀 글꼴: 한글 Galmuri, 영문/숫자 Press Start 2P */
  --pixel: "Galmuri11", "Press Start 2P", "DungGeunMo", monospace;
  /* 화면 크기에 따라 자동으로 커지는 기준 글자 크기 */
  --fs: clamp(16px, 3.4vw, 22px);
}

html { font-size: var(--fs); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 24px);
  font-family: var(--pixel);
  background-color: var(--bg);
  background-image:
    linear-gradient(45deg, #20203a 25%, transparent 25%, transparent 75%, #20203a 75%),
    linear-gradient(45deg, #20203a 25%, transparent 25%, transparent 75%, #20203a 75%);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
  color: var(--ink);
  image-rendering: pixelated;
  line-height: 1.6;
}

/* 각진 픽셀 카드 (배경을 담는 틀) */
.card {
  position: relative;
  width: 100%;
  max-width: 480px;          /* 폰 기본 */
  background: var(--panel);
  border: 5px solid var(--line);
  box-shadow: 10px 10px 0 var(--line);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== 매점 내부 배경 ===== */
.shop { display: flex; flex-direction: column; }

/* --- 위쪽 상시 메뉴판 --- */
.board {
  background: #3b2a1a;
  border-bottom: 5px solid var(--line);
  padding: 0.7em 0.7em 0.8em;
}
.board-title {
  font-size: 0.95em;
  color: var(--accent);
  text-align: center;
  margin-bottom: 0.6em;
  text-shadow: 2px 2px 0 var(--line);
}
.menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4em;
}
.menu li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.5em 0.6em;
  background: #fff;
  color: #1a1a2e;
  border: 3px solid var(--line);
  font-size: 0.8em;
}
.m-emoji { font-size: 1.4em; }
.m-name { flex: 1; text-align: left; }
.m-price { color: #c0392b; font-weight: bold; }
.menu li.new-item { background: #fff3c4; border-color: var(--accent2); }
.m-new {
  position: absolute;
  top: -0.6em;
  right: -0.3em;
  background: var(--accent2);
  color: #fff;
  font-size: 0.6em;
  padding: 0.15em 0.3em;
  border: 2px solid var(--line);
}

/* --- 매점 내부 (창문/선반/냉장고) --- */
.interior {
  display: flex;
  padding: 0;
  min-height: 15em;
  background: #caa36f; /* 매점 내부 벽(나무톤) */
}

/* ===== 매점 카운터 장면 ===== */
.counter-scene {
  position: relative;
  flex: 1;
  min-height: 15em;
  overflow: hidden;
}

/* 뒤쪽 벽 진열 (창문 + 빵 선반) */
.backwall {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52%;
  display: flex;
  align-items: stretch;
  gap: 0.4em;
  padding: 0.5em;
  background: linear-gradient(#d8c4a0, #c9b188);
}
.bw-window {
  flex: 1;
  border: 4px solid var(--line);
  box-shadow: inset 0 0 0 3px #fff;
  /* 창밖 하늘 + 운동장 */
  background:
    linear-gradient(#aee6ff 0%, #cdeeff 55%, transparent 55%),
    linear-gradient(#7ec850 70%, #6ab33f 70%);
  background-color: #cdeeff;
  position: relative;
}
.bw-window::after { /* 해 */
  content: "☀️";
  position: absolute;
  top: 0.2em;
  right: 0.3em;
  font-size: 0.9em;
}

/* 손님(교복 학생): 카운터 뒤에 상체까지 서 있음 */
.customer {
  position: absolute;
  left: 50%;
  bottom: 2.6em;            /* 카운터 상판 위로 상체가 올라오게 */
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 3;
}
.customer .bubble { margin-bottom: 0.5em; }
.customer.enter { animation: comeIn 0.45s ease-out; }
@keyframes comeIn {
  from { transform: translate(140px, 0); opacity: 0; }  /* 오른쪽에서 들어옴 */
  to   { transform: translate(-50%, 0);  opacity: 1; }
}
.customer.leave { animation: goOut 0.35s ease-in forwards; }
@keyframes goOut {
  from { transform: translate(-50%, 0);   opacity: 1; }
  to   { transform: translate(-220px, 0); opacity: 0; }  /* 왼쪽으로 사라짐 */
}

/* ===== 교복 입은 학생 캐릭터 (CSS 도트) ===== */
.student {
  --hair: #2b1a0e;
  --skin: #ffd9b3;
  --uniform: #3a4a7a;
  position: relative;
  width: 6em;
  display: flex;
  flex-direction: column;
  align-items: center;
}
/* 머리카락 (정수리 + 옆머리로 얼굴을 살짝 감쌈) */
.st-hair {
  position: relative;
  width: 3.9em;
  height: 1.9em;
  background: var(--hair);
  border: 3px solid var(--line);
  border-bottom: none;
  border-radius: 2em 2em 0.6em 0.6em;
  margin-bottom: -1em;
  z-index: 2;
}
/* 옆머리(얼굴 양옆 구레나룻) */
.st-hair::before,
.st-hair::after {
  content: "";
  position: absolute;
  bottom: -0.6em;
  width: 0.55em;
  height: 1em;
  background: var(--hair);
  border: 3px solid var(--line);
}
.st-hair::before { left: -0.15em; border-radius: 0.4em 0 0 0.4em; }
.st-hair::after  { right: -0.15em; border-radius: 0 0.4em 0.4em 0; }
/* 얼굴 */
.st-face {
  position: relative;
  width: 3.4em;
  height: 3em;
  background: var(--skin);
  border: 3px solid var(--line);
  border-radius: 1.4em 1.4em 1.2em 1.2em;
  z-index: 1;
}
.st-eye {
  position: absolute;
  top: 1.3em;
  width: 0.4em;
  height: 0.5em;
  background: #1a1a1a;
  border-radius: 50%;
}
.st-eye.left { left: 0.8em; }
.st-eye.right { right: 0.8em; }
.st-mouth {
  position: absolute;
  bottom: 0.5em;
  left: 50%;
  transform: translateX(-50%);
  width: 1em;
  height: 0.35em;
  border-bottom: 3px solid #a0522d;
  border-radius: 0 0 1em 1em;
}
/* 교복 상의 + 어깨 */
.st-body {
  position: relative;
  width: 5em;
  height: 2.6em;
  background: var(--uniform);
  border: 3px solid var(--line);
  border-radius: 1.4em 1.4em 0 0;
  margin-top: -0.3em;
}
/* 하얀 카라(깃) */
.st-collar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 1.1em solid transparent;
  border-right: 1.1em solid transparent;
  border-top: 1em solid #fff;
}
/* 넥타이 */
.st-tie {
  position: absolute;
  top: 0.1em;
  left: 50%;
  transform: translateX(-50%);
  width: 0.5em;
  height: 1.3em;
  background: #c0392b;
  border: 2px solid var(--line);
  clip-path: polygon(50% 0, 100% 20%, 50% 100%, 0 20%);
  z-index: 1;
}

/* 앞쪽 계산대(카운터) */
.counter {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 4;
}
.counter-top {
  height: 0.9em;
  background: linear-gradient(#e0b483, #c9975a);
  border: 4px solid var(--line);
  border-radius: 4px 4px 0 0;
}
.counter-front {
  height: 2.4em;
  background: repeating-linear-gradient(90deg, #a9703c 0 1.6em, #9a6433 1.6em 3.2em);
  border: 4px solid var(--line);
  border-top: none;
}

/* 정답 시 카운터 위에 내려놓는 음식 자리 */
.served-items {
  position: absolute;
  bottom: 4.4em;          /* 소품보다 살짝 위, 학생 앞 */
  left: 0; right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.5em;
  height: 2em;
  z-index: 6;
  pointer-events: none;
}
.served-item {
  font-size: 1.8em;
  filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.3));
  animation: dropItem 0.35s ease-out both;
}
/* 위에서 톡 떨어지는 느낌 */
@keyframes dropItem {
  0%   { transform: translateY(-1.2em); opacity: 0; }
  70%  { transform: translateY(0.15em); opacity: 1; }
  100% { transform: translateY(0); }
}

/* 상판 위 소품들 (포스기 / 계산기 / 카드 단말기) */
.counter-items {
  position: absolute;
  bottom: 2.9em;          /* counter-top 바로 위 */
  left: 0; right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1.4em;
  z-index: 5;
}
/* 카드 포스기 (화면 + 키패드) */
.pos {
  width: 2.2em;
  background: #4a4a5a;
  border: 3px solid var(--line);
  border-radius: 3px 3px 2px 2px;
  padding: 0.15em;
}
.pos-screen {
  height: 0.7em;
  background: #8fe3c0;
  border: 2px solid var(--line);
  margin-bottom: 0.15em;
}
.pos-keys {
  height: 0.9em;
  background: repeating-linear-gradient(90deg, #cfcfe0 0 0.35em, #4a4a5a 0.35em 0.45em);
  border: 2px solid var(--line);
}
/* 계산기 (노란 화면 + 키) */
.calc {
  width: 1.8em;
  background: #2a2a3a;
  border: 3px solid var(--line);
  border-radius: 2px;
  padding: 0.15em;
}
.calc-screen {
  height: 0.6em;
  background: #f4e04d;
  border: 2px solid var(--line);
  margin-bottom: 0.15em;
}
.calc-keys {
  height: 1em;
  background:
    repeating-linear-gradient(90deg, #d0d0d8 0 0.3em, #2a2a3a 0.3em 0.4em),
    repeating-linear-gradient(0deg, #d0d0d8 0 0.3em, #2a2a3a 0.3em 0.4em);
  border: 2px solid var(--line);
}
/* 카드 단말기 (카드 꽂는 슬롯 + 카드) */
.cardreader {
  position: relative;
  width: 1.6em;
  height: 1.9em;
  background: #3a5a8a;
  border: 3px solid var(--line);
  border-radius: 3px;
}
.cr-slot {
  position: absolute;
  top: 0.3em; left: 50%;
  transform: translateX(-50%);
  width: 1em; height: 0.25em;
  background: #15152a;
  border: 2px solid var(--line);
}
.cr-card {
  position: absolute;
  top: -0.5em; left: 50%;
  transform: translateX(-50%);
  font-size: 0.8em;
}

/* ===== 배경 위에 겹치는 화면들 (시작/결과) ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1em;
  text-align: center;
  background: rgba(26, 26, 46, 0.85);
  z-index: 8;
}
/* 시작 화면은 뒤(학생/카운터)가 안 비치게 꽉 채움 */
#start-screen {
  background: #1a1a2e;
  background-image:
    linear-gradient(45deg, #20203a 25%, transparent 25%, transparent 75%, #20203a 75%),
    linear-gradient(45deg, #20203a 25%, transparent 25%, transparent 75%, #20203a 75%);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
}

/* ===== 교시 전환(클리어) 화면 ===== */
#transition-screen { background: rgba(26, 26, 46, 0.92); z-index: 9; }
.trans-box { display: flex; flex-direction: column; align-items: center; gap: 0.8em; }
.trans-clear {
  margin: 0;
  font-size: 1.5em;
  color: var(--green);
  text-shadow: 3px 3px 0 var(--line);
  animation: popIn 0.4s ease-out both;
}
.trans-next {
  margin: 0;
  font-size: 1.1em;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--line);
  animation: slideUp 0.5s ease-out 0.3s both;
}
/* 다음 스테이지 새 메뉴 안내 박스 */
.trans-newmenu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
  padding: 0.7em 1em;
  background: #2b2b4a;
  border: 3px solid var(--line);
  box-shadow: 4px 4px 0 var(--line);
  animation: slideUp 0.5s ease-out 0.5s both;
}
.nm-title { font-size: 0.7em; color: var(--accent2); }
.nm-item {
  font-size: 0.85em;
  color: #fff;
  background: #3a3a5c;
  border: 2px solid var(--line);
  padding: 0.3em 0.6em;
}
/* "클리어!" 튀어나오기 */
@keyframes popIn {
  0%   { transform: scale(0.3); opacity: 0; }
  70%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
/* "다음은.." 아래서 올라오기 */
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* 큰 게임 제목 */
.title {
  margin: 0 0 0.6em;
  font-size: 1.8em;
  line-height: 1.5;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--line), 6px 6px 0 var(--accent2);
}
h2 {
  margin: 0 0 0.5em;
  font-size: 1.3em;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--line);
}
.desc { font-size: 0.85em; color: #e4e4f4; margin: 0.6em 0 1em; }
.desc b { color: var(--accent); }

.best-top { margin: 0 0 0.8em; font-size: 1em; color: var(--ink); }
.best-top span { color: var(--accent); }
.best { font-size: 0.95em; color: var(--accent); margin: 1em 0; }

/* 픽셀 버튼 */
.big-btn {
  width: 100%;
  max-width: 18em;
  margin-top: 0.6em;
  padding: 0.8em;
  border: 4px solid var(--line);
  background: var(--accent);
  color: #2b2b1a;
  font-family: var(--pixel);
  font-size: 0.95em;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--line);
}
.big-btn:active { transform: translate(5px, 5px); box-shadow: none; }
.big-btn.ghost { background: var(--panel-light); color: var(--ink); }
.start-big { font-size: 1.15em; padding: 0.9em; background: var(--green); color: #123; }

/* 게임 중 상단 상태 바 */
.status {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  padding: 0.5em;
  background: var(--panel);
  border-bottom: 5px solid var(--line);
}
/* 윗줄: 교시 / 손님 / 하트 */
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.3em;
  font-size: 0.62em;
  padding: 0.35em 0.6em;
  background: var(--panel-light);
  border: 3px solid var(--line);
}
.status-row span { white-space: nowrap; }
#period { color: var(--accent); }
#guests { color: #cfe0ff; }

/* 타이머 가로 바 */
.timer-bar {
  position: relative;
  height: 1.2em;
  background: #15152a;
  border: 3px solid var(--line);
  overflow: hidden;
}
/* 노란색 채움: 남은 시간 비율만큼. 1초마다 부드럽게 줄어듦 */
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(var(--accent), #e8a400);
  transition: width 1s linear;
}
.timer-fill.warn { background: linear-gradient(var(--accent2), #c0392b); }
/* 바 위에 겹쳐 보이는 남은 시간 숫자 */
.timer-text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.6em;
  line-height: 1.9;
  color: #1a1a2e;
  text-shadow: 0 0 2px rgba(255,255,255,0.6);
}
.timer-text.warn { color: #fff; text-shadow: 1px 1px 0 #000; }
@keyframes blink { 50% { opacity: 0.3; } }

/* 손님 말풍선 */
.bubble {
  position: relative;
  min-width: 7em;
  max-width: 11em;
  min-height: 2.6em;
  padding: 0.6em 0.8em;
  background: var(--ink);
  color: #1a1a2e;
  border: 4px solid var(--line);
  font-size: 0.85em;
  line-height: 1.6;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--line);
}

/* ===== 맨 아래 총 가격 입력 + 숫자 키패드 ===== */
/* 배경을 가리지 않도록 겹치지 않고 아래에 자연스럽게 붙는다 */
.pay-bar {
  padding: 0.7em;
  background: var(--panel);
  border-top: 5px solid var(--line);
}
.pay-display { margin-bottom: 0.6em; }
#answer {
  width: 100%;
  padding: 0.7em;
  border: 4px solid var(--line);
  background: #fff;
  color: #1a1a2e;
  font-family: var(--pixel);
  font-size: 1.3em;
  text-align: center;
  caret-color: transparent; /* 키패드로만 입력 */
}
#answer:focus { outline: none; background: #fffbe6; }

/* 숫자 키패드 (3열) */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5em;
}
.key {
  padding: 0.7em 0;
  border: 4px solid var(--line);
  background: var(--ink);
  color: #1a1a2e;
  font-family: var(--pixel);
  font-size: 1.3em;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--line);
}
.key:active { transform: translate(4px, 4px); box-shadow: none; }
.key-del { background: var(--accent2); color: #fff; }
.key-ok { background: var(--green); color: #123; }

/* 정답/오답 안내 */
.feedback { min-height: 1.3em; margin: 0 0 0.5em; font-size: 0.85em; text-align: center; }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--accent2); }

/* ===== 반응형: 태블릿 / PC ===== */
/* 태블릿: 카드 넓게 */
@media (min-width: 700px) {
  :root { --fs: clamp(20px, 2.4vw, 26px); }
  .card { max-width: 640px; }
}
/* PC: 더 넓게, 기준 글자도 키움 */
@media (min-width: 1100px) {
  :root { --fs: 26px; }
  .card { max-width: 760px; }
}

/* ===== 게임 시작 로딩(인트로) 화면 ===== */
.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6em;
}
.load-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: 1.8em;
  color: #e8710a;
  text-shadow: 3px 3px 0 #ffcb3d;
  text-align: center;
}
/* 노란 바가 담기는 틀 */
.load-bar {
  width: 70%;
  max-width: 18em;
  height: 1.4em;
  background: #f0f0f0;
  border: 4px solid var(--line);
  overflow: hidden;
}
/* 3초에 걸쳐 0% -> 100% 차오르는 노란 바 */
.load-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(var(--accent), #e8a400);
  animation: loadFill 3s linear forwards;
}
@keyframes loadFill {
  from { width: 0; }
  to   { width: 100%; }
}
/* 다 차오른 뒤 페이드아웃 (JS가 fade 클래스를 붙인다) */
.loading.fade {
  animation: loadFade 0.6s ease forwards;
}
@keyframes loadFade {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; }
}
.loading.gone { display: none; }

/* ===== 기록 보기 팝업 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  background: rgba(0, 0, 0, 0.6);
}
.modal.hidden { display: none; }
.modal-box {
  width: 100%;
  max-width: 18em;
  background: var(--panel);
  border: 5px solid var(--line);
  box-shadow: 8px 8px 0 var(--line);
  padding: 1em;
  text-align: center;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8em;
}
.modal-title {
  font-size: 0.9em;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--line);
}
.x-btn {
  border: 3px solid var(--line);
  background: var(--accent2);
  color: #fff;
  font-family: var(--pixel);
  font-size: 0.8em;
  width: 2em;
  height: 2em;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line);
}
.x-btn:active { transform: translate(2px, 2px); box-shadow: none; }
/* 큰 기록 숫자 */
.record-big {
  margin: 0.3em 0;
  font-size: 2.6em;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--line);
}
.record-unit { font-size: 0.4em; color: var(--ink); margin-left: 0.2em; }
.record-note {
  font-size: 0.7em;
  color: #cfcfe8;
  line-height: 1.6;
  margin: 0.6em 0 0;
}
