* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none;
  background: #1b1712; color: #f3ead8;
  font-family: "DungGeunMo", "Galmuri11", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
#game {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  image-rendering: pixelated; image-rendering: crisp-edges;
  cursor: crosshair; touch-action: none;
}
#hud {
  position: fixed; top: 10px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
#clock {
  background: rgba(20, 16, 12, .72); padding: 6px 10px; border-radius: 6px;
  font-size: 14px; letter-spacing: .5px; white-space: nowrap;
}
#buttons { display: flex; gap: 6px; pointer-events: auto; }
#hud .left { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
#money { background: rgba(20, 16, 12, .72); padding: 4px 10px; border-radius: 6px; font-size: 14px; }
#shop { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(15, 12, 8, .45); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); } /* 휴대폰 조작 버튼보다 위 */
#shop[hidden] { display: none; }
#shop .card { background: #f6ecd6; color: #3a2a18; border-radius: 10px; padding: 16px 18px; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; box-shadow: 0 4px 0 rgba(0,0,0,.35); }
#shop .card .dim { color: #7a6448; }
#shop .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 17px; position: sticky; top: -16px; background: #f6ecd6; padding: 4px 0; z-index: 1; }
#shop .head > b { margin-right: auto; }
#shop .head .close { background: #e7d8bb; color: #3a2a18; width: 34px; height: 34px; border-radius: 50%; padding: 0; font-size: 16px; flex: none; }
@media (max-width: 520px) { #shop .card { padding: 12px; } #shop .head { font-size: 15px; top: -12px; } #shop .item { grid-template-columns: 28px 1fr auto; gap: 8px; padding: 7px 8px; } #shop .ic { font-size: 20px; } }
#shop .items { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#shop .item { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; background: #fff8e8; border-radius: 8px; padding: 8px 10px; }
#shop .ic { font-size: 24px; }
#shop button { background: #b7562f; color: #fff; border: 0; padding: 6px 10px; }
#shop button.on { background: #6b7d3a; }
#shop button.poor { background: #b3a58f; }
#shop .gift { display: flex; gap: 6px; margin-top: 10px; }
#shop .gift input { flex: 1; min-width: 0; font: inherit; padding: 7px 10px; border: 1px solid #d9c7a7; border-radius: 8px; background: #fffaf0; color: #3a2a18; text-transform: uppercase; }
.center { text-align: center; }
button {
  font: inherit; color: inherit; cursor: pointer;
  background: rgba(20, 16, 12, .72); border: 1px solid rgba(243, 234, 216, .25);
  border-radius: 6px; padding: 4px 9px; min-width: 32px;
}
a.btn { font: inherit; color: inherit; text-decoration: none; background: rgba(20, 16, 12, .72); border: 1px solid rgba(243, 234, 216, .25); border-radius: 6px; padding: 4px 9px; min-width: 32px; text-align: center; }
a.btn:hover,
button:hover { background: rgba(60, 48, 34, .85); }
button.on { background: #b7562f; border-color: #e58a5c; }
#prompt {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 16, 12, .72); padding: 6px 12px; border-radius: 6px;
  font-size: 14px; white-space: nowrap; pointer-events: none;
}
#prompt:empty { display: none; }
#toasts {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  background: rgba(250, 240, 214, .94); color: #3a2a18; padding: 7px 14px; border-radius: 8px;
  font-size: 15px; box-shadow: 0 2px 0 rgba(0,0,0,.3);
  animation: toastIn .25s ease-out; transition: opacity .5s;
}
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(-6px); opacity: 0; } }
#debug {
  position: fixed; top: 52px; right: 12px; width: 330px;
  background: rgba(20, 16, 12, .9); border-radius: 8px; padding: 10px; font-size: 13px;
}
#debug .row { margin: 4px 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
#debug button { padding: 2px 7px; font-size: 12px; }
.dim { color: rgba(243, 234, 216, .65); }
.small { font-size: 12px; }
#help {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 12, 8, .55);
}
#help[hidden] { display: none; }
#help .card {
  background: #f6ecd6; color: #3a2a18; border-radius: 10px; padding: 20px 26px; max-width: 460px;
  box-shadow: 0 4px 0 rgba(0,0,0,.35); margin: 16px; max-height: calc(100dvh - 32px); overflow-y: auto;
}
#help .card .dim { color: #7a6448; }
#help h1 { margin: 0 0 6px; font-size: 24px; }
#help table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
#help td { padding: 3px 10px 3px 0; vertical-align: top; }
#help td:first-child { font-weight: bold; white-space: nowrap; color: #8a3a1c; }
#help .start { text-align: center; margin: 12px 0 0; font-weight: bold; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .35; } }

#bubbles { position: fixed; inset: 0; pointer-events: none; }
.bubble {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
  background: #fffdf6; color: #3a2a18; padding: 4px 9px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.bubble[hidden] { display: none; }

#online { background: rgba(20, 16, 12, .72); padding: 4px 10px; border-radius: 6px; font-size: 14px; }
#online[hidden] { display: none; }
#chat {
  position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); width: min(420px, calc(100vw - 32px));
  font: inherit; font-size: 15px; padding: 8px 12px; border-radius: 8px; border: 2px solid #b7562f;
  background: #fffdf6; color: #3a2a18; outline: none;
}
#chat[hidden] { display: none; }
#help .name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; }
#help .name-row input { font: inherit; padding: 4px 8px; border: 1px solid #b9a888; border-radius: 6px; width: 120px; background: #fff; }
.bubble.tag { background: rgba(20,16,12,.65); color: #fff; font-size: 11px; padding: 2px 7px; }

#lobby .profile { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0 2px; }
#lobby .profile label { display: flex; align-items: center; gap: 6px; font-weight: bold; color: #8a3a1c; }
#lobby .profile input, #lobby .profile select { font: inherit; padding: 4px 8px; border: 1px solid #b9a888; border-radius: 6px; background: #fff; color: #3a2a18; }
#lobby .profile input { width: 110px; }
#lobby .gender { display: flex; flex-wrap: wrap; gap: 4px; }
#lobby .gender.kind { flex-basis: 100%; }
#lobby .gender button { background: #efe3c8; color: #3a2a18; border: 1px solid #b9a888; padding: 4px 12px; }
#lobby .gender button.on { background: #b7562f; color: #fff; border-color: #b7562f; }

/* 대기실: ① 서버 → ② 내 아이 → ③ 시작 */
#lobby { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 30%, rgba(60,44,24,.55), rgba(15,12,8,.82)); }
#lobby[hidden] { display: none; }
#lobby .card { background: #f6ecd6; color: #3a2a18; border-radius: 14px; padding: 20px 22px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; box-shadow: 0 6px 0 rgba(0,0,0,.35); }
#lobby .dim { color: #7a6448; }
#lobby h1 { margin: 0 0 10px; font-size: 26px; letter-spacing: -1px; }
#lobby .steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 14px; }
#lobby .steps li { flex: 1; text-align: center; padding: 6px 4px; border-radius: 8px; background: #e9dcc0; color: #8a7458; font-size: 13px; font-weight: bold; }
#lobby .steps li.on { background: #b7562f; color: #fff; }
#lobby .steps li.done { background: #d7c49c; color: #5a4630; }
#lobby .servers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0 4px; }
#lobby .srv { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 9px 8px; border-radius: 10px; border: 2px solid #d9c7a7; background: #fffaf0; color: #3a2a18; text-align: left; cursor: pointer; }
#lobby .srv b { font-size: 15px; }
#lobby .srv .cnt { font-size: 18px; font-weight: bold; color: #8a3a1c; }
#lobby .srv .cnt small { font-size: 11px; color: #9c886e; font-weight: normal; }
#lobby .srv .bar { height: 5px; border-radius: 3px; background: #eadfc8; overflow: hidden; }
#lobby .srv .bar i { display: block; height: 100%; background: #6b9d4a; }
#lobby .srv .mood { font-size: 11px; color: #9c886e; }
#lobby .srv.on { border-color: #b7562f; background: #fff1de; box-shadow: 0 0 0 2px rgba(183,86,47,.25); }
#lobby .srv.full .bar i { background: #c0443a; }
#lobby .srv:disabled { opacity: .5; cursor: not-allowed; }
#lobby .nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 14px; }
#lobby .nav button { font: inherit; font-weight: bold; padding: 9px 18px; border-radius: 10px; border: 0; background: #b7562f; color: #fff; cursor: pointer; }
#lobby .nav button.ghost { background: #e7d8bb; color: #5a4630; }
#lobby:not(.ingame) #lobby-cancel { visibility: hidden; } /* 처음 들어올 땐 닫기 없음 */
#lobby .summary { display: flex; align-items: center; gap: 14px; background: #fff8e8; border-radius: 12px; padding: 14px; margin: 4px 0 12px; line-height: 1.6; }
#lobby .summary .big { font-size: 46px; }
#lobby .go { display: block; width: 100%; font: inherit; font-size: 20px; font-weight: bold; padding: 14px; border: 0; border-radius: 12px; background: #b7562f; color: #fff; cursor: pointer; box-shadow: 0 4px 0 #7d3418; }
#lobby .go:active { transform: translateY(2px); box-shadow: 0 2px 0 #7d3418; }
@media (max-width: 520px) { #lobby .servers { grid-template-columns: repeat(2, 1fr); } #lobby .card { padding: 14px; } #lobby h1 { font-size: 22px; } }

/* 휴대폰 조작 */
#pad { position: fixed; inset: auto 0 0 0; height: 0; pointer-events: none; }
#stick {
  position: fixed; left: calc(18px + env(safe-area-inset-left)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%; background: rgba(20,16,12,.35); border: 2px solid rgba(255,255,255,.35);
  pointer-events: auto; touch-action: none;
}
#knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255,250,235,.85); }
#tbtns {
  position: fixed; right: calc(14px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(2, 64px); gap: 8px; pointer-events: auto; direction: rtl;
}
#tbtns button {
  direction: ltr; height: 46px; border-radius: 12px; font-size: 13px; font-weight: bold; touch-action: none;
  background: rgba(20,16,12,.55); color: #fff; border: 2px solid rgba(255,255,255,.3);
}
#tbtns button.big { grid-row: span 2; height: 100px; font-size: 16px; background: rgba(183,86,47,.8); }
#tbtns button.big { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#tbtns button.big .ic { font-size: 30px; line-height: 1; }
#tbtns button.big small { font-size: 12px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
#tbtns button.big.off { background: rgba(70,62,52,.45); color: rgba(255,255,255,.45); border-color: rgba(255,255,255,.2); } /* 가까이 아무것도 없을 때 */
#tbtns button.mid { background: rgba(60,90,140,.7); }
#tbtns button.on { transform: scale(.94); filter: brightness(1.3); }
body.touch #prompt { bottom: auto; top: 96px; font-size: 13px; }
body.touch #chat { bottom: auto; top: 140px; }
@media (max-width: 520px) { #clock { font-size: 12px; } #buttons button { padding: 3px 6px; } }

/* 감성 그림체 모드: 노을빛으로 물들이고 가장자리를 어둡게 (창밖으로 놀이터를 보는 느낌) */
#toonfx { display: none; }
body.toon #game { filter: sepia(0.38) saturate(1.35) hue-rotate(-10deg) contrast(1.06) brightness(1.04); }
body.toon #toonfx {
  display: block; position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255,170,90,0) 45%, rgba(120,50,15,.35) 85%, rgba(60,25,8,.6) 100%),
    linear-gradient(rgba(255,150,60,.08), rgba(255,120,40,.12));
  mix-blend-mode: multiply;
}

/* 좁은 화면: 오른쪽 위 버튼이 넘치지 않게 줄바꿈 */
#buttons { flex-wrap: wrap; justify-content: flex-end; max-width: 62vw; }
@media (max-width: 520px) { #buttons button, #buttons a.btn { min-width: 30px; padding: 3px 5px; font-size: 13px; } .toast { font-size: 13px; } }

/* 놀이기구 아이콘 · 제스처 */
#icons { position: fixed; inset: 0; pointer-events: none; }
.ride-icon {
  position: absolute; transform: translate(-50%, -100%); pointer-events: auto; touch-action: none;
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 8px 4px; min-width: 52px;
  background: rgba(255,250,236,.93); color: #3a2a18; border: 2px solid #b7562f; border-radius: 12px;
  font-size: 11px; font-weight: bold; box-shadow: 0 3px 0 rgba(0,0,0,.25); cursor: pointer;
}
.ride-icon span { font-size: 22px; line-height: 1.1; }
.ride-icon:hover { background: #fff; }
.ride-icon.busy { opacity: .45; border-color: #9a8f80; }
.ride-icon.going { background: #b7562f; color: #fff; }
.ride-icon.exit { background: #2f62a8; color: #fff; border-color: #fff; font-size: 13px; padding: 6px 12px; }
.ride-icon[hidden] { display: none; }
#emotes {
  position: fixed; top: 54px; right: 12px; display: grid; grid-template-columns: repeat(3, 72px); gap: 6px;
  background: rgba(20,16,12,.85); padding: 8px; border-radius: 12px;
}
#emotes[hidden] { display: none; }
#emotes button { display: flex; flex-direction: column; align-items: center; font-size: 12px; padding: 6px 2px; position: relative; }
#emotes button span { font-size: 24px; }
#emotes button small { position: absolute; top: 2px; right: 5px; font-size: 9px; opacity: .6; }

#tbtns button.gun { background: rgba(40,40,44,.85); border-color: #ff6a1a; }
#tbtns button[hidden] { display: none; }
