/* 색은 여기서 한 번에 바꿀 수 있다 */
:root {
  --bg: #1b1712;
  --panel: #262019;
  --line: #4a3d2c;
  --text: #e9dfcf;
  --muted: #a8977e;
  --accent: #c8913a;
  --good: #8fb36a;
  --bad: #d06a4f;
}

* { box-sizing: border-box; }

/* 브라우저가 스스로 스크롤을 옮기는 기능(스크롤 앵커링)을 끈다.
   화면을 다시 그릴 때 보던 자리는 src/ui/dom.js의 replaceKeepingPlace가 직접 지킨다. */
html, body { overflow-anchor: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.6;
  /* 한국어는 단어 중간에서 줄이 바뀌지 않게, 너무 긴 글자는 그래도 줄을 바꾼다 */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

#app {
  max-width: 640px;
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* 상단 상태바 */
/* 화면 위에 붙은 부분: 상태바 */
#top {
  position: sticky;
  top: 0;
  z-index: 2;
}
#statusbar {
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
#statusbar:empty { display: none; }
/* 높이가 변하지 않는 상태바 (src/ui/layout.js 참고) */
.stats-line { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.stat { white-space: nowrap; }
.stat-label { color: var(--muted); margin-right: 4px; }
/* 숫자 칸 폭 고정: 자릿수가 바뀌어도 줄바꿈 위치가 그대로 */
.stat-number { display: inline-block; font-variant-numeric: tabular-nums; }
.stat-number.wide { min-width: 7ch; }
.stat-number.gold { min-width: 5ch; }
.stat-number.level { min-width: 2ch; }
.status-line {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 1.6em;
  margin-top: 2px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.status-line::-webkit-scrollbar { display: none; }
.timer { color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; }
.badge {
  flex: none;
  color: var(--bg);
  background: var(--bad);
  border-radius: 4px;
  padding: 0 6px;
  font-weight: bold;
}
.effect { color: var(--good); font-size: 13px; margin-left: 6px; }

/* 중앙 장면 */
#scene {
  flex: 1;
  padding: 16px;
}
h2 { margin: 0 0 8px; font-size: 20px; color: var(--accent); }
h3 { margin: 20px 0 8px; font-size: 16px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.selected { border-color: var(--accent); background: #3a2e1f; }
/* 작은 버튼은 글자가 줄바꿈되지 않게 한다. 옆 글이 길면 그 글이 대신 줄바꿈된다. */
button.small { padding: 4px 10px; text-align: center; white-space: nowrap; flex-shrink: 0; }
button.primary { background: var(--accent); color: #1b1712; border-color: var(--accent); text-align: center; font-weight: bold; }

/* 목록 한 줄 (가방 칸, 텃밭 칸, 스탯) */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.row-buttons { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.stat-value { min-width: 2ch; text-align: center; }
.stat-bonus { min-width: 3ch; text-align: right; }
.stat-final { min-width: 4ch; text-align: right; }

/* 행동 결과 알림: 하단 탭 바로 위에 겹쳐서 뜬다. (다른 내용을 밀지 않음, src/ui/toast.js)
   #dock(하단 탭을 감싼 부분) 안에서 위쪽 바깥(bottom: 100%)에 붙인다. */
#toast {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  padding: 0 16px 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  cursor: pointer;
  /* 알림 위에서 끌어도 브라우저가 화면을 스크롤하거나 당겨서 새로고침하지 않게 한다 */
  touch-action: none;
  user-select: none;
  /* 시간과 움직이는 거리는 data/rules.json의 ui에서 온다 (src/ui/toast.js가 --toast-* 로 넣어 줌) */
  transition: transform var(--toast-leave, 0.3s) ease-in, opacity var(--toast-leave, 0.3s) ease-in;
  padding: 10px 14px;
  background: #3a2e1f;
  border: 1px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  /* 나타날 때: 아래에서 살짝 올라오며 부드럽게 */
  animation: toast-in var(--toast-enter, 0.2s) ease-out;
}
.toast.dragging { transition: none; cursor: grabbing; }
/* 사라질 때: 지금 위치에서 흐려지며 조금 더 움직인다 (transform, opacity는 src/ui/toast.js가 정함).
   사라지는 중에는 눌러도 반응하지 않고, 나타나는 애니메이션이 남아 있으면 끈다. */
.toast.leaving { animation: none; pointer-events: none; }
.toast p { margin: 0; }
.toast p + p { color: var(--muted); font-size: 14px; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(var(--toast-drift, 12px)); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
/* 움직임 줄이기 설정을 켠 사람에게는 움직이지 않고 흐려지기만 한다 */
@media (prefers-reduced-motion: reduce) {
  .toast { animation-name: toast-fade-in; transition-property: opacity; }
  .toast.leaving { transform: none !important; }
}

/* 화면 아래에 붙은 부분: 하단 탭 */
#dock {
  position: sticky;
  bottom: 0;
  z-index: 1;
  /* 아이폰 홈 바 영역 + 외부 배지 높이(src/ui/bottom-overlay.js가 계산)만큼 띄운다 */
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--bottom-overlay, 0px));
  background: var(--panel);
}
/* 캐릭터 만들기처럼 탭이 없을 때는 아래 띠를 숨긴다 */
#dock:has(> #tabs:empty) { display: none; }

/* 하단 탭 */
#tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#tabs:empty { display: none; }
#tabs button {
  border: none;
  border-radius: 0;
  text-align: center;
  padding: 14px 0;
}
#tabs button.selected { color: var(--accent); background: #3a2e1f; }

/* 프로필 */
.profile-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: bold; }
.field-label .muted { font-weight: normal; font-size: 13px; }
.field-error { margin: 0; font-size: 13px; }
.field-error:empty { display: none; }
.counter { font-size: 12px; text-align: right; }
input[type="text"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  width: 100%;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.photo-box { display: flex; align-items: center; gap: 12px; }
.photo-buttons { display: flex; flex-direction: column; gap: 6px; }
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.avatar-large { width: 96px; height: 96px; }
.avatar-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--muted);
  font-size: 32px;
}
.profile-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.profile-text { min-width: 0; }
.profile-name { font-size: 20px; font-weight: bold; margin: 0; }
.profile-intro { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 8px; }

/* 사진 자르기 */
/* 창은 실제로 보이는 화면 높이(dvh: 주소창이 줄고 늘어나는 것까지 반영)에 딱 맞춘다.
   넘치면 위쪽이 잘려 보이지 않으므로, 넘치지 않게 틀이 남는 공간에 맞춰 줄어든다. */
.crop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 1000;
  display: flex;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    16px
    calc(max(12px, env(safe-area-inset-bottom)) + var(--bottom-overlay, 0px));
  background: var(--bg);
  overflow: hidden;
  /* 창 위에서는 스크롤, 당겨서 새로고침, 화면 확대 같은 브라우저 동작을 막는다 */
  touch-action: none;
  overscroll-behavior: contain;
}
.crop-panel {
  width: 100%;
  max-width: 400px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.crop-panel > * { flex: none; }
.crop-panel h2 { margin: 0; }
.crop-panel p { margin: 0; font-size: 14px; }
/* 제목, 설명, 슬라이더, 버튼을 놓고 남는 공간. 틀은 이 안의 가로·세로 중 작은 쪽에 맞춘다. */
.crop-panel > .crop-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}
.crop-frame {
  position: relative;
  /* 오래된 브라우저용 (cqw, cqh를 모르면 이 줄을 씀) */
  width: min(100%, 45vh);
  width: min(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #000;
  border: 2px solid var(--accent);
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.crop-frame:active { cursor: grabbing; }
.crop-image {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: none;
}
/* 동그랗게 보일 부분 안내: 원 밖을 살짝 어둡게 */
.crop-guide {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.crop-zoom { display: flex; align-items: center; gap: 10px; }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.crop-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.crop-buttons button { text-align: center; }
/* 가로 화면처럼 높이가 낮으면 설명을 숨겨서 틀이 쓸 공간을 늘린다 */
@media (max-height: 480px) {
  .crop-panel p { display: none; }
  .crop-panel h2 { font-size: 16px; }
}

/* 전투 */
.combat-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.combat-panel p { margin: 0; font-size: 13px; }
.hp-head { display: flex; justify-content: space-between; gap: 8px; }
.hp-number { font-variant-numeric: tabular-nums; }
.hp-bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.hp-fill { height: 100%; background: var(--bad); }
.hp-fill.mine { background: var(--good); }
/* 전투 기록: 높이 고정, 새 줄이 아래에 붙음 (column-reverse로 항상 맨 아래가 보임) */
.combat-log {
  display: flex;
  flex-direction: column-reverse;
  height: 9.5em;
  overflow-y: auto;
  margin: 12px 0;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}
.combat-log p { margin: 0 0 4px; }
/* 버튼 칸: 높이 고정. 아이템 목록이나 전투 결과가 길면 이 안에서만 스크롤된다. */
.combat-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 12.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.combat-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.combat-actions button, .combat-items button, .combat-controls > button { text-align: center; }
.combat-items { display: flex; flex-direction: column; gap: 8px; }
/* 안내 줄: 비어 있어도 두 줄 자리를 차지한다 */
.combat-reason { min-height: 3.2em; margin: 8px 0 0; font-size: 13px; }
.combat-result {
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--panel);
}
.combat-result p { margin: 0 0 4px; }

/* 가게, NPC, 의뢰 */
.npc-card { padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.npc-card p:last-child { margin-bottom: 0; }
.quote { font-style: italic; }
.tab-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.quest { padding: 10px 0 0; border-bottom: 1px solid var(--line); }
.quest .row { border-bottom: none; }
.quest.rare strong { color: var(--accent); }
/* NPC 한 줄 소개. 폰에서도 한 줄에 들어가도록 조금 작게. 길면 잘라내지 않고 다음 줄로 넘어간다. */
.tagline { font-size: 14px; }

/* 의체 */
.implant { padding: 10px 0 0; border-bottom: 1px solid var(--line); }
.implant > p { margin-bottom: 4px; }
.implant .row { border-bottom: none; }
.effects { margin: 0 0 4px; font-size: 14px; color: var(--good); }

/* 더보기 맨 아래의 빌드 시각 */
.version { margin-top: 16px; font-size: 12px; text-align: center; }
