:root {
  --paper: #f4f1ea;
  --panel: #fffdf9;
  --ink: #26241f;
  --ink-2: #6b665c;
  --ink-3: #9c968a;
  --line: #e2ddd2;
  --line-2: #cfc8b9;
  --accent: #b9572f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e5dc;
  --danger: #c0392b;
  --ok: #3e7d4f;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(38, 36, 31, .12), 0 1px 3px rgba(38, 36, 31, .08);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* 공통 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); font-size: 15px; font-weight: 500; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: #e8c3bd; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.wide { width: 100%; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* 로그인 */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); }
.login-card input { height: 46px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fff; }
.login-sub { margin: -8px 0 4px; color: var(--ink-2); font-size: 14px; }
.login-card a.btn { text-decoration: none; color: var(--ink-2); }
.login-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: #fbeae7; color: var(--danger); font-size: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--ink); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 5px; top: 5px; width: 7px; height: 12px; border-radius: 1px; background: var(--paper); box-shadow: 6px 5px 0 -1px var(--accent); }

/* 앱 레이아웃 */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
.topbar .brand { font-size: 16px; }
.topbar .spacer { flex: 1; }
.layout-picker { display: flex; align-items: center; gap: 6px; min-width: 0; }
.layout-picker select { height: 38px; max-width: 46vw; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 30px 0 10px; background: #fff; font-size: 15px; font-weight: 600; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b665c' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.status { font-size: 12px; color: var(--ink-3); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status.saving .dot { background: #d8a33a; }
.status.error .dot { background: var(--danger); }
.user-btn { font-size: 14px; color: var(--ink-2); }

.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#stage { position: absolute; inset: 0; }
.mode-banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 13px; padding: 7px 14px; border-radius: 999px; box-shadow: var(--shadow); pointer-events: none; white-space: nowrap; }
.mode-banner[hidden] { display: none; }

/* 아래 도구 막대 */
.toolbar { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 4px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); z-index: 4; }
.toolbar .btn { border: none; min-height: 48px; padding: 0 12px; flex-direction: column; gap: 2px; font-size: 11px; font-weight: 600; color: var(--ink-2); background: transparent; min-width: 58px; }
.toolbar .btn svg { width: 22px; height: 22px; }
.toolbar .btn.on { background: var(--accent-soft); color: var(--accent); }
.toolbar .btn.main { background: var(--accent); color: #fff; }

/* 시트 (모바일: 아래, 넓은 화면: 오른쪽) */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 72%; background: var(--panel); border-top-left-radius: 18px; border-top-right-radius: 18px; box-shadow: 0 -8px 30px rgba(38,36,31,.16); z-index: 6; display: flex; flex-direction: column; transform: translateY(105%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; padding-bottom: var(--safe-b); }
.sheet.open { transform: none; visibility: visible; transition: transform .22s ease, visibility 0s; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px 18px; }
.sheet-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--line-2); }
.sheet-title { flex: 1; font-weight: 700; font-size: 17px; padding-top: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 6px 18px 18px; -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) {
  .sheet { left: auto; top: 12px; right: 12px; bottom: 12px; width: 360px; max-height: none; border-radius: 18px; transform: translateX(115%); padding-bottom: 0; }
  .sheet-head::before { display: none; }
  .sheet.open ~ .toolbar { transform: translateX(calc(-50% - 186px)); }
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); }
.field input, .field select { height: 44px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fff; color: var(--ink); width: 100%; }
.field .with-unit { position: relative; }
.field .with-unit input { padding-right: 40px; }
.field .with-unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: 14px; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1; }
.hint { font-size: 13px; color: var(--ink-2); line-height: 1.55; margin: 6px 0; }
.warn { font-size: 13px; color: var(--danger); background: #fbeae7; padding: 8px 10px; border-radius: 10px; margin: 8px 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-2); }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }

.palette-group { margin: 14px 0 6px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.palette button { display: grid; gap: 6px; justify-items: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-align: center; }
.palette button:active { background: var(--accent-soft); }
.palette .pv { width: 44px; height: 30px; display: grid; place-items: center; }
.palette .pv i { display: block; border: 1.5px solid var(--ink-2); border-radius: 3px; }
.palette .nm { font-size: 13px; font-weight: 600; }
.palette .sz { font-size: 11px; color: var(--ink-3); }

.list { display: grid; gap: 6px; }
.list button { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; text-align: left; font-size: 15px; }
.list button small { color: var(--ink-3); font-size: 12px; }

.toast { position: absolute; left: 50%; top: 58px; transform: translate(-50%, -20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); transition: all .2s ease; pointer-events: none; z-index: 10; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.zoom-ctl { position: absolute; right: 12px; top: 12px; display: grid; gap: 4px; z-index: 3; }
.zoom-ctl .btn { width: 40px; min-height: 40px; padding: 0; box-shadow: var(--shadow); border: none; font-size: 20px; }

@media (max-width: 520px) {
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .topbar .brand-text, .status .label { display: none; }
  .toolbar .btn { min-width: 52px; padding: 0 8px; }
}

/* 구매 정보 */
.buy-box { display: flex; gap: 12px; align-items: center; margin: 6px 0 4px; }
.photo-slot { width: 96px; height: 96px; flex: none; border-radius: 12px; border: 1px dashed var(--line-2); background: #fff; display: grid; place-items: center; overflow: hidden; color: var(--ink-3); font-size: 12px; cursor: pointer; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.buy-actions { display: grid; gap: 6px; }
.buy-actions [hidden] { display: none; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fff; }
.link-row .btn { min-height: 44px; }
