:root {
  --cream: #fbf5ea;
  --ink: #4a3a2a;
  --soft: #8a7663;
  --mint: #9fe3c6;
  --gold: #e8c26a;
  font-family: 'Galmuri11', 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1d140e;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

[hidden] { display: none !important; }

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}
#stage canvas {
  display: block;
  image-rendering: pixelated; /* 도트가 흐려지지 않게 */
}

/* 위쪽 이름표 */
#top {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  border: 2px solid #3e2416;
  border-radius: 6px;
  background: var(--cream);
  box-shadow: 0 3px 0 #3e2416;
  font-size: 14px;
  white-space: nowrap;
}
#top .title { font-weight: 800; }
#top { padding-right: 6px; }
/* 머무는 인원: 상단 상자 바로 아래 가운데(휴대폰에서도 보이게) */
#count {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(74, 58, 42, 0.8);
  color: var(--cream);
  font-size: 12px;
  pointer-events: none;
}
/* 'n명'을 누르면 함께 머무는 사람 목록이 열린다 */
#people-btn {
  margin: -6px 0;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--gold);
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  pointer-events: auto;
}

/* 도트 기도손: 다은 님 그림을 36×36 도트로 줄인 것(그림 한 장 256×36의 맨 왼쪽) */
.hands-icon {
  display: inline-block;
  flex: none;
  width: 36px;
  height: 36px;
  background: url(assets/ui/hands.png) 0 0 / 256px 36px no-repeat;
  image-rendering: pixelated;
}

/* 상단 기도 제목 버튼 */
#board-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  padding: 0 8px 0 2px;
  border: 2px solid #3e2416;
  border-radius: 6px;
  background: #fff8e6;
  box-shadow: 0 2px 0 #3e2416;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
#board-btn:active { transform: translateY(2px); box-shadow: none; }
#board-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 18px;
  padding: 1px 4px;
  border: 2px solid #3e2416;
  border-radius: 9px;
  background: #e0605a;
  color: #fff;
  font-size: 11px;
  line-height: 14px;
  text-align: center;
}
/* 아주 좁은 화면에서는 버튼 글자를 숨겨 기도손만 */
@media (max-width: 340px) {
  #board-btn .label { display: none; }
}

/* 기도 제목 게시판·설정 창 */
#board, #settings, #people {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 12px);
  background: rgba(29, 20, 14, 0.55);
}
#board .sheet, #settings .sheet, #people .sheet {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: 100%;
  border: 3px solid #3e2416;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 6px 0 #3e2416;
  animation: pop 0.25s ease-out;
  overflow: hidden;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 8px 8px;
  border-bottom: 2px solid #eadfcd;
}
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
#board-close, #settings-close, #people-close {
  width: 34px;
  height: 34px;
  border: 2px solid #3e2416;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
#people .sheet { width: min(320px, 100%); }
#people .sheet-head { padding-left: 12px; }
#people-list {
  margin: 0;
  padding: 4px 0;
  list-style: none;
  overflow-y: auto;
}
#people-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 14px;
}
#people-list li + li { border-top: 1px solid #eadfcd; }
#people-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#people-list .me .name { font-weight: 800; }
#people-list .state { color: var(--soft); font-size: 12px; }

#board-form { padding: 10px 12px; border-bottom: 2px solid #eadfcd; }
#board-text {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #eadfcd;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px 밑이면 아이폰이 화면을 확대한다 */
  line-height: 1.5;
  resize: none;
  outline: none;
  user-select: text;
}
#board-text:focus { border-color: var(--gold); }
#board-form .row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; }
#board-form label { display: flex; align-items: center; gap: 4px; color: var(--soft); cursor: pointer; }
#board-msg { flex: 1; color: #b0543c; font-size: 12px; }
#board-form button[type='submit'] {
  padding: 8px 16px;
  border: 2px solid #3e2416;
  border-radius: 6px;
  background: var(--ink);
  color: var(--cream);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
#board-form button:disabled { opacity: 0.6; }
#board-list {
  flex: 1;
  margin: 0;
  padding: 8px 12px 12px;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  user-select: text;
}
#board-list li {
  margin-top: 8px;
  padding: 10px 12px;
  border: 2px solid #eadfcd;
  border-radius: 8px;
  background: #fff;
}
#board-list .head { display: flex; justify-content: space-between; font-size: 13px; }
#board-list .head span { color: var(--soft); font-size: 12px; }
#board-list .body { margin: 6px 0 8px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }
#board-list .foot { display: flex; align-items: center; gap: 8px; }
#board-list .amen {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px 0 2px;
  border: 2px solid #eadfcd;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
#board-list .amen.on { border-color: #2f6b55; background: var(--mint); cursor: default; }
#board-list .del {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--soft);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}
#board-list .empty { margin: 24px 0; color: var(--soft); text-align: center; font-size: 14px; }

/* 안내 말풍선 */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 16px;
  background: rgba(74, 58, 42, 0.88);
  color: var(--cream);
  font-size: 14px;
  white-space: nowrap;
  animation: pop 0.25s ease-out;
}

/* 도트 아이콘: 캐릭터 시트(192×432, 한 칸 48)에서 32×42만큼 잘라 보여 준다. 위치는 main.js setIcon */
.px-icon {
  display: block;
  width: 32px;
  height: 42px;
  background-repeat: no-repeat;
  background-size: 192px 432px;
  image-rendering: pixelated;
}

/* 왼쪽 아래 조이스틱 */
#joy {
  position: fixed;
  left: calc(env(safe-area-inset-left) + 16px);
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  width: 76px;
  height: 76px;
  border: 3px solid #3e2416;
  border-radius: 50%;
  background: rgba(251, 245, 234, 0.45);
  box-shadow: 0 3px 0 #3e2416;
  touch-action: none;
  pointer-events: none; /* 손은 화면(캔버스)이 받고, 조이스틱은 누른 자리로 옮겨 그리기만 한다 */
  opacity: 0.55;
  transition: opacity 0.15s;
}
/* 왼쪽 아래를 누르면 그 자리로 옮겨 온다(main.js 가 left·top 을 정함) */
#joy.active { bottom: auto; opacity: 1; transition: none; }
#joy .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid #3e2416;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: inset -3px -3px 0 #d8c8ad;
  pointer-events: none;
}

/* 오른쪽 아래 행동 버튼 */
#actions {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 16px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 2px solid #3e2416;
  border-radius: 8px;
  background: var(--cream);
  box-shadow: 0 4px 0 #3e2416;
}
#actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
#actions button:active { transform: scale(0.94); }
#actions button.on {
  background: var(--mint);
  box-shadow: 0 0 0 2px #2f6b55 inset;
}

/* 입장 화면 */
#entry {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at center, rgba(29, 20, 14, 0.35), rgba(29, 20, 14, 0.8));
}
#entry .card {
  width: min(360px, 100%);
  padding: 28px 24px 22px;
  border: 3px solid #3e2416;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 6px 0 #3e2416;
  text-align: center;
  animation: pop 0.35s ease-out;
}
#entry h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.5px; }
#entry .lead { margin: 0 0 22px; color: var(--soft); line-height: 1.6; font-size: 15px; }
.field { display: block; margin-bottom: 16px; text-align: left; }
.field > span { display: block; margin: 0 0 6px 4px; font-size: 13px; color: var(--soft); }
#name, #set-name {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #eadfcd;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
  user-select: text;
}
#name:focus, #set-name:focus { border-color: var(--gold); }
.gender-pick { display: flex; gap: 10px; }
.gender-pick button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 2px solid #eadfcd;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.gender-pick button[aria-checked='true'] { border-color: var(--gold); background: #fff8e6; transform: scale(1.03); }
#enter, #settings-save {
  width: 100%;
  margin-top: 6px;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  background: var(--ink);
  color: var(--cream);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
#enter:disabled, #settings-save:disabled { opacity: 0.6; cursor: default; }

/* 설정 창 */
#settings-form { padding: 14px 16px 16px; }
#settings-msg { min-height: 1.2em; margin: 0 0 6px; font-size: 13px; color: #b0543c; text-align: center; }

/* 오른쪽 위 설정 버튼(도트 톱니바퀴) */
.gear-icon {
  display: inline-block;
  flex: none;
  width: 32px;
  height: 32px;
  background-size: 32px 32px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
#settings-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  right: calc(env(safe-area-inset-right) + 12px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #3e2416;
  border-radius: 6px;
  background: #8a7663;
  box-shadow: 0 3px 0 #3e2416;
  cursor: pointer;
}
#settings-btn:active { transform: translateY(3px); box-shadow: none; }

/* 도트 알림창(확인·취소) */
#dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(29, 20, 14, 0.6);
}
.dialog-box {
  width: min(320px, 100%);
  padding: 18px 18px 14px;
  border: 3px solid #3e2416;
  border-radius: 4px;
  background: var(--cream);
  /* 도트 느낌: 안쪽 밝은 테두리 + 아래 그림자 */
  box-shadow: inset 0 0 0 3px #fff8e6, inset 0 0 0 5px #d8c8ad, 0 6px 0 #3e2416;
  text-align: center;
  animation: pop 0.2s ease-out;
}
#dialog-title { margin: 0 0 8px; font-size: 17px; }
#dialog-msg { margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: var(--ink); white-space: pre-line; }
.dialog-btns { display: flex; gap: 8px; }
.dialog-btns button {
  flex: 1;
  padding: 10px;
  border: 2px solid #3e2416;
  border-radius: 4px;
  box-shadow: 0 3px 0 #3e2416;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.dialog-btns button:active { transform: translateY(3px); box-shadow: none; }
#dialog-cancel { background: #fff; color: var(--ink); }
#dialog-ok { background: var(--ink); color: var(--cream); }
#dialog-ok.danger { background: #c4553f; color: #fff; }
#status { min-height: 1.4em; margin: 12px 0 0; font-size: 13px; color: #b0543c; }

@keyframes pop {
  from { opacity: 0; transform: translate(var(--tx, 0), 8px) scale(0.97); }
  to { opacity: 1; transform: translate(var(--tx, 0), 0) scale(1); }
}
#hint { --tx: -50%; }
