:root {
  --accent: #3366ff;
  --accent-dark: #274bcc;
  --text: #16181d;
  --text-sub: #6b7280;
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --border: #e5e7eb;
  --danger: #e0455a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(16, 20, 30, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Pretendard', -apple-system, 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg-soft);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.logo span {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: none;
  color: var(--text-sub);
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.content {
  flex: 1;
  padding: 24px 20px 100px;
}

h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-sub);
  font-size: 14px;
  margin: 0 0 28px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 8px;
}

.field input {
  width: 100%;
  height: 50px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}

.field input::placeholder {
  color: var(--text-sub);
  opacity: 0.6;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
}

.btn:active {
  background: var(--accent-dark);
}

.btn.secondary {
  background: var(--bg-soft);
  color: var(--text);
}

.btn.danger {
  background: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
}

.login-center {
  display: flex;
  flex-direction: column;
}

.id-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.id-row input {
  flex: 1;
  min-width: 0;
}

.check-btn {
  flex: 0 0 auto;
  width: auto;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hint-msg {
  font-size: 12px;
  margin: 6px 0 0;
  min-height: 15px;
}

.hint-msg.ok {
  color: #1ca672;
}

.hint-msg.err {
  color: var(--danger);
}

.gender-group {
  display: flex;
  gap: 10px;
}

.gender-btn {
  flex: 1;
  height: 50px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-sub);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.gender-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 16px;
}

.switch-line {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-sub);
}

.switch-line a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 600;
}

.tabbar a svg {
  width: 22px;
  height: 22px;
}

.tabbar a.active {
  color: var(--accent);
}

.seg {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 20px;
}

.seg-btn {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  border-radius: 999px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--bg);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
}

.member-row:last-child {
  border-bottom: none;
}

.member-avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--bg-soft);
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.member-badge {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  padding: 1px 7px;
  border-radius: 999px;
}

.member-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 3px;
}

.member-cred {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 4px;
}

.member-cred b {
  color: var(--accent);
  font-weight: 700;
}

.member-count {
  flex: none;
  text-align: right;
  font-size: 12px;
  color: var(--text-sub);
}

.member-count b {
  display: block;
  font-size: 18px;
  color: var(--text);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.photo-grid .cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
}

.photo-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-grid .owner-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-sub);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 14px;
  color: var(--border);
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 18px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  color: #fff;
}

/* viewer */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.92);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.viewer img {
  max-width: 92%;
  max-height: 70%;
  border-radius: 12px;
  object-fit: contain;
}

.viewer-actions {
  display: flex;
  gap: 14px;
  margin-top: 24px;
}

.viewer-actions button {
  padding: 12px 22px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
}

.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-sub);
  font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f2f3f5;
    --text-sub: #9aa0ab;
    --bg: #17181c;
    --bg-soft: #202126;
    --border: #2b2d33;
  }
}

/* ---- editor (always dark, regardless of system theme) ---- */
.editor-page {
  --text: #f2f3f5;
  --text-sub: #9aa0ab;
  --bg: #121317;
  --bg-soft: #1c1d22;
  --border: #2a2b31;
  background: var(--bg);
}

.editor-page .app {
  background: var(--bg);
}

.editor-page .topbar {
  background: var(--bg);
  border-bottom-color: var(--border);
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.canvas-wrap canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  border-radius: 12px;
  touch-action: none;
  will-change: transform;
}

/* 브러시 조준 링 - 손가락에 가려지는 지점을 화면에 표시 */
.brush-ring {
  position: fixed;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 40;
  display: none;
}

/* 다리 늘리기 기준선 - 이 아래가 늘어남 */
.leg-guide {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  pointer-events: none;
  z-index: 30;
  display: none;
}

.leg-guide .leg-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  border-top: 2px dashed rgba(51, 130, 255, 0.95);
}

.leg-guide .leg-handle {
  position: absolute;
  right: 12px;
  top: 0;
  transform: translateY(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: auto;
  touch-action: none;
  white-space: nowrap;
}

.undo-btn {
  position: absolute;
  left: 20px;
  top: 20px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.undo-btn svg {
  width: 20px;
  height: 20px;
}

.undo-btn:active {
  background: var(--accent);
}

.zoom-badge {
  position: absolute;
  left: 24px;
  bottom: 24px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  z-index: 40;
  display: none;
}

.dropzone {
  width: 300px;
  max-width: 84%;
  border: 1.5px dashed var(--border);
  border-radius: 18px;
  padding: 44px 24px;
  text-align: center;
  color: var(--text-sub);
  background: var(--bg-soft);
}

.dropzone svg {
  width: 44px;
  height: 44px;
  margin-bottom: 16px;
  color: var(--accent);
  opacity: 0.85;
}

.dropzone p {
  font-size: 15px;
  margin: 0;
}

.dropzone .btn {
  max-width: 220px;
  margin: 20px auto 0;
}

.compare-btn {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  touch-action: none;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.compare-btn.visible {
  display: flex;
}

.compare-btn.holding {
  background: var(--accent);
}

.compare-btn svg {
  width: 20px;
  height: 20px;
}

.editor-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

.editor-tabs button {
  flex: 1;
  padding: 8px 0 7px;
  background: none;
  border: none;
  outline: none;
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.editor-tabs button svg {
  width: 18px;
  height: 18px;
}

.editor-tabs button.active {
  color: var(--accent);
}

.param-chip:focus {
  outline: none;
}

.editor-panel {
  background: var(--bg-soft);
  padding: 12px 16px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  min-height: 96px;
  max-height: 40vh;
  overflow-y: auto;
}

.slider-row {
  margin-bottom: 11px;
}

.slider-row:last-child {
  margin-bottom: 0;
}

.slider-row .slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.slider-row .slider-label span.val {
  color: var(--text);
}

.slider-row input[type='range'] {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
}

.slider-row input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
}

.slider-panel-scroll {
  overflow: visible;
}

/* 항목 칩 + 단일 슬라이더 (인스타/라이트룸 방식) */
.param-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 12px;
}

.param-chips::-webkit-scrollbar {
  display: none;
}

.param-chip {
  flex: none;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.param-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.param-slider {
  padding: 4px 2px 2px;
}

.panel-mini-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 8px;
}

.tool-panel {
  padding-top: 4px;
}

.tool-panel .chips {
  margin-bottom: 0;
}

.param-slider .slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.param-slider .slider-label .val {
  color: var(--text);
}

.param-slider input[type='range'] {
  display: block;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
  margin: 0;
}

.param-slider input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.param-slider input[type='range']::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
}

.panel-placeholder {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  padding: 30px 0;
}

.save-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.save-btn:disabled {
  opacity: 0.4;
}

/* ===== before/after 분할 슬라이더 ===== */
.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
  z-index: 41;
  transform: translateX(-1px);
  touch-action: none;
}

.compare-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  cursor: ew-resize;
}

.compare-knob::before {
  content: '⟺';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-size: 15px;
}

.compare-label {
  position: absolute;
  top: 14px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: 999px;
}

.compare-label.compare-before {
  right: 8px;
}

.compare-label.compare-after {
  left: 8px;
}

/* ===== 자르기 모드 ===== */
#cropOverlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: #0f1013;
  display: flex;
  flex-direction: column;
}

.crop-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid #2a2b31;
}

.crop-cancel,
.crop-apply {
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 6px;
}

.crop-cancel {
  color: #9aa0ab;
}

.crop-apply {
  color: var(--accent);
}

.crop-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 20px;
  touch-action: none;
}

.crop-canvas-holder {
  position: relative;
  touch-action: none;
}

.crop-canvas-holder canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.crop-rect {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
  touch-action: none;
  cursor: move;
}

.crop-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.4) 1px, transparent 1px);
  background-size: 33.33% 33.33%;
  background-position: -1px -1px;
  pointer-events: none;
}

.crop-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  touch-action: none;
}

.crop-handle.tl { left: -3px; top: -3px; border-right: none; border-bottom: none; }
.crop-handle.tr { right: -3px; top: -3px; border-left: none; border-bottom: none; }
.crop-handle.bl { left: -3px; bottom: -3px; border-right: none; border-top: none; }
.crop-handle.br { right: -3px; bottom: -3px; border-left: none; border-top: none; }

.crop-tools {
  background: var(--bg-soft);
  padding: 14px 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.crop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: rgba(20, 21, 26, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
  max-width: 85vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
