:root {
  --bg: #fff8f1;
  --card: #ffffff;
  --line: #f1e2d3;
  --text: #2b2420;
  --muted: #8a7b70;
  --accent: #f08a3c;
  --accent-d: #d96f22;
  --accent-l: #ffe9d6;
  --pink: #f6b9c4;
  --danger: #d9534f;
  --ok: #3a9d5d;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(120, 70, 30, .07);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); padding-bottom: 96px; }
a { color: var(--accent-d); }
code { background: #f6eee7; padding: 1px 5px; border-radius: 5px; font-size: .92em; word-break: break-all; }
[hidden] { display: none !important; }

/* 머리글 */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: rgba(255, 240, 225, .94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); text-decoration: none; }
.brand img { object-fit: contain; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--text); text-decoration: none; font-size: 14px; }
.tabs a.on { background: var(--accent); color: #fff; font-weight: 700; }
.tabs a:hover:not(.on) { background: var(--accent-l); }
.chip { margin-left: auto; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); }
.chip.ok { border-color: #bfe3cb; color: var(--ok); }
.chip.warn { border-color: #f3c7a6; color: var(--accent-d); }

main { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.title { text-align: center; font-size: 30px; margin: 28px 0 4px; letter-spacing: -.5px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.view.help .sub, #view-usage .sub, #view-settings .sub { text-align: left; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 16px 0; position: relative; }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-h h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.pre { white-space: pre-line; }
.empty { text-align: center; color: var(--muted); padding: 26px 0; margin: 0; }
.tip { background: #fff6ec; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

/* 단추 */
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 10px; padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #fff3e8; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: var(--accent-d); }
.btn.danger { color: var(--danger); border-color: #f0c9c7; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 16px; border-radius: 12px; }
.link { background: none; border: 0; color: var(--accent-d); cursor: pointer; font: inherit; font-size: 14px; padding: 2px 4px; }
.link:hover { text-decoration: underline; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 36px; height: 36px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: #fff3e8; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.check.small { margin: 0; }

/* 알림 띠 */
.banner { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 12px 0; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.text { display: block; line-height: 1.7; }
.banner.warn { background: #fff4e5; border-color: #f6cf9e; }
.banner.test { background: #eef6ff; border-color: #c7dcf5; justify-content: flex-start; }
.banner.cloud { background: #f2f8f4; border-color: #cfe7d6; }

/* 캐릭터 */
.char-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.char { border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 8px 6px 6px; cursor: pointer; text-align: center; position: relative; font: inherit; }
.char:hover { border-color: #f5c7a0; }
.char.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-l); }
.char img { width: 100%; height: 84px; object-fit: contain; display: block; }
.char span { display: block; font-size: 13px; font-weight: 700; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char.upload { border-style: dashed; color: var(--accent-d); display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 120px; }
.char.upload b { font-size: 26px; line-height: 1; }
.char .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; cursor: pointer; display: none; }
.char:hover .x { display: block; }
.char-detail { display: grid; grid-template-columns: 140px 1fr; gap: 14px; margin-top: 14px; align-items: start; }
.char-detail .big { width: 140px; height: 140px; object-fit: contain; background: #fffaf5; border-radius: 12px; border: 1px solid var(--line); }
.char-detail label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.drop-hint { position: absolute; inset: 0; border-radius: var(--radius); border: 3px dashed var(--accent); background: rgba(255, 233, 214, .85); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; color: var(--accent-d); z-index: 3; pointer-events: none; }

input, select, textarea { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: #fff; color: var(--text); width: 100%; }
select { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-l); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 8px 0; }
.form-grid label, label.block { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.block { margin: 8px 0; }
.form-grid select { width: 100%; }

/* 턴어라운드 */
.ta-box { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; }
.ta-view { min-height: 180px; border: 1px dashed var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #fffcf9; overflow: hidden; }
.ta-view img { max-width: 100%; max-height: 260px; object-fit: contain; cursor: zoom-in; }
.ta-view .ph { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }

/* 포즈 */
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pill-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.pill-tabs button .n { color: var(--muted); margin-left: 3px; }
.pill-tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pill-tabs button.on .n { color: #ffe3cc; }
.pose-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.pose { position: relative; border: 2px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; padding: 6px; text-align: center; user-select: none; }
.pose:hover { border-color: #f5c7a0; }
.pose.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-l); }
.pose .th { height: 92px; display: flex; align-items: center; justify-content: center; font-size: 46px; }
.pose .th img { max-width: 100%; max-height: 92px; object-fit: contain; }
.pose .nm { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pose .ck { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; line-height: 22px; display: none; }
.pose.on .ck { display: block; }
.pose .badge { position: absolute; top: 6px; left: 6px; font-size: 11px; background: #fff0e3; color: var(--accent-d); border-radius: 6px; padding: 1px 5px; }
.pose .acts { position: absolute; left: 4px; right: 4px; bottom: 28px; display: flex; justify-content: center; gap: 4px; opacity: 0; transition: opacity .15s; }
.pose:hover .acts, .pose:focus-within .acts { opacity: 1; }
.pose .acts button { border: 0; background: rgba(255,255,255,.95); box-shadow: 0 1px 4px rgba(0,0,0,.18); border-radius: 8px; padding: 3px 6px; font-size: 13px; cursor: pointer; }
.pose.add { border-style: dashed; color: var(--accent-d); display: flex; flex-direction: column; justify-content: center; min-height: 128px; }

/* 아래 고정 막대 */
.sticky-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 15; width: min(940px, calc(100% - 24px)); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 6px 24px rgba(120, 70, 30, .16); padding: 10px 12px 10px 18px; display: flex; align-items: center; gap: 12px; }
.make-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.make-info .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 진행 */
.bar { height: 10px; border-radius: 99px; background: #f5ebe1; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #f6b06d); transition: width .4s; }
.bar.free i { background: linear-gradient(90deg, #4bb37a, #9fd8b3); }
.bar.over i { background: var(--danger); }

/* 결과 */
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 10px; }
.res { position: relative; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; cursor: pointer; }
.res.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-l); }
.res img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; background: repeating-conic-gradient(#f7f1ec 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.res .cap { font-size: 12px; padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-top: 1px solid var(--line); }
.res .ck { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff; background: rgba(0,0,0,.25); color: #fff; font-size: 13px; line-height: 18px; text-align: center; }
.res.on .ck { background: var(--accent); }
.res .tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.res:hover .tools, .res:focus-within .tools { opacity: 1; }
.res .tools button { border: 0; background: rgba(255,255,255,.95); box-shadow: 0 1px 4px rgba(0,0,0,.2); border-radius: 8px; width: 28px; height: 28px; cursor: pointer; font-size: 13px; }
.res .tag { position: absolute; bottom: 30px; right: 6px; font-size: 10px; background: #e7f0ff; color: #3567b5; padding: 1px 5px; border-radius: 5px; }
.res.wait { cursor: default; }
.res.wait .drawing { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 13px; background: #fffaf5; }
.res.failed .drawing { color: var(--danger); background: #fff5f4; padding: 8px; text-align: center; }
.fail-box { background: #fff5f4; border: 1px solid #f3cfcc; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 8px 0; }
.fail-box ul { margin: 6px 0; padding-left: 18px; }

/* 그리는 모션 */
.sketch { width: 90px; height: 90px; }
.sketch path, .sketch circle { fill: none; stroke: #c9a88c; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 260; stroke-dashoffset: 260; animation: draw 2.2s ease-in-out infinite; }
.sketch .p2 { animation-delay: .35s; } .sketch .p3 { animation-delay: .7s; } .sketch .p4 { animation-delay: 1s; }
@keyframes draw { 0% { stroke-dashoffset: 260; } 55%, 80% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -260; } }
.motion-stage { height: 260px; border-radius: 14px; background: #fffaf5; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.motion-stage img { max-height: 200px; max-width: 80%; animation: pop .5s ease-out both; }
.motion-stage .emo { position: absolute; top: 14px; right: 18px; font-size: 40px; animation: wob 1.2s ease-in-out infinite; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wob { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) translateY(-4px); } }

/* 메뉴 */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 6px; z-index: 10; min-width: 180px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; }
.menu button:hover { background: #fff3e8; }

/* 대화상자 */
.dlg { border: 0; border-radius: 18px; padding: 20px; width: min(480px, calc(100% - 24px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); color: var(--text); }
.dlg.wide { width: min(640px, calc(100% - 24px)); }
.dlg::backdrop { background: rgba(40, 25, 15, .45); }
.dlg h3 { margin: 0 0 10px; }
.dlg .opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; cursor: pointer; }
.dlg .opt:has(input:checked) { border-color: var(--accent); background: #fff8f1; }
.dlg .opt input { width: auto; margin-top: 4px; }
.check input, .opt input { width: auto; }
.view-dlg { width: min(720px, calc(100% - 24px)); }
.view-dlg img { width: 100%; max-height: 70vh; object-fit: contain; background: repeating-conic-gradient(#f7f1ec 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 12px; }

/* 키 목록 */
.key-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.key-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.key-row.off { opacity: .55; }
.key-row .meta { min-width: 0; }
.key-row .meta b { margin-right: 6px; }
.key-row .meta div { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prov { font-size: 11px; border-radius: 6px; padding: 1px 6px; background: #f2ede8; }
.prov.cloudflare { background: #fff0dd; color: #c26a00; }
.prov.gemini { background: #e8f0fe; color: #2d5fb8; }
.prov.openai { background: #e9f6ef; color: #23784b; }
.ok-t { color: var(--ok); } .bad-t { color: var(--danger); }

/* 사용량 */
.usage-card .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.stat { background: #fffaf5; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }
table.days { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
table.days th, table.days td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: right; }
table.days th:first-child, table.days td:first-child { text-align: left; }
.table-wrap { overflow-x: auto; }

/* 알림 */
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2b2420; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.2); max-width: min(560px, 92vw); white-space: pre-line; animation: tin .2s ease-out; }
.toast.err { background: #b23b37; }
.toast.ok { background: #2f7d4c; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

.foot { max-width: 980px; margin: 30px auto 0; padding: 16px; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.help ol li, .help ul li { margin: 6px 0; line-height: 1.6; }

@media (max-width: 640px) {
  .top { gap: 8px; padding: 8px 12px; }
  .brand span { font-size: 15px; }
  .title { font-size: 24px; }
  .char-detail { grid-template-columns: 1fr; }
  .char-detail .big { width: 100%; }
  .sticky-bar { padding: 8px; gap: 8px; }
  .btn.big { padding: 10px 14px; font-size: 15px; }
  .pose .acts { opacity: 1; }
  .res .tools { opacity: 1; }
}
.enter-default { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
