:root {
  --paper: #f6f0e3;
  --card: #fffaf0;
  --ink: #2f2a24;
  --soft: #6d6456;
  --line: #d9cdb7;
  --accent: #b5532f;
  --accent-ink: #fff8ee;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); overflow: hidden; overscroll-behavior: none; }
[hidden] { display: none !important; }
#gl { position: fixed; left: 0; top: 0; width: 100%; height: 100%; display: block; touch-action: none; z-index: 1; }
button, input { font: inherit; color: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 11px; font-size: 13px; }
.btn.big { min-height: 56px; font-size: 18px; padding: 0 26px; }
.btn:focus-visible, .act:focus-visible, .pill:focus-visible, .chip:focus-visible, .sw:focus-visible, .step:focus-visible, .tab:focus-visible, .preset:focus-visible { outline: 3px solid #2a6b78; outline-offset: 2px; }

#title { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(180deg, #e7efe6 0%, #f6f0e3 60%, #e6d6b7 100%); z-index: 5; }
.title-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.eyebrow { margin: 0; font-size: 13px; color: var(--soft); font-weight: 600; }
.title-card h1 { margin: 0; font-size: 38px; line-height: 1.2; letter-spacing: 0; font-weight: 800; }
#title-sub { margin: 0 0 10px; line-height: 1.55; color: var(--soft); }
.fine { font-size: 12.5px; line-height: 1.5; color: var(--soft); margin: 6px 0 0; }
.fine.light { color: #fff; background: rgba(38,32,26,.62); padding: 4px 10px; border-radius: 12px; text-align: center; margin-top: 4px; }

#studio { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 2; padding-top: env(safe-area-inset-top); }
body[data-screen="studio"] #gl { pointer-events: none; }
#steps { display: flex; gap: 2px; overflow-x: auto; padding: 6px 8px; border-bottom: 1px solid var(--line); flex: none; scrollbar-width: none; background: var(--paper); z-index: 4; }
.step { flex: none; border: 0; background: none; padding: 7px 9px; font-size: 13px; font-weight: 600; color: var(--soft); border-radius: 8px; cursor: pointer; min-height: 36px; }
.step.on { background: var(--ink); color: var(--paper); }

#ref { flex: none; position: relative; z-index: 4; display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #ece3d1; min-height: 56px; }
#ref.folded .ref-canvas { display: none; }
.ref-canvas { height: 15vh; min-height: 84px; max-width: 58%; object-fit: contain; border-radius: 6px; cursor: crosshair; display: block; touch-action: none; }
.ref-empty { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ref-note { margin: 0; font-size: 12px; color: var(--soft); flex-basis: 100%; }
.ref-samples { display: flex; flex-wrap: wrap; gap: 4px; }
.ref-tools { display: flex; flex-direction: column; gap: 4px; margin-left: auto; }

#stage { flex: 1 1 auto; min-height: 0; position: relative; touch-action: none; user-select: none; z-index: 4; overflow: hidden; }
#overlay { position: absolute; pointer-events: none; z-index: 2; }
#cursor { position: absolute; border: 2px solid #fff; outline: 1px solid #1a1a1a; border-radius: 50%; pointer-events: none; z-index: 3; }

#tools { flex: none; max-height: 40vh; overflow-y: auto; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); z-index: 4; position: relative; display: flex; flex-direction: column; gap: 7px; }
.tool-title { margin: 0; font-size: 13px; line-height: 1.45; color: var(--soft); }
.tool-title.warn { color: var(--accent); font-weight: 600; }
.hint { margin: 0; font-size: 12px; color: var(--soft); }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 6px; }
.preset { display: flex; align-items: center; gap: 8px; text-align: left; padding: 7px; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; line-height: 1.3; }
.preset.on { border: 2px solid var(--accent); padding: 6px; }
.preset-sw { width: 28px; height: 28px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.2); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: none; }
.tab { flex: none; border: 1px solid var(--line); background: #fff; padding: 0 12px; min-height: 38px; border-radius: 19px; font-size: 13px; font-weight: 600; cursor: pointer; }
.tab.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.slider { display: grid; grid-template-columns: 102px 1fr; align-items: center; gap: 8px; font-size: 13px; min-height: 34px; }
.slider input { width: 100%; accent-color: var(--accent); height: 28px; }
.view-row { display: flex; flex-wrap: wrap; gap: 4px; }
.sw-row { display: flex; align-items: center; gap: 5px; overflow-x: auto; scrollbar-width: none; }
.sw-row.wrap { flex-wrap: wrap; overflow: visible; }
.sw-label { font-size: 12px; width: 56px; flex: none; color: var(--soft); }
.sw { width: 32px; height: 32px; flex: none; border-radius: 50%; border: 1px solid rgba(0,0,0,.32); cursor: pointer; padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.sw-custom { width: 36px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.eye-row { display: flex; flex-direction: column; gap: 5px; }
.habit { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.habit legend { padding: 0 0 3px; font-size: 13px; font-weight: 700; }
.chip { border: 1px solid var(--line); background: #fff; padding: 0 11px; min-height: 36px; border-radius: 18px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.text-row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.text-row input { min-height: 42px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.nav-row { display: flex; gap: 6px; position: sticky; bottom: -8px; padding: 6px 0 2px; background: var(--card); }
.nav-row .btn { flex: 1; }

#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud-touch { position: absolute; inset: 0; touch-action: none; }
.hud-top { position: absolute; left: 10px; right: 10px; top: calc(8px + env(safe-area-inset-top)); display: flex; justify-content: space-between; align-items: center; pointer-events: none; gap: 6px; }
.hud-top > * { pointer-events: auto; }
.hud-right { display: flex; gap: 5px; }
.pill { background: rgba(38,32,26,.68); color: #fff; border: 0; min-height: 36px; padding: 0 12px; border-radius: 18px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; }
#hud-name { cursor: default; }
#hud .sheet { position: absolute; left: 8px; right: 8px; bottom: calc(68px + env(safe-area-inset-bottom)); background: rgba(255,250,240,.97); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 2px 12px rgba(0,0,0,.25); z-index: 2; }
#hud .sheet[hidden] { display: none !important; }
.sheet p { margin: 0; font-size: 13px; font-weight: 700; color: var(--soft); }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.sheet-grid .act { background: #f1e9d8; min-height: 46px; box-shadow: none; }
#actions .act.on { background: var(--accent); color: var(--accent-ink); }
#pills { position: absolute; right: 10px; bottom: calc(72px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-end; gap: 5px; pointer-events: none; }
#pills .pill { pointer-events: auto; min-height: 40px; }
.pill.strong { background: var(--accent); color: var(--accent-ink); }
.skip { position: absolute; right: 10px; top: calc(52px + env(safe-area-inset-top)); }
#gate-panel { position: absolute; left: 0; right: 0; bottom: calc(44px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#gate-panel > * { pointer-events: auto; }
#actions { position: absolute; left: 8px; right: 8px; bottom: calc(10px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; pointer-events: none; }
.act { pointer-events: auto; min-height: 50px; border: 0; border-radius: 12px; background: rgba(255,250,240,.94); font-size: 13.5px; font-weight: 700; cursor: pointer; padding: 2px; color: var(--ink); line-height: 1.2; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
#joy { position: absolute; left: 14px; bottom: calc(72px + env(safe-area-inset-bottom)); width: 100px; height: 100px; border-radius: 50%; background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.55); touch-action: none; display: flex; align-items: center; justify-content: center; }
#joy-knob { width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.86); box-shadow: 0 1px 3px rgba(0,0,0,.35); }

@media (min-width: 900px) {
  #studio { flex-direction: row; flex-wrap: wrap; }
  #steps { width: 100%; }
  #ref { width: 260px; flex-direction: column; align-items: stretch; height: calc(100vh - 50px); }
  .ref-canvas { height: auto; max-width: 100%; width: 100%; }
  #stage { flex: 1 1 0; height: calc(100vh - 50px); }
  #tools { width: 380px; max-height: none; height: calc(100vh - 50px); border-top: 0; border-left: 1px solid var(--line); }
  body[data-screen="studio"] #steps { justify-content: center; }
}

#talk-form { display: flex; gap: 5px; }
#talk-input { flex: 1; min-width: 0; min-height: 44px; border: 1px solid #cfc6b2; border-radius: 10px; padding: 0 10px; font: inherit; font-size: 16px; background: #fff; color: #1d3a36; }
#talk-form .act { flex: none; width: 76px; min-height: 44px; background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.sheet-grid .act.strong { background: var(--accent); color: var(--accent-ink); }

/* 하늘 섬 화면과 창 */
#fade { position: fixed; inset: 0; background: #fffdf6; opacity: 0; pointer-events: none; z-index: 8; }
#toast { position: fixed; left: 50%; top: calc(58px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 12; background: rgba(38,32,26,.86); color: #fff; font-size: 13px; line-height: 1.4; padding: 8px 12px; border-radius: 12px; max-width: min(90vw, 420px); pointer-events: none; }
#sky-ui { position: fixed; inset: 0; z-index: 3; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }
.sky-top, .sky-bottom { padding: calc(10px + env(safe-area-inset-top)) 12px 0; display: flex; flex-direction: column; gap: 8px; }
.sky-bottom { padding: 0 12px calc(12px + env(safe-area-inset-bottom)); }
.sky-top > *, .sky-bottom > * { pointer-events: auto; }
.sky-brand { display: flex; justify-content: space-between; align-items: center; gap: 8px; pointer-events: none; }
.sky-brand button { pointer-events: auto; }
.sky-brand h1 { margin: 0; font-size: 20px; font-weight: 800; color: #1d3a36; background: rgba(255,253,246,.85); padding: 3px 10px; border-radius: 10px; }
#sky-q { min-height: 44px; border: 1px solid #d8dfd2; border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fffdf6; color: #1d3a36; width: 100%; }
.sky-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
#sky-ui .chip, .wish-list .chip { flex: none; min-height: 38px; padding: 0 12px; border-radius: 19px; border: 0; background: rgba(255,253,246,.92); color: #1d3a36; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: #2f5d62 !important; color: #fff !important; }
#sky-status { margin: 0; align-self: center; font-size: 13px; background: rgba(255,253,246,.82); color: #1d3a36; padding: 3px 10px; border-radius: 10px; text-align: center; }
#sky-status:empty { display: none; }
.sky-card { background: #fffdf6; color: #1d3a36; border-radius: 14px; padding: 12px; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 12px; box-shadow: 0 3px 16px rgba(30,60,60,.25); width: min(480px, 100%); align-self: center; }
.sky-card canvas { width: 84px; height: 84px; border-radius: 10px; display: block; }
.sky-card h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.sky-card p { margin: 0; color: #4f6a64; font-size: 14px; }
.sky-card .info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sky-card .acts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.sky-card .acts .btn { flex: 1 1 40%; padding: 0 8px; }
.sky-main { display: flex; gap: 6px; width: min(480px, 100%); align-self: center; }
.sky-main .btn { flex: 1; padding: 0 8px; background: #fffdf6; color: #1d3a36; }
.sky-main .btn.primary { background: var(--accent); color: var(--accent-ink); }
.modal { position: fixed; inset: 0; z-index: 11; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(28,44,48,.45); }
.modal-card { width: min(420px, 100%); max-height: 88vh; overflow-y: auto; background: #fffdf6; color: #1d3a36; border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.modal-card > div:not(.scroll):not(.wish-list) { display: flex; flex-direction: column; gap: 10px; }
.modal-card h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.modal-card h3 { margin: 4px 0 0; font-size: 15px; }
.modal-card p { margin: 0; color: #4f6a64; font-size: 14px; line-height: 1.5; }
.modal-card input[type="text"], .modal-card textarea { width: 100%; border: 1px solid #cfd8cd; border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px; background: #fff; color: #1d3a36; }
#make-preview { width: 128px; height: 128px; border-radius: 12px; align-self: center; }
.scroll { max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.scroll p { color: #1d3a36; }
.wish-list { display: flex; flex-wrap: wrap; gap: 6px; }
.wish-list .chip { background: #f1e9d8; white-space: normal; text-align: left; padding: 6px 12px; }
.log-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.log-row .btn { flex: none; min-height: 36px; padding: 0 10px; }

/* 로그인과 관리 */
.modal { z-index: 11; }
#login-sheet { z-index: 13; }
#log-sheet, #memory-sheet { z-index: 12; }
.modal-head { display: flex !important; flex-direction: row !important; justify-content: space-between; align-items: center; }
.link { background: none; border: 0; color: #4f6a64; font-size: 14px; cursor: pointer; min-height: 40px; padding: 0 4px; }
.kakao { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border: 0; border-radius: 12px; background: #fee500; color: #191600; font-weight: 700; font-size: 16px; cursor: pointer; }
.kakao[hidden] { display: none; }
.login-or { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px; color: #7a8c86; font-size: 13px; }
.login-or::before, .login-or::after { content: ''; flex: 1; height: 1px; background: #d8dfd2; }
.login-row { display: flex !important; flex-direction: row !important; gap: 6px; }
.login-row[hidden] { display: none !important; }
.login-row input { flex: 1; min-width: 0; min-height: 44px; border: 1px solid #cfd8cd; border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fff; color: #1d3a36; }
.login-row .btn { flex: none; padding: 0 12px; }
.modal-card .login-fine { font-size: 12px; color: #6d7f79; }
.login-fine a { color: inherit; }
.mg-top { display: flex !important; flex-direction: row !important; gap: 12px; align-items: center; }
#mg-photo { width: 84px; height: 84px; border-radius: 10px; flex: none; }
.mg-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.btn.danger { color: #a33d3a; border-color: #e2c2bf; }
#login-email { gap: 6px; }

/* 오른쪽 아래 동그란 버튼 */
#rounds { position: absolute; right: 10px; bottom: calc(68px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, 56px); gap: 6px; direction: rtl; pointer-events: none; }
#rounds[hidden] { display: none; }
.round { position: relative; direction: ltr; pointer-events: auto; width: 56px; height: 56px; border-radius: 50%; border: 1px solid rgba(255,255,255,.28); background: rgba(24,34,44,.72); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; font-weight: 600; cursor: pointer; padding: 0; }
.round[aria-expanded="true"], .round.on { background: rgba(200,160,90,.85); }
.badge { position: absolute; top: -4px; right: -2px; min-width: 20px; height: 18px; padding: 0 5px; border-radius: 9px; background: #d9b56a; color: #2a2010; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.badge[hidden] { display: none; }
#pills { bottom: calc(196px + env(safe-area-inset-bottom)) !important; }
#hud .sheet { z-index: 2; }
