/* 두메살이 — 흙빛 바탕에 한지 색 글씨 */
@font-face {
  font-family: 'Galmuri11';
  src: url('assets/fonts/Galmuri11.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Galmuri11';
  src: url('assets/fonts/Galmuri11-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #15120e;
  --panel: rgba(42, 33, 24, 0.94);
  --line: #6f5a3c;
  --ink: #f1e7d0;
  --dim: #b9a888;
  --accent: #e0a63f;
  --danger: #c9543f;
  --gap: 8px;
  --top: calc(env(safe-area-inset-top, 0px) + var(--gap));
  --right: calc(env(safe-area-inset-right, 0px) + var(--gap));
  --bottom: calc(env(safe-area-inset-bottom, 0px) + var(--gap));
  --left: calc(env(safe-area-inset-left, 0px) + var(--gap));
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Galmuri11', 'Malgun Gothic', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
  cursor: grab;
}
#view:active { cursor: grabbing; }

/* ── 화면 위 버튼·패널 공통 */
.home-btn, .hud-btn, .clock, .stock, .tools, #inspect, #hint {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.home-btn {
  position: fixed;
  z-index: 30;
  top: var(--top);
  left: var(--left);
  height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  text-decoration: none;
}
.hud-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}
.home-btn:hover, .hud-btn:hover { border-color: var(--accent); }

#btnMenu { position: fixed; z-index: 30; top: var(--top); right: var(--right); }

.clock {
  position: fixed;
  z-index: 30;
  top: var(--top);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 6px 0 12px;
  white-space: nowrap;
}
.clock-text { display: flex; align-items: baseline; gap: 8px; }
.clock-text span { color: var(--dim); min-width: 5.2em; }
.clock-text #hSky { min-width: 0; color: #cfe0ea; }
.speed { display: flex; gap: 2px; }
.speed button {
  min-width: 34px;
  height: 28px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: -2px;
}
.speed button:hover { color: var(--ink); }
.speed button[aria-pressed="true"] { background: var(--accent); color: #2a1c0c; }
.speed button[data-speed="0"] { letter-spacing: 0; font-size: 13px; }
.speed button[data-speed="0"][aria-pressed="true"] { background: var(--danger); color: #fff; }

.side {
  position: fixed;
  z-index: 25;
  top: calc(var(--top) + 48px);
  right: var(--right);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
#minimap {
  width: 144px;
  height: 144px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: #000;
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
}
.zoom { display: flex; flex-direction: column; gap: 4px; }

.under-clock {
  position: fixed;
  z-index: 29;
  top: calc(var(--top) + 46px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.stock {
  margin: 0;
  padding: 2px 10px;
  color: var(--dim);
  font-size: 12px;
  white-space: nowrap;
}
#alerts { display: flex; flex-direction: column; align-items: center; gap: 3px; }
/* 길잡이: 다음에 할 일 한 줄 */
.guide {
  max-width: min(520px, calc(100vw - 16px));
  padding: 3px 10px;
  background: rgba(42, 33, 24, 0.86);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #ffe9a8;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: auto;
}
/* 과업 창 */
.goal-list { margin: 0 0 10px; padding: 0; list-style: none; text-align: left; font-size: 13px; }
.goal-list li { display: flex; align-items: baseline; gap: 8px; padding: 5px 2px; border-bottom: 1px solid rgba(111, 90, 60, 0.4); }
.goal-list li b { flex: none; width: 20px; color: var(--dim); text-align: center; }
.goal-list li.done b { color: #9be870; }
.goal-list li.done span { color: var(--dim); }
.goal-list span { flex: 1; }
.goal-list small { display: block; color: var(--dim); font-size: 11px; }
.goal-list em { flex: none; color: var(--accent); font-style: normal; }
.won-label { display: block; margin-bottom: 4px; text-align: left; font-size: 13px; }
#wonName {
  width: 100%;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 4px 10px;
  background: #1f1810;
  border: 2px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
#wonName:focus { outline: none; border-color: var(--accent); }
#won .chron-list, #over .chron-list { max-height: 40vh; }
.card p.over-feats { color: #ffe9a8; font-size: 13px; }
/* 시작 화면: 시작 묶음, 업적과 지난 마을 */
.tt-party { display: flex; flex-direction: column; gap: 4px; max-height: 30vh; overflow: auto; }
.tt-party button { flex: none; height: auto; min-height: 34px; padding: 4px 8px; line-height: 1.3; background: #3a2e20; border: 2px solid var(--line); border-radius: 4px; font-size: 13px; text-align: left; }
.tt-party button[aria-checked="true"] { background: var(--accent); border-color: #f4cf86; color: #2a1c0c; font-weight: 700; }
.tt-party button:disabled { color: var(--dim); border-style: dashed; }
.tt-party small { display: block; font-size: 11px; font-weight: 400; color: var(--dim); }
.tt-party button[aria-checked="true"] small { color: #4a3414; }
.tt-records h2 { margin: 6px 0 2px; font-size: 14px; text-align: left; }
.tt-records h2 small { color: var(--dim); font-weight: 400; }
.feat-list { max-height: 26vh; margin: 0; padding: 0; overflow: auto; list-style: none; text-align: left; font-size: 12px; }
.feat-list li { padding: 3px 2px; border-bottom: 1px solid rgba(111, 90, 60, 0.3); }
.feat-list li.locked { color: var(--dim); }
.feat-list small { color: var(--dim); }
.note-card {
  max-width: min(360px, calc(100vw - 16px));
  padding: 8px 10px;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  pointer-events: auto;
}
.note-card p { margin: 0 0 6px; }
.note-card b { color: var(--accent); margin-right: 6px; }
.note-card .btn { min-height: 32px; padding: 2px 10px; }
#ask { border-color: var(--danger); }
.left-col {
  position: fixed;
  z-index: 25;
  top: calc(var(--top) + 48px);
  left: var(--left);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hud-btn.wide { width: auto; min-width: 48px; height: 36px; padding: 0 10px; font-size: 13px; }
/* 사람 카드·일지 */
.ps-body { max-height: 60vh; margin-bottom: 12px; overflow: auto; text-align: left; font-size: 13px; }
.ps-body h3 { margin: 10px 0 4px; font-size: 12px; font-weight: 400; color: var(--accent); }
.ps-body p { margin: 0 0 4px; }
.ps-body small { color: var(--dim); }
.ps-body ul { margin: 0; padding: 0; list-style: none; }
.ps-body li { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
.ps-warn { color: #f0a48f; }
.pips { letter-spacing: 1px; color: var(--accent); white-space: nowrap; }
.pips i { color: #5a4a34; font-style: normal; }
.chron-list { max-height: 60vh; margin: 0 0 12px; padding: 0; overflow: auto; list-style: none; text-align: left; font-size: 13px; }
.chron-list li { padding: 5px 2px; border-bottom: 1px solid rgba(111, 90, 60, 0.4); }
.chron-list time { display: block; color: var(--dim); font-size: 11px; }
#alerts button {
  padding: 3px 10px;
  background: #5a221a;
  border: 2px solid var(--danger);
  border-radius: 6px;
  color: #ffd9cf;
  font-size: 12px;
  pointer-events: auto;
}
#alerts button.warn { background: #4a3a14; border-color: var(--accent); color: #ffe9a8; }
/* 거래 */
.tr-scroll { max-height: 52vh; margin-bottom: 8px; overflow: auto; text-align: left; }
.tr-scroll h3 { margin: 8px 0 4px; font-size: 12px; font-weight: 400; color: var(--accent); }
.tr-scroll h3 small, .tr-list small { color: var(--dim); }
.tr-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.tr-list li { display: flex; align-items: center; gap: 4px; padding: 3px 0; border-bottom: 1px solid rgba(111, 90, 60, 0.3); }
.tr-list .tr-name { flex: 1; min-width: 0; }
.tr-list .tr-none { color: var(--dim); }
.tr-list button { min-width: 32px; height: 32px; padding: 0 6px; background: #3a2e20; border: 2px solid var(--line); border-radius: 4px; }
.tr-list output { min-width: 26px; text-align: center; font-weight: 700; }
.tr-sum { font-size: 13px; }
.tr-sum.bad { color: #f0a48f; }
/* 난이도 고르기 */
.tt-diff { display: flex; gap: 4px; }
.tt-diff button { flex: 1; min-height: 36px; padding: 0 4px; background: #3a2e20; border: 2px solid var(--line); border-radius: 4px; font-size: 13px; }
.tt-diff button[aria-checked="true"] { background: var(--accent); border-color: #f4cf86; color: #2a1c0c; font-weight: 700; }
.card p.tt-diff-text { margin: 0; color: var(--dim); font-size: 12px; }

/* 아래쪽: 도움말 → 칸 설명 → 도구 막대 순으로 쌓인다 */
.bottom {
  position: fixed;
  z-index: 26;
  left: var(--left);
  right: var(--right);
  bottom: var(--bottom);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.bottom > * { pointer-events: auto; }
#hint {
  margin: 0;
  padding: 4px 12px;
  max-width: 100%;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.6s;
}
#hint.gone { opacity: 0; }

.tools {
  display: flex;
  gap: 4px;
  max-width: 100%;
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tools::-webkit-scrollbar { display: none; }
.tools button {
  flex: none;
  min-width: 52px;
  height: 40px;
  padding: 0 10px;
  background: #3a2e20;
  border: 2px solid transparent;
  border-radius: 4px;
  white-space: nowrap;
}
.tools button:hover { border-color: var(--line); }
.tools button[aria-pressed="true"] { background: var(--accent); color: #2a1c0c; font-weight: 700; }
.tools .people-btn { margin-left: 8px; border-color: var(--line); }
.tools button[aria-expanded="true"] { border-color: var(--accent); }
.build-row { border-color: var(--accent); }

#inspect {
  width: max-content;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
}
.ins-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.ins-text b { color: var(--accent); }
.ins-text b.link { text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.ins-text span { color: var(--dim); font-size: 12px; }
.ins-text em { flex-basis: 100%; color: #f3d9a0; font-size: 12px; font-style: normal; }
#insClose {
  flex: none;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* ── 알림 */
/* 알림은 왼쪽 단추 아래에 쌓는다(가운데는 경보와 선택지 카드 자리) */
#toasts {
  position: fixed;
  z-index: 90;
  top: calc(var(--top) + 134px);
  left: var(--left);
  max-width: min(340px, 60vw);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 6px 14px;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 6px;
  animation: toast 3.2s forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(-6px); }
  8%, 85% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

/* ── 가운데 창(시작 화면·메뉴·오류·로딩) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(14, 11, 8, 0.55);
}
#loading { z-index: 1900; background: var(--bg); }
#err { z-index: 2000; background: rgba(14, 11, 8, 0.9); }
.card {
  width: min(360px, 100%);
  padding: 22px 20px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  text-align: center;
}
.card.small { width: auto; padding: 12px 20px; }
.card.wide { width: min(520px, 100%); padding: 18px 12px; }

/* 사람 표(작업 우선순위) */
.pp-help { color: var(--dim); font-size: 12px; }
.pp-scroll { max-height: 55vh; margin-bottom: 12px; overflow: auto; }
.pp-table { width: 100%; border-collapse: collapse; }
.pp-table th { padding: 4px 2px; font-size: 12px; font-weight: 400; color: var(--dim); }
.pp-table { table-layout: fixed; }
.pp-table .pp-who th { padding-top: 10px; text-align: left; }
.pp-table td { padding: 3px 2px; text-align: center; }
.pp-name { padding: 0; background: none; border: 0; color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.pp-table small { display: inline-block; margin-left: 8px; color: var(--dim); font-size: 11px; }
.pp-need { color: #d8c79c !important; }
.pp-cell { width: 100%; max-width: 40px; height: 34px; background: #3a2e20; border: 2px solid var(--line); border-radius: 4px; }
.pp-cell.v1 { background: var(--accent); border-color: #f4cf86; color: #2a1c0c; font-weight: 700; }
.pp-cell.v2 { background: #8a6a30; }
.pp-cell.v4 { color: var(--dim); }
.pp-cell.v0 { background: transparent; color: var(--dim); }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card p { margin: 0 0 12px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.logo { margin: 0 0 6px; font-size: 34px; letter-spacing: 2px; color: var(--accent); text-shadow: 0 3px 0 #1c140c; }
.logo small { display: block; font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--dim); text-shadow: none; }
.dev-note { color: var(--dim); font-size: 12px; }

.btn {
  min-height: 42px;
  padding: 6px 14px;
  background: #3a2e20;
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.alt { background: var(--accent); border-color: #f4cf86; color: #2a1c0c; font-weight: 700; }
.btn.big { min-height: 50px; font-size: 16px; }
.tt-save { display: block; font-size: 12px; font-weight: 400; }
.tt-broken, .tt-warn { color: #f0a48f; font-size: 12px; }
.tt-seed label { text-align: left; }
.tt-seed small { color: var(--dim); }
.tt-seed input {
  height: 42px;
  padding: 0 10px;
  background: #1d1711;
  border: 2px solid var(--line);
  border-radius: 6px;
  -webkit-user-select: text;
  user-select: text;
}
.tt-seed input:focus { outline: none; border-color: var(--accent); }
#overText { white-space: pre-line; color: var(--dim); }
.menu-seed { color: var(--dim); }
.menu-seed b { color: var(--ink); -webkit-user-select: text; user-select: text; }
.err-home { display: inline-block; margin-top: 14px; color: var(--dim); }
.noscript { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 좁은 화면(휴대폰 세로) */
@media (max-width: 560px) {
  .home-txt { display: none; }
  .clock { gap: 4px; padding: 0 4px 0 8px; font-size: 13px; }
  .clock-text { flex-direction: column; gap: 0; line-height: 1.2; }
  .clock-text span { font-size: 11px; min-width: 0; }
  .clock-text #hSky { display: none; }
  .stock { font-size: 11px; padding: 2px 6px; }
  .speed button { min-width: 30px; }
  #minimap { width: 96px; height: 96px; }
  .side { top: calc(var(--top) + 78px); }
  .left-col { top: calc(var(--top) + 78px); }
  /* 좁은 화면에서는 가운데가 경보와 카드로 차므로 알림을 아래쪽(도구 막대 위)에 쌓는다 */
  .guide { max-width: calc(100vw - 206px); padding: 2px 6px; font-size: 11px; }
  #toasts { top: auto; bottom: calc(var(--bottom) + 172px); max-width: 72vw; flex-direction: column-reverse; }
  .toast { padding: 4px 10px; font-size: 12px; }
  .tools { gap: 2px; padding: 3px; }
  .tools button { min-width: 36px; padding: 0 3px; font-size: 12px; }
  .pp-cell { height: 32px; padding: 0; border-width: 1px; }
  .pp-table th { font-size: 10px; word-break: keep-all; }
  .pp-table .pp-who th { font-size: 12px; }
  .tools .people-btn { margin-left: 0; }
}
