:root {
  --bg: #1b1a28;
  --ink: #2c2a40;
  --paper: #fbf6ec;
  --paper-2: #f0e6d2;
  --line: #cdbfa6;
  --muted: #6d6780;
  --hl: #1f5e4b;     /* 강조색: 로고의 파랑과 노랑이 겹친 초록 */
  --warn: #b4461b;   /* 경고·오류 표시 */
  --on-dark: #ece7f7;
  --on-dark-muted: #aaa4be;
  --shade: rgba(12, 10, 24, 0.45);
  /* 글꼴은 모두 고딕 (Pretendard) */
  --sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--on-dark);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
p, h1, h2, dl, dd, ul { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--hl); outline-offset: 2px; }

/* 게임 화면 */
#game {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

/* 픽셀 창틀 */
.panel {
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 4px var(--line), 0 4px 0 0 var(--shade);
}

/* 위쪽 이름표와 버튼 */
.hud {
  position: fixed;
  top: calc(12px + var(--safe-t));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand { display: grid; gap: 6px; padding: 10px 14px 11px; }
.brand-logo { display: block; width: 115px; height: auto; }
.brand-sub { font: 600 12px/1.2 var(--sans); color: var(--hl); }
.btn-sm {
  padding: 9px 14px 10px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.btn-sm:hover { background: var(--paper-2); }

.keys-hint {
  position: fixed;
  left: 12px;
  bottom: calc(12px + var(--safe-b));
  padding: 7px 12px 8px;
  border-radius: 3px;
  background: rgba(27, 26, 40, 0.78);
  color: var(--on-dark-muted);
  font: 12px/1 var(--sans);
}
.keys-hint kbd {
  font: inherit;
  color: var(--on-dark);
  padding: 1px 5px 2px;
  border: 1px solid var(--on-dark-muted);
  border-radius: 2px;
}
/* 그림 출처 (라이선스상 꼭 있어야 해서, 눈에 띄지 않게 아주 흐리게만) */
.credit {
  position: fixed;
  right: 12px;
  bottom: calc(10px + var(--safe-b));
  color: rgba(236, 231, 247, 0.28);
  font: 11px/1 var(--sans);
  pointer-events: none;  /* 글자 위를 눌러도 게임 화면이 눌린다 */
  user-select: none;
}
.is-talking .keys-hint, .is-talking .credit { visibility: hidden; }  /* 대화창에 반쯤 덮이지 않게 대화 중에만 숨김 */

/* 마우스를 올린 식구·물건 머리 위 이름표 */
.name-tag {
  position: fixed;
  transform: translate(-50%, -100%);
  padding: 4px 8px 5px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font: 700 12px/1 var(--sans);
  white-space: nowrap;
  pointer-events: none;
}
.name-tag::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -4px;
  border: 4px solid transparent;
  border-bottom: 0;
  border-top-color: var(--ink);
}
/* 지도 맨 위에 선 식구는 머리 위 자리가 화면 밖이라 발밑에 띄운다 */
.name-tag.below { transform: translateX(-50%); }
.name-tag.below::after { top: auto; bottom: 100%; border-width: 0 4px 4px; border-color: transparent transparent var(--ink); }

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font: 12px/1 var(--sans);
  color: var(--on-dark-muted);
}

/* 시작 화면 */
.title {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(27, 26, 40, 0.55);
}
.title-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(440px, 100%);
  padding: 30px 24px 22px;
  text-align: center;
}
.title-logo { display: block; width: 270px; max-width: 100%; height: auto; margin-bottom: 2px; }
.title-sub { font: 700 17px/1.5 var(--sans); color: var(--hl); word-break: keep-all; text-wrap: balance; }
.btn {
  margin-top: 6px;
  padding: 12px 22px 13px;
  border: 3px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font: 700 14px/1 var(--sans);
  box-shadow: 0 4px 0 0 var(--shade);
  cursor: pointer;
}
.btn:hover { background: #3b3856; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 0 var(--shade); }
.title-hint { font: 13px/1.6 var(--sans); color: var(--muted); word-break: keep-all; }
.linkish {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 12px/1.4 var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* 대화창 */
.dialog {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  width: min(760px, calc(100% - 24px));
  transform: translateX(-50%);
}
.dlg-panel {
  position: relative;
  display: flex;
  gap: 14px;
  min-height: 124px;
  padding: 16px 18px 20px;
  cursor: pointer;
}
.dlg-face {
  flex: none;
  width: 64px;
  height: 80px;
  image-rendering: pixelated;
  background: var(--paper-2);
  border: 2px solid var(--ink);
}
.dlg-body { flex: 1; min-width: 0; }
.dlg-name {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 10px 4px;
  background: var(--ink);
  color: var(--paper);
  font: 700 13px/1 var(--sans);
}
.dlg-text {
  min-height: 3.4em;
  font: 16px/1.7 var(--sans);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.dlg-text b { font-weight: inherit; color: var(--hl); }
.dlg-next {
  position: absolute;
  right: 16px;
  bottom: 10px;
  font: 12px/1 var(--sans);
  animation: nudge 0.9s steps(2) infinite;
}
@keyframes nudge { 50% { transform: translateY(3px); } }
.dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choice {
  position: relative;
  padding: 6px 12px 7px 24px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.2 var(--sans);
  cursor: pointer;
}
.choice.is-sel { background: var(--paper-2); }
.choice.is-sel::before {
  content: '▶';
  position: absolute;
  left: 7px;
  top: 50%;
  transform: translateY(-50%);
  font: 12px/1 var(--sans);
}

/* 휴대폰 조작 */
.touch { position: fixed; inset: auto 0 0 0; pointer-events: none; }
.joy {
  position: absolute;
  left: 20px;
  bottom: calc(24px + var(--safe-b));
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(251, 246, 236, 0.55);
  border-radius: 50%;
  background: rgba(44, 42, 64, 0.4);
  pointer-events: auto;
  touch-action: none;
}
.joy-knob {
  width: 46px;
  height: 46px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  pointer-events: none;
}
.touch.talking .joy { visibility: hidden; }

/* 목록으로 보기 */
.plain {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: calc(20px + var(--safe-t)) 16px calc(28px + var(--safe-b));
  background: rgba(27, 26, 40, 0.88);
}
.plain-inner {
  position: relative;
  display: grid;
  gap: 14px;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 24px 26px;
  font: 16px/1.75 var(--sans);
  word-break: keep-all;
}
.close-list { justify-self: end; }
.plain-logo { display: block; width: 210px; max-width: 100%; height: auto; }
.plain-inner h2 {
  margin-top: 10px;
  padding-bottom: 6px;
  border-bottom: 2px dashed var(--line);
  font: 700 18px/1.3 var(--sans);
}
.plain-inner .lead { font: 800 26px/1.45 var(--sans); color: var(--hl); text-wrap: balance; }
.works { display: grid; gap: 8px; }
.works dd + dt { margin-top: 18px; }  /* 제목·내용 한 묶음이 끝나면 조금 더 띄운다 */
.works dt { font: 700 15px/1.4 var(--sans); }
.works dd { color: var(--ink); }
.ways { display: grid; gap: 8px; padding-left: 18px; }
.ways b { font-weight: inherit; color: var(--hl); }
.plain-inner a { color: var(--hl); text-underline-offset: 3px; }
.corp { margin-top: 12px; font: 12px/1.7 var(--sans); color: var(--muted); }
.nowrap { white-space: nowrap; }

.noscript { position: fixed; inset: auto 16px 16px; padding: 12px; background: var(--paper); color: var(--ink); }

/* 배치 모드 (로컬 /?edit) */
.is-editing .hud, .is-editing .credit, .is-editing .keys-hint { display: none; }
.editor {
  position: fixed;
  top: 12px;
  right: 12px;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 16px;
  font: 12px/1.5 var(--sans);
}
.ed-title { font-weight: 700; }
.ed-help, .ed-msg { color: var(--muted); word-break: keep-all; }
.ed-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.ed-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 8px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
}
.ed-item:hover { background: var(--paper-2); }
.ed-item.is-selected { border-color: #d9a400; background: #fff3c4; }
.ed-label {
  position: fixed;
  z-index: 2;
  transform: translate(-50%, -100%);
  padding: 4px 8px 5px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font: 700 12px/1 var(--sans);
  white-space: nowrap;
  pointer-events: none;
}
.ed-name { font-weight: 700; }
.ed-dirs { display: flex; gap: 2px; grid-row: 1 / span 2; grid-column: 2; }
.ed-dirs button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  font: 12px/1 var(--sans);
  cursor: pointer;
}
.ed-dirs button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.ed-info { grid-column: 1; }
.ed-info.ok { color: #2f7d4f; }
.ed-info.bad { color: var(--warn); }
.ed-actions { display: flex; align-items: center; gap: 12px; }
.ed-actions .btn { margin: 0; }

@media (max-width: 560px) {
  .brand-logo { width: 84px; }
  .brand { padding: 8px 10px 9px; }
  .brand-sub { display: none; }
  .title-logo { width: 210px; }
  .dlg-face { width: 48px; height: 60px; }
  .dlg-panel { gap: 10px; padding: 14px 14px 20px; }
}
/* 폰(터치)이나 좁은 화면에는 키보드 안내를 띄우지 않는다. 좁으면 아래 안내가 크레딧과 겹친다 */
@media (max-width: 560px), (pointer: coarse) {
  .keys-hint, .kbd-only { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .dlg-next { animation: none; }
}
