:root {
  --ink: #15171a;
  --sheet: #f7c600;
  --steel: #23272c;
  --paper: #f3efe2;
  --dim: #aeb2a8;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
}

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  cursor: grab;
}

#world:active { cursor: grabbing; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  margin-right: 3px;
  background: var(--ink);
  color: var(--sheet);
  border-radius: 3px;
  font: 700 12px/1 Consolas, "Malgun Gothic", monospace;
}

/* 벽에 붙은 작업장 명판 */
.plate {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  max-width: calc(100vw - 28px);
  background: var(--sheet);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 3px 3px 0 #0009;
}

.plate strong {
  padding: 8px 12px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 14px;
  font-weight: 800;
}

.plate span {
  padding: 8px 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#seated { background: #ffffff2e; }

#people {
  padding: 8px 11px;
  background: var(--ink);
  color: var(--sheet);
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}

#people::after { content: " ▾"; font-size: 10px; }
#people[aria-expanded="true"]::after { content: " ▴"; }
#people:hover { background: #2c3036; }

/* 접속자 목록: 이름만 */
.people-panel {
  z-index: 5;
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 42px);
  left: 14px;
  width: 230px;
  max-width: calc(100vw - 28px);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--ink);
  box-shadow: 3px 3px 0 #0009;
}

.people-panel[hidden] { display: none; }

.people-panel ul {
  margin: 0;
  padding: 6px 0;
  list-style: none;
}

.people-panel li {
  padding: 6px 13px;
  color: var(--paper);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

.people-panel li.me { color: var(--sheet); font-weight: 700; }

/* 머리 위 이름표와 떠오르는 표시 */
.marks {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.name-tag, .float-mark {
  position: absolute;
  top: 0;
  left: 0;
  white-space: nowrap;
  will-change: transform;
}

.name-tag {
  padding: 2px 7px;
  background: #15171ac4;
  color: var(--paper);
  font-size: 12px;
  border-radius: 3px;
}

.name-tag.me { background: var(--sheet); color: var(--ink); font-weight: 700; }
.name-tag[hidden], .float-mark[hidden] { display: none; }

.float-mark { font-size: 30px; line-height: 1; }
.float-mark.cheer { color: #ff5a5f; text-shadow: 0 1px 3px #0008; }

/* 인사·기록 버튼 */
.actions {
  position: fixed;
  right: 14px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
}

.actions button, .person button {
  min-height: 42px;
  padding: 0 13px;
  background: var(--steel);
  color: var(--paper);
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 #0009;
}

.actions button:hover { background: #363c43; }
.actions kbd { background: var(--sheet); color: var(--ink); }

/* 사람을 눌렀을 때 */
.person {
  position: fixed;
  left: 50%;
  bottom: max(120px, calc(env(safe-area-inset-bottom) + 106px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 7px 7px 14px;
  background: var(--ink);
  white-space: nowrap;
}

.person[hidden] { display: none; }
.person strong { font-size: 14px; }
.person #cheer-button { background: #d7263d; color: #fff; }
.person #cheer-button:hover { background: #ec3a51; }
.person .person-close { min-width: 42px; padding: 0; font-size: 18px; box-shadow: none; }

.view-button {
  min-height: 40px;
  padding: 0 12px;
  background: #33383e;
  color: var(--paper);
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.view-button:hover { background: #454b52; }

#sound-button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); }
#sound-button[aria-pressed="true"]:hover { background: #ffd92e; }

.sit-cheers { color: #ff7b7b; font-size: 13px; font-weight: 700; }
.sit-cheers[hidden] { display: none; }

/* 이름·카드 창 */
.sheet {
  width: min(420px, calc(100vw - 24px));
  padding: 0;
  background: #f3efe2;
  color: var(--ink);
  border: 0;
  border-top: 8px solid var(--sheet);
  box-shadow: 6px 6px 0 #000b;
}

.sheet::backdrop { background: #0009; }
.sheet-body { display: grid; gap: 12px; padding: 18px; }
.sheet h2 { margin: 0; font-size: 19px; font-weight: 800; }
.sheet p { margin: 0; color: #5e6257; font-size: 13px; line-height: 1.5; }

.sheet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.grow { flex: 1; }

.sheet button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--ink);
  color: var(--sheet);
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.sheet button.plain { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px #15171a44; }
.sheet button:disabled { opacity: .45; cursor: default; }

.card-sheet { width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
#card-image { display: block; width: 100%; max-height: 62dvh; object-fit: contain; background: var(--ink); }
#card-image[hidden] { display: none; }

/* 업데이트 공지: 소리 없이 위쪽에 작게 */
.notice {
  z-index: 4;
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 72px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 28px);
  padding: 5px 5px 5px 13px;
  background: #15171aee;
  color: var(--paper);
  font-size: 13px;
  box-shadow: 3px 3px 0 #0009;
}

.notice[hidden] { display: none; }

.notice button {
  flex: none;
  min-height: 30px;
  padding: 0 10px;
  background: var(--sheet);
  color: var(--ink);
  border: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.notice #notice-close { padding: 0 8px; background: transparent; color: var(--dim); font-size: 15px; }
.notice #notice-close:hover { color: var(--paper); }

.connection {
  position: fixed;
  top: 66px;
  left: 14px;
  margin: 0;
  padding: 7px 11px;
  background: #b5301f;
  color: #fff;
  font-size: 13px;
}

.help {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 12px;
  width: max-content;
  max-width: calc(100vw - 28px);
  background: #15171ad9;
  color: var(--dim);
  font-size: 12.5px;
}

.help kbd { background: #33383e; color: var(--paper); margin-right: 2px; }

.sit-prompt {
  position: fixed;
  left: 50%;
  bottom: max(62px, calc(env(safe-area-inset-bottom) + 48px));
  transform: translateX(-50%);
  min-height: 46px;
  padding: 0 18px;
  background: var(--sheet);
  color: var(--ink);
  border: 0;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 3px 3px 0 #000a;
}

.sit-prompt[hidden] { display: none; }
.sit-prompt:hover { background: #ffd92e; }

/* 앉아 있을 때만 보이는 시계 */
.sit-panel {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -140%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 8px 8px 16px;
  background: var(--ink);
  border-bottom: 4px solid var(--sheet);
  transition: transform .35s ease;
  white-space: nowrap;
}

.sitting .sit-panel { transform: translate(-50%, 0); }
.sitting .help { display: none; }

/* 창이 좁으면 시계가 왼쪽 위 명판과 겹치지 않게 그 아래로 내린다 */
@media (max-width: 1280px) {
  .sit-panel {
    top: calc(max(14px, env(safe-area-inset-top)) + 44px);
    left: 14px;
    transform: translateY(-220%);
  }
  .sitting .sit-panel { transform: translateY(0); }
  .sitting .notice { top: calc(max(14px, env(safe-area-inset-top)) + 122px); left: 14px; transform: none; }
}

.sit-label { color: var(--dim); font-size: 12px; }

#sit-clock {
  color: var(--sheet);
  font: 700 25px/1 Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.sit-total { color: var(--paper); font-size: 12.5px; }

#stand-button {
  min-height: 40px;
  padding: 0 12px;
  background: var(--sheet);
  color: var(--ink);
  border: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

#stand-button:hover { background: #ffd92e; }

.toast, .stand-summary {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 14px;
  background: #15171aee;
  color: var(--paper);
  font-size: 14px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.stand-summary { top: 30%; color: var(--sheet); font-weight: 700; }
.toast.show, .stand-summary.show { opacity: 1; }

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: var(--ink);
  color: var(--sheet);
  transition: opacity .6s, visibility .6s;
}

.loading strong { font-size: 28px; font-weight: 900; }
.loading span { color: var(--dim); font-size: 13px; }
.loading.done { opacity: 0; visibility: hidden; }

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  margin: 0;
  padding: 24px;
  text-align: center;
  background: var(--ink);
}

.fatal[hidden] { display: none; }

.fatal button {
  min-height: 44px;
  padding: 0 18px;
  background: var(--sheet);
  color: var(--ink);
  border: 0;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* 이동 조이스틱: 터치 기기와 좁은 화면에서만 왼쪽 아래에 반투명하게 */
.joystick {
  display: none;
  position: fixed;
  left: 20px;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 10px));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .22), 0 2px 10px rgba(0, 0, 0, .14);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background .15s;
}

.joystick.held { background: rgba(255, 255, 255, .14); }

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
  pointer-events: none;
}

.joystick.held .joystick-knob { background: rgba(255, 255, 255, .48); }

@media (max-width: 620px), (pointer: coarse) {
  .joystick { display: block; }
  .sitting .joystick { display: none; }
}

/* 휴대폰(가로로 돌린 폰 포함): 안내 글 없이 버튼만 둔다 */
@media (max-width: 620px), (pointer: coarse) and (max-width: 950px) {
  .help, .wide, .sit-prompt kbd, .actions kbd, #stand-button kbd { display: none; }

  /* 왼쪽 아래는 조이스틱 자리라 앉기 버튼은 오른쪽 버튼들 위에 둔다 */
  .sit-prompt {
    left: auto;
    right: 14px;
    bottom: max(66px, calc(env(safe-area-inset-bottom) + 50px));
    transform: none;
    min-height: 46px;
    padding: 0 22px;
    font-size: 15px;
  }

  .person { bottom: max(158px, calc(env(safe-area-inset-bottom) + 142px)); }

  /* 소리 버튼은 앉았을 때만 */
  #sound-button { display: none; }
  .sitting #sound-button { display: block; }

  .plate strong { display: none; }
  #seated { display: none; }

  /* 앉았을 때: 시계는 왼쪽 위, 호실과 인원은 오른쪽 위에 둬서 한 줄에 들어가게 한다 */
  .sitting .plate { left: auto; right: 10px; top: max(10px, env(safe-area-inset-top)); font-size: 12px; }
  .sitting .plate span, .sitting #people { padding: 6px 8px; font-size: 12px; }
  .sitting .people-panel { left: auto; right: 10px; top: calc(max(10px, env(safe-area-inset-top)) + 34px); width: 190px; }

  /* 공지: 호실 칸 바로 아래에 작게. 호실 칸이 있는 쪽에 붙는다. */
  .notice {
    top: calc(max(14px, env(safe-area-inset-top)) + 38px);
    left: 14px;
    right: auto;
    transform: none;
    gap: 4px;
    max-width: min(300px, calc(100vw - 28px));
    padding: 2px 2px 2px 8px;
    font-size: 11px;
  }
  .notice button { min-height: 26px; padding: 0 6px; font-size: 10.5px; }
  .notice #notice-close { padding: 0 5px; font-size: 13px; }
  .sitting .notice {
    top: calc(max(10px, env(safe-area-inset-top)) + 32px);
    left: auto;
    right: 10px;
    max-width: calc(100vw - 180px);
  }

  /* 앉았을 때의 시계: 왼쪽 위 구석에 작게 */
  .sit-panel {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    transform: translateY(-160%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 4px;
    width: 148px;
    padding: 6px;
    border-bottom-width: 3px;
  }

  .sitting .sit-panel { transform: translateY(0); }
  .sit-label { display: none; }
  #sit-clock { grid-column: 1 / -1; font-size: 17px; }
  .sit-total, .sit-cheers { grid-column: 1 / -1; font-size: 10.5px; }
  #view-button, #stand-button { min-height: 30px; padding: 0 2px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .sit-panel, .toast, .stand-summary, .loading { transition: none; }
}
