:root {
  --bg: #06070b;
  --ink: #eef0f7;
  --ink-2: #a4a9bd;
  --ink-3: #6d7288;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --panel: rgba(14, 16, 26, .66);
  --violet: #a193ff;
  --mint: #5cf2c4;
  --amber: #ffb86b;
  --rose: #ff6b8b;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --split: 50%;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); overflow: hidden;
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', sans-serif;
  letter-spacing: -0.011em; word-break: keep-all; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
kbd { font: 500 11.5px ui-monospace, 'SF Mono', Menlo, monospace; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04); }
kbd kbd { border: 0; padding: 0; background: none; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; border-radius: 8px; }

#gl { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity 1.4s var(--ease); }
.is-ready [data-view="start"] #gl { opacity: 1; }
.atmos {
  position: fixed; inset: -10%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 35% at 50% 25%, rgba(120, 100, 255, .16), transparent 70%),
    radial-gradient(35% 30% at 12% 85%, rgba(60, 220, 180, .06), transparent 70%),
    var(--bg);
}
.grain {
  position: fixed; inset: 0; z-index: 90; pointer-events: none; opacity: .05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Start ---------- */
.start { position: fixed; inset: 0; z-index: 2; overflow-y: auto; display: flex; flex-direction: column; }
[data-view="work"] .start { opacity: 0; pointer-events: none; transform: scale(.98); transition: opacity .4s, transform .4s; }
[data-view="start"] .app { display: none; }
.start-brand { position: absolute; top: calc(22px + env(safe-area-inset-top)); left: clamp(18px, 4vw, 40px); display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13px; letter-spacing: .14em; }
.start-brand svg, .home svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.start-brand svg circle, .home svg circle { fill: currentColor; stroke: none; }
.start-inner {
  margin: auto; width: min(760px, 100%); padding: 44vh 22px calc(40px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.eyebrow { margin: 0 0 16px; font: 500 12.5px ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .1em; color: var(--ink-3); }
.start h1 { margin: 0; font-size: clamp(40px, 6.4vw, 72px); line-height: 1.05; letter-spacing: -0.045em; font-weight: 750; }
.start h1 em { font-style: normal; background: linear-gradient(100deg, #c9c2ff, var(--violet) 40%, var(--mint)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.start-sub { margin: 18px 0 0; color: var(--ink-2); font-size: 17px; line-height: 1.6; }
.br-d { display: none; }
@media (min-width: 700px) { .br-d { display: inline; } }

.choices { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 36px; }
.choice {
  display: flex; align-items: center; gap: 14px; padding: 16px; text-align: left; border-radius: 20px;
  background: rgba(16, 18, 28, .6); border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  transition: border-color .3s, background .3s, transform .4s var(--ease);
}
.choice:hover { border-color: var(--line-2); background: rgba(24, 26, 40, .7); transform: translateY(-2px); }
.choice:active { transform: scale(.98); }
.c-icon { flex: none; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font: 700 15px ui-monospace, 'SF Mono', Menlo, monospace; border: 1px solid var(--line-2); }
.c-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.c-md { color: var(--violet); background: rgba(161, 147, 255, .12); }
.c-html { color: var(--mint); background: rgba(92, 242, 196, .1); }
.c-file, .c-url { color: var(--amber); background: rgba(255, 184, 107, .1); }
.c-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.c-text strong { font-size: 16px; }
.c-text span { font-size: 13px; color: var(--ink-3); }

.resume {
  width: 100%; margin-top: 10px; display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 18px; text-align: left;
  border: 1px solid rgba(161, 147, 255, .35); background: linear-gradient(90deg, rgba(161, 147, 255, .14), rgba(92, 242, 196, .06));
  transition: transform .4s var(--ease);
}
.resume:hover { transform: translateY(-2px); }
.r-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px var(--mint); }
.r-text { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.r-text span { font-size: 13px; color: var(--ink-2); flex: none; }
.r-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-text em { font-style: normal; font-size: 12.5px; color: var(--ink-3); margin-left: auto; flex: none; }
.samples { margin: 26px 0 0; font-size: 14px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.samples button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--ink-2); font-size: 13.5px; transition: color .3s, border-color .3s; }
.samples button:hover { color: var(--ink); border-color: rgba(255, 255, 255, .3); }

/* ---------- App ---------- */
.app { position: fixed; inset: 0; z-index: 3; display: flex; flex-direction: column; animation: appIn .5s var(--ease); background: rgba(6, 7, 11, .55); }
@keyframes appIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.top {
  position: relative; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 11, 18, .7); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.home { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; flex: none; }
.home:hover { background: rgba(255, 255, 255, .06); }
.doc-name {
  min-width: 0; flex: 0 1 260px; height: 36px; padding: 0 10px; border-radius: 10px; border: 1px solid transparent;
  background: none; font-weight: 600; font-size: 15px; text-overflow: ellipsis;
}
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--violet); background: rgba(255, 255, 255, .04); }
.seg { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); flex: none; }
.seg button { height: 30px; padding: 0 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); display: grid; place-items: center; transition: color .2s, background .2s; }
.seg button:hover { color: var(--ink); }
.seg .short { display: none; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #0b0c12; }
.seg svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.tbtn {
  height: 36px; padding: 0 12px; border-radius: 11px; display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); border: 1px solid var(--line); background: rgba(255, 255, 255, .03);
  transition: color .2s, background .2s;
}
.tbtn:hover { color: var(--ink); background: rgba(255, 255, 255, .07); }
.tbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tbtn-primary { background: var(--ink); color: #0b0c12; border-color: var(--ink); }
.tbtn-primary:hover { background: #fff; color: #0b0c12; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 230px; padding: 6px; border-radius: 14px;
  background: rgba(18, 20, 32, .97); border: 1px solid var(--line-2); box-shadow: 0 20px 60px -10px rgba(0, 0, 0, .7);
  display: flex; flex-direction: column; animation: appIn .25s var(--ease);
}
.menu[hidden] { display: none; }
.menu button { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; font-size: 14px; text-align: left; }
.menu button:hover { background: rgba(255, 255, 255, .07); }
.menu button[hidden] { display: none; }
.menu-share { min-width: 260px; }
.menu-share span { display: flex; flex-direction: column; gap: 2px; }
.menu-share strong { font-weight: 600; }
.menu-share small { font-size: 12.5px; color: var(--ink-3); }

.work { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--split) 10px 1fr; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-edit { background: rgba(8, 9, 15, .6); }
.tabs { display: none; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); }
[data-mode="html"] .tabs { display: flex; }
.tabs button { position: relative; padding: 8px 14px 10px; font: 600 13px ui-monospace, 'SF Mono', Menlo, monospace; color: var(--ink-3); border-radius: 9px 9px 0 0; }
.tabs button:hover { color: var(--ink-2); }
.tabs button[aria-selected="true"] { color: var(--ink); background: rgba(255, 255, 255, .04); }
.tabs button[aria-selected="true"]::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--mint); }
.tabs button.has::before { content: ''; position: absolute; top: 8px; right: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); }
.editor { flex: 1; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; }
.editor .cm-editor.cm-focused { outline: none; }

.divider { cursor: col-resize; position: relative; touch-action: none; background: rgba(8, 9, 15, .6); }
.divider::after { content: ''; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px; background: var(--line); transition: background .2s; }
.divider:hover::after, .is-resizing .divider::after { background: var(--violet); }
.is-resizing, .is-resizing * { user-select: none; cursor: col-resize !important; }
.is-resizing iframe { pointer-events: none; }

.view-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.seg-device button { padding: 0 10px; }
.view-actions { display: flex; gap: 4px; }
.ibtn { position: relative; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); transition: color .2s, background .2s; }
.ibtn:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }
.ibtn[aria-pressed="true"] { color: var(--ink); background: rgba(255, 255, 255, .08); }
.ibtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[data-mode="md"] .html-only, [data-mode="html"] .md-only { display: none; }
.badge { position: absolute; top: 2px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; font: 700 10px/16px system-ui; background: var(--ink-3); color: #0b0c12; }
.badge.is-error { background: var(--rose); }

.view-stage {
  flex: 1; min-height: 0; position: relative; display: flex; justify-content: center; overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .06) 1px, transparent 0) 0 0 / 18px 18px,
    rgba(4, 5, 9, .6);
}
.view-stage iframe { flex: none; width: 100%; height: 100%; border: 0; background: #0c0d14; transition: width .5s var(--ease), border-radius .5s var(--ease), margin .5s var(--ease); }
.view-stage.is-light iframe { background: #fff; }
[data-mode="html"] .view-stage iframe { background: #fff; }
.view-stage[data-device="tablet"] iframe { width: 768px; margin: 16px; height: calc(100% - 32px); border-radius: 18px; box-shadow: 0 0 0 1px var(--line-2), 0 30px 80px -20px rgba(0, 0, 0, .8); }
.view-stage[data-device="phone"] iframe { width: 390px; margin: 16px; height: calc(100% - 32px); border-radius: 28px; box-shadow: 0 0 0 1px var(--line-2), 0 0 0 7px #15161f, 0 30px 80px -20px rgba(0, 0, 0, .8); }
.view-stage::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 2px var(--violet); opacity: 0; border-radius: 2px; }
.view-stage.is-flash::after { animation: flash .6s var(--ease); }
@keyframes flash { 0% { opacity: .5; } 100% { opacity: 0; } }

.console { display: none; flex-direction: column; height: 34%; min-height: 120px; border-top: 1px solid var(--line); background: rgba(8, 9, 15, .92); }
.console-open[data-mode="html"] .console { display: flex; }
.console-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: 12.5px; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.console-head button { font-size: 12.5px; color: var(--ink-2); padding: 4px 8px; border-radius: 6px; }
.console-head button:hover { background: rgba(255, 255, 255, .06); }
.console-list { list-style: none; margin: 0; padding: 4px 0; overflow: auto; flex: 1; font: 12.5px/1.55 ui-monospace, 'SF Mono', Menlo, monospace; }
.console-list li { padding: 3px 12px; border-bottom: 1px solid rgba(255, 255, 255, .03); white-space: pre-wrap; word-break: break-word; }
.console-list .lv-warn { color: var(--amber); background: rgba(255, 184, 107, .05); }
.console-list .lv-error { color: var(--rose); background: rgba(255, 107, 139, .06); }
.console-list .lv-info { color: #8fd8ff; }
.console-list .empty { color: var(--ink-3); border: 0; }

.status {
  display: flex; gap: 16px; align-items: center; padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(10, 11, 18, .8); font-size: 12.5px; color: var(--ink-3);
}
.saved::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--ink-3); vertical-align: 1px; }
.saved.is-ok::before { background: var(--mint); }
.hint { margin-left: auto; }
.seg-pane { display: none; }

/* 크게 보기 */
.is-max .work { grid-template-columns: 0 0 1fr; }
.is-max .pane-edit, .is-max .divider { visibility: hidden; }

/* ---------- Drop / toast / dialog ---------- */
.drop { position: fixed; inset: 0; z-index: 80; display: none; place-items: center; background: rgba(6, 7, 11, .7); backdrop-filter: blur(6px); }
.is-dragging .drop { display: grid; }
.drop div { padding: 48px 64px; border-radius: 28px; border: 2px dashed var(--violet); display: flex; flex-direction: column; align-items: center; gap: 6px; background: rgba(161, 147, 255, .08); }
.drop strong { font-size: 22px; }
.drop span { color: var(--ink-2); font-family: ui-monospace, monospace; font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 85; translate: -50% 12px;
  max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; text-align: center;
  background: rgba(20, 22, 34, .95); border: 1px solid var(--line-2); box-shadow: 0 16px 40px -10px rgba(0, 0, 0, .7);
  opacity: 0; pointer-events: none; transition: opacity .3s, translate .4s var(--ease);
}
.toast.is-on { opacity: 1; translate: -50% 0; }
dialog {
  width: min(520px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line-2); border-radius: 24px;
  background: rgba(14, 16, 26, .96); color: var(--ink); box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .8);
}
dialog[open] { animation: appIn .35s var(--ease); }
dialog::backdrop { background: rgba(3, 4, 8, .6); backdrop-filter: blur(4px); }
.dlg { padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font-size: 21px; letter-spacing: -0.03em; }
.dlg p { margin: 0; color: var(--ink-2); font-size: 14.5px; }
.dlg input { height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04); font-size: 15px; }
.dlg input:focus { outline: none; border-color: var(--violet); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 20px; border-radius: 999px; font-weight: 650; font-size: 14.5px; }
.btn-primary { background: var(--ink); color: #0b0c12; }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { border: 1px solid var(--line-2); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .start-inner { padding-top: 40svh; }
  .choices { grid-template-columns: 1fr; }
  .top { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .doc-name { flex: 1 1 auto; font-size: 14px; }
  .tbtn span { display: none; }
  .tbtn { width: 36px; padding: 0; justify-content: center; }
  .seg-mode button { padding: 0 9px; font-size: 12.5px; }
  .seg-mode .long { display: none; }
  .seg-mode .short { display: inline; }
  .top-actions [data-open-url] { display: none; }
  .work { grid-template-columns: 1fr; }
  .divider { display: none; }
  [data-pane="edit"] .pane-view, [data-pane="view"] .pane-edit { display: none; }
  .hint { display: none; }
  .seg-pane {
    display: flex; position: fixed; z-index: 30; left: 50%; bottom: calc(40px + env(safe-area-inset-bottom)); translate: -50% 0;
    padding: 4px; border-radius: 999px; background: rgba(18, 20, 32, .92); border: 1px solid var(--line-2);
    backdrop-filter: blur(16px); box-shadow: 0 16px 40px -10px rgba(0, 0, 0, .7);
  }
  .seg-pane button { height: 38px; padding: 0 20px; border-radius: 999px; font-size: 14px; }
  .toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
  .view-stage[data-device="tablet"] iframe { width: 100%; margin: 0; height: 100%; border-radius: 0; box-shadow: none; }
  .seg-device [data-device="tablet"] { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
