* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  background: #efe9dd; color: #2b2b2b;
}
#bar {
  flex: none; background: #fffaf0; border-bottom: 1px solid #ddd2bd;
  padding: 6px 8px calc(4px) 8px; padding-top: max(6px, env(safe-area-inset-top));
}
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 3px 0; }
#roomName { margin-right: 4px; font-size: 15px; }
button, select {
  font: inherit; font-size: 14px; border: 1px solid #cfc3ab; background: #fff; color: inherit;
  border-radius: 8px; padding: 6px 9px; cursor: pointer; touch-action: manipulation;
}
button.on { background: #3b3127; color: #fff; border-color: #3b3127; }
button:disabled { opacity: .5; }
select { max-width: 46vw; }
input[type=color] { width: 36px; height: 32px; padding: 0; border: 1px solid #cfc3ab; border-radius: 8px; background: #fff; }
input[type=range] { width: 90px; }
.status { font-size: 12px; color: #6b6256; gap: 8px; }
.peer { border: 2px solid; border-radius: 999px; padding: 1px 8px; background: #fff; color: #333; }

#stage { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 40px; }
.sheet { width: max-content; margin: 0 auto 18px; }
.sheetHead { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: 13px; color: #6b6256; }
.sheetHead .bgSel { font-size: 13px; padding: 3px 6px; }
.sheetLabel { font-weight: 600; margin-right: auto; }
.paper { position: relative; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.paper canvas { display: block; touch-action: none; background: #fffdf7; }
#sheets.hand canvas { touch-action: pan-x pan-y; }
#sheets.offline { opacity: .6; }
#addSheet { display: block; margin: 0 auto 30px; padding: 10px 18px; border-style: dashed; }
#addSheet[hidden] { display: none; }
button.small { padding: 3px 8px; font-size: 12px; }
button.title { border: none; background: none; font-weight: 700; font-size: 15px; padding: 6px 4px; }
#myRoomsBox h3 { margin: 6px 0 4px; font-size: 14px; }
#myRoomsBox[hidden] { display: none; }
#myRooms { max-height: 30vh; overflow: auto; }
.roomRow { display: flex; gap: 6px; align-items: stretch; }
.roomRow.current .roomPick { border-color: #3b3127; }
.roomPick { flex: 1; display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; }
.roomPick small { color: #7a7064; font-size: 12px; }

.editor {
  position: absolute; min-width: 120px; min-height: 1.4em; padding: 0; margin: 0;
  border: 1px dashed #888; background: rgba(255,255,255,.85); outline: none; resize: none; overflow: hidden;
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; white-space: pre;
}

#join {
  position: fixed; inset: 0; background: rgba(60,50,40,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
#join[hidden] { display: none; }
.card {
  background: #fffaf0; border-radius: 14px; padding: 20px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.card input { font: inherit; font-size: 16px; padding: 9px 10px; border: 1px solid #cfc3ab; border-radius: 8px; }
.primary { background: #3b3127; color: #fff; border-color: #3b3127; padding: 10px; }
.hint { font-size: 12px; color: #7a7064; margin: 0; }

.datebtn { position: relative; border: 1px solid #cfc3ab; background: #fff; border-radius: 8px; padding: 6px 9px; font-size: 14px; cursor: pointer; overflow: hidden; }
.datebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
dialog { border: none; border-radius: 14px; background: #fffaf0; width: min(420px, 94vw); padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(60,50,40,.5); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }
dialog h3 { margin: 16px 0 4px; font-size: 15px; }
.col { display: flex; flex-direction: column; gap: 6px; }
.bk { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.bk span { flex: 1; }
.bk button { padding: 4px 8px; font-size: 13px; }
dialog form { margin-top: 12px; text-align: right; }

#adBar { flex: none; display: flex; justify-content: center; background: #fffaf0; border-top: 1px solid #ddd2bd; padding-bottom: env(safe-area-inset-bottom); }
#adBar[hidden], #adJoin[hidden], #siteLinks[hidden] { display: none; }
#adJoin { display: flex; justify-content: center; }
.links a { color: #7a7064; }

button.danger { background: #e03131; color: #fff; border-color: #e03131; }

dialog.help { width: min(480px, 94vw); max-height: 86dvh; overflow: auto; }
.help section { border-top: 1px solid #e8dfcc; padding-top: 6px; margin-top: 8px; }
.help h3 { margin: 4px 0; }
.help ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.6; }
.help .red { color: #e03131; }
.helpFoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; bottom: -18px; background: #fffaf0; padding: 10px 0 2px; }
.helpFoot label { font-size: 14px; display: flex; align-items: center; gap: 6px; }

.styleBtns { display: inline-flex; gap: 2px; }
button.sty { min-width: 32px; padding: 6px 7px; font-family: Georgia, "Times New Roman", serif; }

/* ---------- 휴대폰 ---------- */
#moreBtn { display: none; }
.paper canvas { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#bar { -webkit-user-select: none; user-select: none; }
@media (max-width: 700px) {
  #bar { padding: 4px 6px 2px; padding-top: max(4px, env(safe-area-inset-top)); }
  .row { gap: 4px; margin: 2px 0; }
  button, select { font-size: 14px; padding: 5px 8px; }
  .lbl { display: none; }
  #moreBtn { display: inline-block; }
  .row.top { flex-wrap: nowrap; }
  #roomName { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
  #pageSel { max-width: 42vw; min-width: 0; }
  .row.more { display: none; }
  .row.more.open { display: flex; }
  /* 도구는 한 줄로, 넘치면 옆으로 밀어서 보기 */
  .row.tools { -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); }
  .row.tools { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .row.tools::-webkit-scrollbar { display: none; }
  .row.tools > * { flex: none; }
  input[type=range] { width: 70px; }
  #fontSel { max-width: 110px; }
  button.sty { min-width: 30px; padding: 5px 6px; }
  .row.status { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; font-size: 11px; gap: 6px; }
  .row.status .peer { padding: 0 6px; }
  #stage { padding-top: 6px; }
  .sheet { margin-bottom: 12px; }
}
