* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  color: #3a2b1e;
  background: #fff6e5;
  overflow: hidden;
}

[hidden] { display: none !important; }

#game {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── 상단 정보 ── */
#hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 12px;
  background: #fffdf8;
  border-bottom: 2px solid #f0dfc4;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 13px;
}

.hud-item .label { color: #a08a6f; }
.hud-item strong { font-size: 16px; }

#quitBtn {
  margin-left: auto;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  color: #8a6a4a;
  background: #fff;
  border: 1.5px solid #e3cfae;
  border-radius: 999px;
  cursor: pointer;
}

#quitBtn:hover { border-color: #ff8442; color: #d2622a; }

/* ── 놀이 영역 ── */
#field {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(160deg, #fff3dc, #ffe7ef);
  touch-action: manipulation;
}

#game[data-category="음료수"] #field { background: linear-gradient(160deg, #eaf6ff, #e2edff); }
#game[data-category="과자"] #field { background: linear-gradient(160deg, #fff4e2, #ffe8cd); }
#game[data-category="아이스크림"] #field { background: linear-gradient(160deg, #ffeef7, #f2ecff); }

/* ── 시작 화면에 떠다니는 간식 장식 ── */
#floatLayer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* 장식 위에 제목·버튼이 오도록 한다. */
#startScreen > *:not(#floatLayer) {
  position: relative;
  z-index: 1;
}

.float-item {
  position: absolute;
  display: block;
  width: clamp(52px, 9.5vw, 100px);
  opacity: 0.96;
  animation: float-drift var(--drift, 24s) ease-in-out infinite alternate;
  will-change: transform;
}

.float-item img {
  display: block;
  width: 100%;
  height: auto;
  animation: float-bob var(--bob, 5.5s) ease-in-out infinite alternate;
}

.float-item--ice-cream { left: 2%; top: 9%; --dx: 26px; --dy: -22px; --drift: 21s; --bob: 5s; }
.float-item--chocolate { left: 42%; top: 5%; --dx: -20px; --dy: 20px; --drift: 22s; --bob: 5.2s; }
.float-item--drink { left: 82%; top: 4%; --dx: -30px; --dy: 26px; --drift: 27s; --bob: 6.4s; }
.float-item--chips { left: 2%; top: 66%; --dx: 34px; --dy: 18px; --drift: 24s; --bob: 5.8s; }
.float-item--cookie { left: 80%; top: 60%; --dx: -22px; --dy: -28px; --drift: 19s; --bob: 4.6s; }
.float-item--drink-bottle { left: 43%; top: 72%; --dx: 24px; --dy: -22px; --drift: 23s; --bob: 5.4s; }

@keyframes float-drift {
  from { transform: translate(0, 0); }
  to { transform: translate(var(--dx, 20px), var(--dy, -20px)); }
}

@keyframes float-bob {
  from { transform: translateY(-7px) rotate(-5deg); }
  to { transform: translateY(7px) rotate(5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .float-item,
  .float-item img { animation: none; }
}

#wordLayer {
  position: absolute;
  inset: 0;
}

.word {
  position: absolute;
  left: 0;
  top: 0;
  padding: 8px 16px;
  font-size: clamp(15px, 2.4vw, 26px);
  font-weight: 700;
  white-space: nowrap;
  color: #5a4128;
  background: #ffffff;
  border: 2px solid #e0c9a6;
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(120, 90, 50, 0.12);
  pointer-events: none;
  user-select: none;
  will-change: transform;
}

.word-text {
  display: inline-block;
  transition: transform 0.18s ease, color 0.18s ease;
}

#game[data-category="음료수"] .word { border-color: #9ac8e8; color: #1f6290; }
#game[data-category="과자"] .word { border-color: #eec383; color: #8c5312; }
#game[data-category="아이스크림"] .word { border-color: #efb2d0; color: #9c2f66; }

.word.target {
  background: #ffe9a3;
  border-color: #ff8442;
  box-shadow: 0 0 0 3px rgba(255, 132, 66, 0.25);
}

/* 다 입력한 단어: Enter 또는 Space 로 완성하는 '확인 대기' 상태 */
#game .word.ready {
  background: #dcf6d6;
  border-color: #46a054;
  color: #1f6b34;
  box-shadow: 0 0 0 3px rgba(70, 160, 84, 0.3);
  animation: ready-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes ready-pulse {
  from { box-shadow: 0 0 0 2px rgba(70, 160, 84, 0.22); }
  to { box-shadow: 0 0 0 8px rgba(70, 160, 84, 0.34); }
}

.word.hit {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.word.hit .word-text {
  transform: scale(1.45);
  color: #ff6b1a;
}

/* ── 입력창 ── */
.input-wrap {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(460px, 86%);
  z-index: 3;
}

.type-input {
  width: 100%;
  padding: 12px 18px;
  font: inherit;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  text-align: center;
  /* 한글 조합을 그대로 유지하기 위해 입력창 글자는 숨기고 미리보기로 보여준다. */
  color: transparent;
  caret-color: transparent;
  background: rgba(255, 255, 255, 0.95);
  border: 2px dashed #dcc4a0;
  border-radius: 14px;
  outline: none;
}

.type-input::placeholder { color: transparent; }

.type-input:focus { border-style: solid; border-color: #ff8442; }
.type-input.miss { border-color: #e0574b; background: #ffecea; }

/* 오타 표시: 입력을 지우지 않고 색과 흔들림으로만 알려 준다. */
.typed-preview.miss {
  color: #cf3b2f;
  animation: miss-shake 0.24s ease;
}

.typed-preview.miss .caret { background: #cf3b2f; }

@keyframes miss-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.typed-preview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  color: #3a2b1e;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
}

.typed-preview .typed-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.typed-preview.is-empty .typed-text::before {
  content: "간식 이름을 입력하세요";
  color: #c0ab90;
  font-weight: 600;
}

.typed-preview .caret {
  flex: none;
  width: 2px;
  height: 1.15em;
  margin-left: 2px;
  background: #ff8442;
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes caret-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ── 안내 문구 ── */
.notice {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  color: #8a4b12;
  background: #fff3d2;
  border: 1.5px solid #edcd8a;
  border-radius: 999px;
  z-index: 4;
}

/* ── 시작 화면 ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 18px;
  text-align: center;
  /* 시작·게임 오버 화면 배경은 불투명하게 둔다. 장식은 시작 화면 안에만 넣는다. */
  background: #fff6e5;
  overflow-y: auto;
}

.overlay h1.title-logo {
  display: flex;
  justify-content: center;
  width: 100%;
}

.overlay h1.title-logo img {
  display: block;
  width: min(320px, 82%);
  height: auto;
}

.overlay h1, .overlay h2 {
  margin: 0;
  font-size: clamp(22px, 3.4vw, 34px);
}

.lead {
  margin: 0;
  max-width: 34em;
  font-size: 15px;
  line-height: 1.6;
  color: #6b5540;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.category {
  padding: 14px 26px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: #3a2b1e;
  background: #ffffff;
  border: 2px solid #e0c9a6;
  border-radius: 16px;
  cursor: pointer;
}

.category:hover:not(:disabled) { border-color: #ff8442; background: #fff6e8; }
.category:disabled { opacity: 0.45; cursor: not-allowed; }

.overlay button:not(.category) {
  padding: 12px 28px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: #ff8442;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.overlay button:not(.category):hover { background: #f06f2b; }

.status {
  margin: 0;
  max-width: 36em;
  font-size: 14px;
  line-height: 1.6;
  color: #7a6350;
}
