/* 이름없는 세계 — 게임 화면을 꽉 채우고, 버튼·창은 게임 안 UI처럼 */
:root {
  --ink: #2a1d14;
  --wood-d: #3f2717;
  --wood: #6b4226;
  --wood-l: #9c6b40;
  --paper: #f3e3c0;
  --paper-d: #e2cc9c;
  --paper-dd: #c9ad78;
  --gold: #f0c040;
  --red: #b8443a;
  --blue: #3a62a2;
  --green: #4f8a3a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0f14; color: var(--ink); font: 13px/1.45 "Malgun Gothic", "Pretendard", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }

/* ── 게임 화면 ── */
#stage { position: fixed; inset: 0; overflow: hidden; }
#stage canvas { position: absolute; left: 0; top: 0; }
#overlay { width: 100%; height: 100%; }
#stage { overscroll-behavior: none; }
button, .menu-btn, .pbtn, .win-tabs button { touch-action: manipulation; } /* 두 번 눌러 확대되지 않게 */
#scene { image-rendering: pixelated; image-rendering: crisp-edges; }
#overlay { pointer-events: none; }

/* ── 게임 안 UI 공통: 나무 테두리 + 양피지 ── */
.plate, .win, .menu-btn {
  background: var(--paper);
  border: 3px solid var(--wood-d);
  box-shadow: inset 0 0 0 2px var(--wood-l), inset 0 0 0 4px var(--paper-dd), 0 3px 0 rgba(0, 0, 0, 0.45);
  border-radius: 6px;
}
.pbtn {
  background: linear-gradient(var(--wood-l), var(--wood));
  color: #fff4dc; border: 2px solid var(--wood-d); border-radius: 4px; padding: 3px 10px; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 0 rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}
.pbtn:hover { filter: brightness(1.12); }
.pbtn:active { transform: translateY(1px); box-shadow: none; }
.pbtn.wide { width: 100%; margin-top: 6px; }
.pbtn.ghost { background: transparent; color: var(--wood); text-shadow: none; }
.pbtn.danger { background: linear-gradient(#d0584c, #9a3a32); }
.pbtn.love { background: linear-gradient(#e0729e, #b04a78); }
.pbtn.ok { background: linear-gradient(#6aa84a, #3f7a2e); }
.pbtn.small { padding: 1px 7px; font-size: 12px; }

.hud { position: fixed; z-index: 10; display: flex; gap: 6px; }
.hud-tl { left: 10px; top: 10px; flex-direction: column; align-items: flex-start; }
.hud-tr { right: 10px; top: 10px; flex-direction: column; align-items: flex-end; }
.hud-br { right: 10px; bottom: 10px; }
.floor-plate { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.floor-name { display: flex; flex-direction: column; min-width: 150px; text-align: center; }
.floor-name b { font-size: 16px; color: var(--wood-d); }
.floor-name small { color: #6a5038; font-size: 11px; }
.small-plate { padding: 2px 10px; font-size: 12px; display: flex; align-items: center; gap: 4px; cursor: pointer; }
.hardcore { color: var(--red); font-weight: 700; cursor: default; }
.hud-row { display: flex; gap: 6px; }
.view-btn { font-weight: 700; color: var(--wood-d); background: #fff6dc; }
.view-label { cursor: default; color: #6a5038; }
.dex-card.hidden-job { text-align: left; display: grid; grid-template-columns: 48px 1fr; gap: 6px; align-items: center; }
.dex-card.hidden-job canvas { margin: 0; }
.dex-grid.wide { grid-template-columns: 1fr; }
.stat-plate { display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-size: 12px; font-variant-numeric: tabular-nums; }
.stat-plate .sep { width: 1px; height: 14px; background: var(--paper-dd); }
#topFloor { color: var(--blue); font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); border: 1px solid var(--wood-d); }
.dot.on { background: #5ad04a; }

.menu-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 62px; height: 58px; cursor: pointer; font-size: 20px; padding: 2px; }
.menu-btn span { font-size: 11px; color: var(--wood-d); font-weight: 700; }
.menu-btn:hover { transform: translateY(-2px); }
.menu-btn.active { background: #fff6dc; }

/* ── 창 ── */
.win { position: fixed; z-index: 20; width: min(380px, calc(100vw - 20px)); max-height: calc(100vh - 175px); display: flex; flex-direction: column; }
.win-left { left: 10px; top: 92px; }
.win-right { right: 10px; top: 92px; width: min(420px, calc(100vw - 20px)); }
.win-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: linear-gradient(var(--wood-l), var(--wood)); color: #fff4dc; font-weight: 700; text-shadow: 0 1px 0 #000; border-bottom: 3px solid var(--wood-d); border-radius: 3px 3px 0 0; }
.win-x { background: none; border: 0; color: #fff4dc; cursor: pointer; font-size: 14px; }
.win-tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 2px solid var(--paper-dd); }
.win-tabs button { background: var(--paper-d); border: 2px solid var(--paper-dd); border-bottom: 0; border-radius: 5px 5px 0 0; padding: 3px 12px; cursor: pointer; color: #6a5038; }
.win-tabs button.active { background: #fff6dc; color: var(--wood-d); font-weight: 700; }
.win-body { padding: 10px; overflow-y: auto; }
.win-body h4 { margin: 10px 0 4px; color: var(--wood); font-size: 13px; border-bottom: 1px dashed var(--paper-dd); }
.hint { color: #7a6048; font-size: 12px; }
.err { color: var(--red); }
.ok-t { color: var(--green); }

input, select, textarea { background: #fffaf0; border: 2px solid var(--paper-dd); border-radius: 4px; padding: 4px 6px; color: var(--ink); width: 100%; }
input[type="checkbox"], input[type="range"] { width: auto; }
.form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.form label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #6a5038; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

.list { list-style: none; margin: 6px 0 0; padding: 0; }
.list li { padding: 5px 4px; border-bottom: 1px dashed var(--paper-dd); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.list li.click { cursor: pointer; }
.list li.click:hover { background: #fff6dc; }
.ranking { counter-reset: r; }
.ranking li::before { counter-increment: r; content: counter(r) "."; color: var(--wood-l); margin-right: 6px; }

/* 캐릭터 정보 */
.ci-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.ci-name { font-size: 16px; font-weight: 700; color: var(--wood-d); }
.badge { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--paper-d); border: 1px solid var(--paper-dd); white-space: nowrap; }
.badge.out { background: #f3c6be; color: #7a2a22; }
.badge.love { background: #f8d0e2; color: #8a2a58; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; font-size: 11px; margin: 6px 0; }
.bar { height: 8px; background: #d8c49a; border: 1px solid var(--wood-d); border-radius: 2px; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; }
.bar.hp > i { background: #5ab04a; }
.bar.hp.low > i { background: var(--red); }
.bar.exp > i { background: #4a7ad0; }
.bar.tr > i { background: linear-gradient(90deg, #6b8cff, #c27bff); }
.bar > b { position: absolute; top: 0; width: 2px; height: 100%; background: #2a1d14aa; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: 12px; }
.kv dt { color: #7a6048; }
.kv dd { margin: 0; }

/* 로그 */
.log-list { list-style: none; margin: 0; padding: 0; }
.log-list li { padding: 5px 2px; border-bottom: 1px dashed var(--paper-dd); white-space: pre-line; word-break: keep-all; overflow-wrap: anywhere; font-size: 12px; }
.log-list time { color: #9a7a58; font-size: 11px; margin-right: 6px; }
.log-list .fl { color: #9a7a58; font-size: 11px; margin-right: 4px; }
.t-death, .t-pk { color: #9a2a22; }
.t-record { color: #8a5a14; font-weight: 700; }
.t-love { color: #a03a6a; }
.t-guild { color: #5a3a8a; }
.t-system { color: #6a5038; }

/* 편집 */
.edit-sec { border: 2px solid var(--paper-dd); border-radius: 5px; padding: 6px 8px; margin-bottom: 8px; background: #fbf0d6; }
.edit-sec > b { display: block; color: var(--wood); margin-bottom: 4px; }
.edit-sec label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: #6a5038; }
.edit-sec .inline { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
.edit-sec .actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.trait-edit { display: grid; grid-template-columns: 22px 1fr 22px 40px; gap: 4px; align-items: center; font-size: 11px; }
.save-bar { position: sticky; bottom: -10px; background: var(--paper); padding: 6px 0; border-top: 2px solid var(--paper-dd); }

/* 도감 */
.win-wide { width: min(560px, calc(100vw - 20px)); }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 8px; }
.dex-card { background: #fbf0d6; border: 2px solid var(--paper-dd); border-radius: 6px; padding: 6px 4px; text-align: center; font-size: 11px; }
.dex-card.boss { border-color: var(--red); background: #fbe4d6; }
.dex-card canvas { width: 68px; height: 68px; image-rendering: pixelated; image-rendering: crisp-edges; display: block; margin: 0 auto 4px; }
.dex-card.char canvas { width: 48px; height: 76px; }
.dex-card.item canvas { width: 64px; height: 64px; }
.dex-card b { display: block; color: var(--wood-d); }

/* 탑 지도 */
.tower { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
.cell { position: relative; aspect-ratio: 1.6 / 1; border-radius: 3px; cursor: pointer; background: var(--paper-d); color: #9a7a58; font-size: 10px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--paper-dd); }
.cell.cleared { background: #c8d8b0; color: #4a6a3a; }
.cell.boss { border-color: var(--red); }
.cell.here { background: #7aa0d8; color: #fff; font-weight: 700; }
.cell.viewing { outline: 2px solid var(--gold); }
.cell .n { position: absolute; top: -5px; right: -4px; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px; background: var(--gold); color: var(--ink); font-size: 9px; line-height: 14px; text-align: center; border: 1px solid var(--wood-d); }

.guild { padding: 6px 4px; border-bottom: 1px dashed var(--paper-dd); }
.guild .gname { font-weight: 700; }
.guild .members { font-size: 11px; color: #6a5038; }

/* ── 휴대폰·작은 화면 ── */
/* 노치·홈 바 영역을 피한다 */
.hud-tl { left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); }
.hud-tr { right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); }
.hud-br { right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }

@media (max-width: 700px) {
  html, body { font-size: 13px; }
  /* 위: 층 이동판 (좁게) */
  .hud-tl { left: max(6px, env(safe-area-inset-left)); top: max(6px, env(safe-area-inset-top)); right: 6px; gap: 4px; }
  .floor-plate { padding: 3px 5px; gap: 4px; }
  .floor-plate .pbtn { padding: 6px 12px; }
  .floor-name { min-width: 0; flex: 1; }
  .floor-name b { font-size: 15px; }
  .floor-name small { font-size: 10px; line-height: 1.2; }
  .hud-row { flex-wrap: wrap; }
  .small-plate { padding: 3px 8px; font-size: 11px; }
  .view-label { white-space: normal; max-width: calc(100vw - 20px); }
  /* 현황판: 아래 메뉴 바로 위 왼쪽으로 */
  .hud-tr { top: auto; right: auto; left: max(6px, env(safe-area-inset-left)); bottom: calc(max(6px, env(safe-area-inset-bottom)) + 58px); }
  .stat-plate { gap: 6px; padding: 3px 8px; font-size: 11px; }
  /* 아래: 메뉴를 화면 폭에 고르게 */
  .hud-br { left: max(6px, env(safe-area-inset-left)); right: max(6px, env(safe-area-inset-right)); bottom: max(6px, env(safe-area-inset-bottom)); justify-content: space-between; gap: 4px; }
  .menu-btn { flex: 1; width: auto; max-width: 70px; height: 50px; font-size: 18px; }
  .menu-btn span { font-size: 10px; }
  /* 창: 화면 아래쪽 절반을 덮는 판 */
  .win-right, .win-left, .win-wide { left: max(4px, env(safe-area-inset-left)); right: max(4px, env(safe-area-inset-right)); width: auto; top: auto; bottom: calc(max(6px, env(safe-area-inset-bottom)) + 58px); max-height: 62vh; max-height: 62dvh; }
  .win-head { padding: 8px 10px; }
  .win-x { font-size: 20px; padding: 0 6px; } /* 손가락으로 누르기 쉽게 */
  .win-tabs button { padding: 6px 14px; }
  .list li { padding: 8px 4px; }
  .tower { grid-template-columns: repeat(10, 1fr); }
  .cell { font-size: 9px; }
  .dex-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  input, select { font-size: 16px; } /* 아이폰이 입력할 때 화면을 확대하지 않게 */
}
/* 가로로 눕힌 휴대폰: 높이가 낮으니 창을 오른쪽에 세로로 */
@media (max-height: 500px) and (orientation: landscape) {
  .win-right, .win-left, .win-wide { top: 6px; bottom: 64px; left: auto; right: max(6px, env(safe-area-inset-right)); width: min(380px, 55vw); max-height: none; }
  .hud-tr { bottom: auto; top: max(6px, env(safe-area-inset-top)); left: auto; right: max(6px, env(safe-area-inset-right)); }
  .hud-tl { right: auto; }
  .hud-br { left: auto; justify-content: flex-end; }
  .menu-btn { flex: none; width: 52px; height: 44px; }
}
