/* 한 톨을 찾아서 — 한지와 나무 소반 느낌의 따뜻한 UI */
:root {
  --paper: #fbf4e4;
  --paper-2: #f3e7cc;
  --ink: #3b2a1c;
  --ink-2: #6e5640;
  --wood: #7a5232;
  --wood-d: #4d321e;
  --line: #d8c39c;
  --gold: #d9a63b;
  --rice: #fffaf0;
  --green: #4f9a5a;
  --red: #c4513f;
  --blue: #3f7fb8;
  --display: "Gowun Batang", "AppleMyungjo", "Batang", serif;
  --brush: "Nanum Brush Script", "Gowun Batang", serif;
  --body: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --panel-h: 270px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe3ee; color: var(--ink); font-family: var(--body); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#fxLayer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
b { font-variant-numeric: tabular-nums; }

.back-btn { position: fixed; top: 12px; left: 12px; z-index: 30; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 13px; font-weight: 700; color: var(--paper); text-decoration: none; border-radius: 9px; background: rgba(77,50,30,.9); border: 1px solid rgba(255,255,255,.18); }
.back-btn:hover { background: var(--wood); }

/* HUD */
.hud { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; align-items: center; gap: 5px; pointer-events: none; min-width: 300px; }
.hud-main { display: flex; align-items: baseline; gap: 6px; padding: 6px 18px 5px; border-radius: 14px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(60,40,20,.18); }
.hud-main b { font: 700 26px var(--display); color: var(--ink); }
.hud-main .unit { font-size: 14px; color: var(--ink-2); }
.hud-main small { font-size: 12px; color: var(--ink-2); margin-left: 4px; }
.rice-ico { font-size: 20px; }
.hud-sub { display: flex; gap: 12px; font-size: 13px; padding: 4px 12px; border-radius: 10px; background: rgba(251,244,228,.88); border: 1px solid var(--line); }
.hud-sub b { font-weight: 800; }
.hud-next { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-2); background: rgba(251,244,228,.75); padding: 3px 10px; border-radius: 10px; }
.hud-next .bar { width: 120px; height: 6px; border-radius: 3px; background: rgba(110,86,64,.2); overflow: hidden; }
.hud-next .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #e7c36a, var(--gold)); transition: width .4s; }
.flow { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 10px; background: rgba(251,244,228,.75); color: var(--ink-2); }
.flow b { color: var(--ink); }
.flow .arrow { opacity: .5; }
.flow .yard.full b { color: var(--red); }

.corner { position: fixed; top: 12px; right: 12px; z-index: 30; display: flex; gap: 6px; }
.corner button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); font-size: 17px; box-shadow: 0 3px 10px rgba(60,40,20,.15); }
.corner button:hover { background: var(--paper-2); }

.modebar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--panel-h) + 16px); z-index: 25; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 12px; background: var(--wood-d); color: var(--paper); font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.modebar button { border: 0; border-radius: 8px; padding: 5px 10px; background: var(--paper); color: var(--ink); font-weight: 700; }
.hint { position: fixed; left: 12px; top: 64px; z-index: 19; max-width: min(320px, 46vw); padding: 8px 12px; border-radius: 10px; background: rgba(251,244,228,.92); border: 1px solid var(--line); font-size: 13px; line-height: 1.45; pointer-events: none; }

/* 패널 */
.panel { position: fixed; left: 50%; transform: translateX(-50%); bottom: 10px; z-index: 22; width: min(760px, calc(100vw - 20px)); height: var(--panel-h); display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 10px 30px rgba(60,40,20,.25); overflow: hidden; transition: height .25s; }
.panel.folded { height: 48px; }
.tabs { display: flex; gap: 2px; padding: 5px 6px 0; background: var(--paper-2); border-bottom: 1px solid var(--line); flex: none; }
.tabs button { flex: 1; min-width: 0; border: 0; border-radius: 10px 10px 0 0; padding: 7px 4px 8px; background: transparent; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--ink-2); position: relative; }
.tabs button span { font-size: 13px; font-weight: 700; }
.tabs button.on { background: var(--paper); color: var(--ink); box-shadow: 0 -1px 0 var(--line) inset; }
.tabs button.dot::after { content: ''; position: absolute; top: 6px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.tabs .fold { flex: 0 0 40px; font-size: 18px; }
.list { flex: 1; overflow-y: auto; padding: 8px 10px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 7px; align-content: start; grid-auto-rows: max-content; }
.list .wide { grid-column: 1 / -1; }
.item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 11px; border: 1px solid var(--line); background: #fffdf7; text-align: left; min-height: 56px; }
.item .ico { font-size: 24px; width: 32px; text-align: center; flex: none; }
.item .txt { flex: 1; min-width: 0; }
.item .nm { font-weight: 800; font-size: 14px; display: flex; gap: 6px; align-items: baseline; }
.item .nm small { font-weight: 600; color: var(--ink-2); font-size: 12px; }
.item .ds { font-size: 12px; color: var(--ink-2); line-height: 1.35; margin-top: 1px; }
.item .buy { flex: none; display: flex; flex-direction: column; gap: 3px; align-items: stretch; }
.item .buy button { border: 1px solid var(--wood); background: var(--wood); color: var(--paper); border-radius: 8px; padding: 4px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.item .buy button.alt { background: transparent; color: var(--wood); }
.item.mv .buy { width: 130px; }
.item.mv .buy button { overflow: hidden; text-overflow: ellipsis; line-height: 16px; height: 22px; }
.item .buy button .k { display: block; font-size: 10px; font-weight: 700; opacity: .85; line-height: 12px; }
.item.mv .buy button:has(.k) { height: 34px; }
.item .buy button:disabled { background: #e7dcc5; border-color: #d6c7a8; color: #9d8a6c; }
.item.locked { opacity: .55; }
.item.done { background: #f2f7ea; border-color: #bcd4a8; }
.item.gold { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(217,166,59,.35) inset; }
.sec { grid-column: 1 / -1; font: 700 13px var(--display); color: var(--ink-2); margin: 6px 2px 0; display: flex; align-items: center; gap: 8px; }
.sec::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.qty { grid-column: 1 / -1; display: flex; gap: 4px; justify-content: flex-end; font-size: 12px; }
.qty button { border: 1px solid var(--line); background: #fffdf7; border-radius: 7px; padding: 2px 9px; font-weight: 700; }
.qty button.on { background: var(--wood); color: var(--paper); border-color: var(--wood); }
.piece { padding: 8px 10px; border-radius: 10px; background: #fffdf7; border: 1px dashed var(--line); font-size: 13px; line-height: 1.5; }
.piece b { color: var(--wood); }
.piece.unk { color: #a8987e; }
.scene-card { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fffdf7; font-size: 12px; line-height: 1.4; cursor: pointer; text-align: left; }
.scene-card b { font-size: 13px; display: block; }
.scene-card.unk { color: #a8987e; cursor: default; }
.scene-card.ach { cursor: default; }
.scene-card.ach.on { background: #fff6dc; border-color: #e6c46a; }
.slider { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 4px 6px; }
.slider input { flex: 1; accent-color: var(--wood); }
.progress { height: 8px; border-radius: 4px; background: #eadfc6; overflow: hidden; margin-top: 4px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, #e7c36a, var(--gold)); }

/* 알림 */
.toasts { position: fixed; right: 12px; top: 60px; z-index: 40; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
.toast { max-width: 300px; padding: 8px 12px; border-radius: 10px; background: var(--wood-d); color: var(--paper); font-size: 13px; line-height: 1.4; box-shadow: 0 6px 16px rgba(0,0,0,.25); animation: tin .25s ease-out; }
.toast.good { background: #2f6b3a; }
.toast.out { animation: tout .4s forwards; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }
@keyframes tout { to { opacity: 0; transform: translateX(12px); } }

/* 카드·대화 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(40,28,16,.35); padding: 16px; }
.modal.clear { background: transparent; pointer-events: none; align-items: flex-end; padding-bottom: calc(var(--panel-h) + 24px); }
.modal.clear .card { pointer-events: auto; }
.card { width: min(440px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 18px 20px 16px; box-shadow: 0 16px 40px rgba(40,28,16,.35); text-align: center; animation: pop .3s ease-out; max-height: calc(100vh - 32px); overflow-y: auto; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.card h2 { font: 700 21px var(--display); margin: 4px 0 6px; }
.card .big { font-size: 44px; line-height: 1.1; }
.card p { font-size: 14px; line-height: 1.6; margin: 8px 0; color: var(--ink-2); }
.card .say { font: 400 17px var(--display); color: var(--ink); background: #fffdf7; border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); text-align: left; }
.card .say small { display: block; font: 700 12px var(--body); color: var(--wood); margin-bottom: 3px; }
.card .row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.card .row button { border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 800; background: var(--wood); color: var(--paper); }
.card .row button.alt { background: var(--paper-2); color: var(--ink); }
.card .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; font-size: 13px; margin: 10px 0; }
.card .stats div { background: #fffdf7; border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; }
.card .stats b { display: block; font-size: 15px; }
.engrave { font: 400 34px var(--brush); color: #3a2a1a; line-height: 1.25; margin: 8px 0; letter-spacing: 1px; }
.engrave .ch { opacity: 0; display: inline-block; animation: chIn .35s forwards; }
@keyframes chIn { to { opacity: 1; } }
/* 쌀하수 진엔딩: 별자리처럼 하나씩 켜지는 문장 */
.stars { text-align: left; margin: 8px auto 4px; max-width: 320px; font-size: 13px; line-height: 1.7; color: #3a4a7a; }
.stars .star { opacity: 0; animation: chIn .6s forwards; }

/* 떠오르는 숫자 */
.float { position: absolute; font: 800 14px var(--body); color: var(--wood-d); text-shadow: 0 1px 0 #fff, 0 0 6px #fff; white-space: nowrap; transform: translate(-50%, -50%); animation: up 1s ease-out forwards; }
@keyframes up { to { transform: translate(-50%, -160%); opacity: 0; } }
.sparkle { position: absolute; width: 26px; height: 26px; transform: translate(-50%, -50%); background: radial-gradient(circle, #fff 0 18%, rgba(255,240,180,.8) 30%, transparent 62%); animation: tw 1.2s ease-in-out infinite; }
@keyframes tw { 50% { transform: translate(-50%, -50%) scale(1.5) rotate(45deg); opacity: .4; } }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px 8px; font-size: 12px; font-weight: 700; white-space: nowrap; box-shadow: 0 3px 8px rgba(0,0,0,.15); }

/* 로딩·오류 */
.loading { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: linear-gradient(#f6ecd6, #e9d6ae); transition: opacity .5s; }
.loading.hide { opacity: 0; pointer-events: none; }
.load-box { text-align: center; }
.load-title { font: 700 30px var(--display); color: var(--ink); margin-bottom: 14px; }
.load-bar { width: 220px; height: 8px; border-radius: 4px; background: rgba(110,86,64,.2); overflow: hidden; margin: 0 auto; }
.load-bar i { display: block; height: 100%; width: 10%; background: var(--wood); transition: width .3s; }
.load-box p { font-size: 13px; color: var(--ink-2); }
.load-err { max-width: 360px; margin: 0 auto; line-height: 1.6; color: var(--red); font-size: 14px; }
.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

@media (max-width: 760px) {
  :root { --panel-h: 46vh; }
  .back-btn { padding: 6px 9px; font-size: 12px; top: 8px; left: 8px; }
  .hud { top: 46px; min-width: 0; width: calc(100vw - 16px); }
  .hud-main b { font-size: 21px; }
  .hud-sub { font-size: 12px; gap: 8px; }
  .flow { font-size: 11px; }
  .corner { top: 8px; right: 8px; }
  .corner button { width: 34px; height: 34px; font-size: 15px; }
  .panel { bottom: 0; width: 100vw; border-radius: 16px 16px 0 0; }
  .tabs button span { display: none; }
  .tabs button { font-size: 19px; }
  .list { grid-template-columns: 1fr; }
  .hint { top: auto; bottom: calc(var(--panel-h) + 10px); max-width: calc(100vw - 24px); }
  .toasts { top: 150px; }
  .hud-next .bar { width: 80px; }
}

/* 넓은 PC 화면: 패널을 오른쪽 세로 한 줄로 (아래 패널 3열은 설명이 좁은 세로 줄로 깨졌다).
   3D 화면·HUD·알림·모드바는 패널 왼쪽 영역 가운데로 옮긴다(main.js resize가 패널 위치를 보고 카메라 중심도 옮김). */
@media (min-width: 1100px) and (min-height: 560px) {
  :root { --side: 432px; }
  /* translateZ: 접을 때 패널이 비운 자리에 캔버스가 안 그려지는 칸이 남던 것(합성 레이어 문제)을 막는다 */
  .panel { left: auto; right: 12px; top: 60px; bottom: auto; transform: translateZ(0); width: 420px; height: calc(100vh - 72px); }
  .panel.folded { height: auto; }
  .panel.folded .list { display: none; }
  .tabs button { flex-direction: column; gap: 1px; padding: 6px 2px 6px; font-size: 17px; }
  .tabs button span { font-size: 11px; }
  .list { grid-template-columns: 1fr; }
  .hud { left: calc((100vw - var(--side)) / 2); }
  .modebar { left: calc((100vw - var(--side)) / 2); bottom: 16px; }
  .modal.clear { padding-bottom: 24px; padding-right: calc(var(--side) + 16px); }
  .toasts { right: calc(var(--side) + 12px); top: 156px; }
  .hint { top: 156px; } /* HUD가 왼쪽 영역 가운데로 오니 그 아래로 */
}

/* 모델 미리보기 (?preview) */
body.previewing #hint { display: none !important; }
.preview { position: fixed; left: 12px; top: 56px; z-index: 30; width: 210px; max-height: calc(100vh - 68px); display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(60,40,20,.22); font-size: 13px; color: var(--ink); overflow: hidden; }
.preview .pv-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--paper-2); border-bottom: 1px solid var(--line); }
.preview .pv-head small { color: var(--red); flex: 1; }
.preview button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 8px; }
.preview button.on { background: var(--gold); border-color: var(--wood); color: #fff; }
.preview .pv-fold { border: 0; background: none; padding: 0 4px; }
.preview .pv-tools { display: flex; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.preview .pv-tools button { flex: 1; padding: 4px 2px; }
.preview .pv-list { overflow-y: auto; padding: 4px 8px 8px; }
.preview summary { cursor: pointer; font-weight: 700; padding: 6px 0 4px; }
.preview .pv-items { display: flex; flex-wrap: wrap; gap: 4px; }
.preview.folded .pv-tools, .preview.folded .pv-list { display: none; }
.preview.folded .pv-fold { transform: rotate(-90deg); }
@media (max-width: 760px) {
  .preview { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 42vh; border-radius: 12px 12px 0 0; }
}
