:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --text: #1c2b33;
  --muted: #5f7480;
  --line: #d8e1e6;
  --primary: #0e7c86;
  --primary-text: #ffffff;
  --danger: #c0392b;
  --marker: #0e7c86;
  --marker-has: #d9730d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); text-decoration: none; }

/* 상단 메뉴: 로고 옆에 기능 메뉴, 오른쪽 끝에 계정 */
.topnav { display: flex; align-items: center; gap: 4px; margin-right: auto; padding-left: 16px; border-left: 1px solid var(--line); }
.nav-btn, .user-link, .logout-btn {
  font: inherit;
  font-size: .92rem;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.nav-btn { font-weight: 600; }
.nav-btn:hover, .user-link:hover, .logout-btn:hover { background: var(--bg); color: var(--primary); }
.nav-btn:focus-visible, .user-link:focus-visible, .logout-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.userbox { display: flex; align-items: center; gap: 2px; margin: 0; }
.user-name { font-size: .92rem; font-weight: 600; }
span.user-name { padding: 6px 10px; }
.logout-btn { color: var(--muted); }
.userbox .logout-btn { position: relative; margin-left: 6px; }
.userbox .logout-btn::before { content: ""; position: absolute; left: -4px; top: 8px; bottom: 8px; border-left: 1px solid var(--line); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 16px 0 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.narrow { max-width: 420px; margin: 32px auto; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
.field-row > label { flex: 1; min-width: 0; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }

/* label처럼 display를 지정한 요소도 hidden 속성으로 숨길 수 있게 한다 */
[hidden] { display: none !important; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  background: #e1f1f2;
  color: #0a5c64;
  font-size: .8rem;
  font-weight: 600;
}

input, textarea, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, .btn:focus-visible, .marker:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.small { padding: 4px 10px; font-size: .85rem; }

.hint { color: var(--muted); font-size: .9rem; margin: 8px 0; }
.flash {
  background: #fdecea;
  border: 1px solid #f3b7b0;
  color: #8a2319;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 16px;
}
.flash.success { background: #e6f4ea; border-color: #a8d5b5; color: #1e5c33; }

/* 회원가입의 약관 동의 */
.agreements { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.agreements legend { font-size: .9rem; font-weight: 600; padding: 0 4px; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { width: auto; margin-top: 4px; flex: none; }

/* 약관 화면 */
.terms { max-width: 760px; margin: 32px auto; }
.terms section { margin-top: 28px; }
.terms h2 { margin-bottom: 8px; }
.terms p { margin: 6px 0; }
.terms table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: .92rem; }
.terms th, .terms td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.terms th { width: 96px; background: var(--bg); white-space: nowrap; }

/* 회원가입의 약관 팝업: 제목과 닫기 버튼은 고정하고 본문만 스크롤한다 */
.terms-modal { width: min(760px, calc(100vw - 32px)); }
.terms-modal[open] { display: flex; flex-direction: column; }
.terms-modal .modal-head { padding: 20px 20px 0; margin-bottom: 0; }
.terms-modal .modal-foot { padding: 12px 20px 20px; margin-top: 0; border-top: 1px solid var(--line); }
.terms-scroll.terms { position: relative; max-width: none; margin: 12px 0 0; padding: 0 20px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.terms-scroll.terms section:first-child { margin-top: 0; }

/* 회원정보 화면 */
.account { max-width: 420px; margin: 32px auto; display: flex; flex-direction: column; gap: 16px; }
.account h2 { margin-bottom: 12px; }
.account input:disabled { background: var(--bg); color: var(--muted); }
.danger-zone { border-color: #f3b7b0; }
.danger-zone h2 { color: var(--danger); }

.default-photo { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.default-photo img { display: block; width: 100%; border-radius: 8px; border: 1px solid var(--line); margin: 12px 0; }
.default-photo form { margin: 0; }
.default-photo .btn { width: 100%; }

.guest-login { margin: 16px 0 0; text-align: right; }
.guest-login .btn { color: var(--muted); font-weight: 400; }
.guest-note { margin: 0 0 12px; }

/* 작업 화면 */
.workspace { display: block; }

/* 팝업 */
.modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(15, 30, 38, .55); }
.modal-body { padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-foot .danger { margin-right: auto; }
.modal .flash { margin: 0 0 12px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar form { margin: 0; }
.toolbar label.btn { flex-direction: row; }

.stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}
.stage img { display: block; max-width: 100%; max-height: 78vh; user-select: none; }

/* 사진 확대: 사진만 넓어지고 번호 크기는 그대로라서 번호 사이가 벌어진다 */
.zoom { display: flex; gap: 4px; margin-left: auto; }
.stage-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stage { vertical-align: top; }
.stage.zoomed { max-width: none; }
.stage.zoomed img { width: 100%; max-width: none; max-height: none; }
.stage.editing { cursor: crosshair; }

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 15px;
  border: 2px solid #fff;
  background: var(--marker);
  color: #fff;
  font: 700 14px/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.marker.has-records { background: var(--marker-has); }
.marker.selected { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--primary); }
.stage.editing .marker { cursor: grab; touch-action: none; }
.stage.editing .marker.dragging { cursor: grabbing; }

/* 좁은 화면(폰): 숫자 크기는 거의 그대로 두고 원만 줄여 번호끼리 덜 겹치게 한다 */
@media (max-width: 640px) {
  .marker {
    min-width: 20px;
    height: 20px;
    padding: 0 2px;
    border-width: 1px;
    border-radius: 10px;
    font-size: 12px;
  }
  .marker.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary); }
}

.record-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.record-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: .92rem;
}
.record-list .meta { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.record-list .date { font-variant-numeric: tabular-nums; }
.record-list p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.record-list .memo { color: var(--muted); }
.record-list .actions { display: flex; gap: 6px; margin-top: 10px; }
.record-list .empty { border-style: dashed; color: var(--muted); text-align: center; }
