/* 웹 편집기. 배치는 맥 앱(넓은 화면)과 휴대폰 앱(좁은 화면)을 따르고, 색은 홈페이지(style.css) 토큰을 씁니다. */
:root { --desk: #d6d5d0; --sheet-line: #c4c3bd; --ctl: #ffffff; --ctl-line: #d4d3ce; --on: color-mix(in srgb, var(--accent) 16%, transparent); --ui: 13px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --desk: #3a3a3f; --sheet-line: #2a2a2f; --ctl: #1d1d21; --ctl-line: #2f2f35; } }
:root[data-theme="dark"] { --desk: #3a3a3f; --sheet-line: #2a2a2f; --ctl: #1d1d21; --ctl-line: #2f2f35; }

html, body.editor { height: 100%; overflow: hidden; }
body.editor { display: flex; flex-direction: column; height: 100dvh; font-size: var(--ui); accent-color: var(--accent); }
body.editor button, body.editor input, body.editor select { font: inherit; color: inherit; }
i[data-icon] { display: inline-flex; align-items: center; justify-content: center; flex: none; }
i[data-icon] svg { width: 16px; height: 16px; }
[hidden] { display: none !important; }

/* ── 탭 줄 ── */
#chrome { flex: none; background: var(--bg); border-bottom: 1px solid var(--line); }
#tabs { display: flex; align-items: center; height: 36px; padding: 0 8px 0 6px; border-bottom: 1px solid var(--line); }
#tabs .brand { display: flex; align-items: center; gap: 7px; flex: none; padding: 0 12px 0 4px; font-weight: 600; color: var(--ink); white-space: nowrap; }
#tabs .brand img, #mtop .brand img { border-radius: 5px; display: block; }
#tabs .list { display: flex; align-items: stretch; height: 100%; overflow-x: auto; scrollbar-width: none; }
#tabs .list::-webkit-scrollbar { display: none; }
.tab { position: relative; display: flex; align-items: center; height: 100%; flex: none; }
.tab > button { height: 28px; border: 0; background: none; cursor: pointer; color: var(--sub); white-space: nowrap; }
.tab .name { padding: 0 6px 0 10px; }
.tab .drop { width: 20px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--hint); }
.tab .drop svg { width: 13px; height: 13px; }
.tab:hover > button { color: var(--ink); }
.tab.on { background: var(--cell); }
.tab.on > button { color: var(--ink); }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent); }
.tab.context .name { color: var(--accent); }
#tabs .spacer { flex: 1; }
#tabs .theme, #ribbon-toggle { width: 34px; height: 28px; border: 0; background: none; color: var(--sub); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
#ribbon-toggle { background: var(--cell); width: 44px; margin-left: 4px; }
#tabs .theme:hover, #ribbon-toggle:hover { color: var(--ink); }

/* ── 리본 ── */
#ribbon { position: relative; display: flex; align-items: stretch; height: 76px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
body.ribbon-closed #ribbon { display: none; }
#ribbon .items { flex: 1; min-width: 0; display: flex; align-items: stretch; overflow: hidden; }
.rgroup { display: flex; align-items: stretch; flex: none; padding: 0 4px; }
.rgroup + .rgroup { border-left: 1px solid var(--line); margin-left: 4px; padding-left: 8px; }
.ritem { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 58px; padding: 2px 6px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--ink); white-space: nowrap; flex: none; }
.ritem i svg { width: 22px; height: 22px; stroke-width: 1.6; }
.ritem span { font-size: 12px; color: var(--sub); }
.ritem:hover:not(:disabled) { background: var(--cell); border-color: var(--line); }
.ritem.on { background: var(--on); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.ritem:disabled { cursor: default; opacity: .38; }
.rgroup.overflow { display: none; }
.rgroup .fold { display: none; align-self: center; height: 30px; padding: 0 12px; border: 0; background: var(--cell); color: var(--ink); cursor: pointer; white-space: nowrap; gap: 4px; align-items: center; }
.rgroup .fold svg { width: 12px; height: 12px; }
.rgroup.folded .ritem { display: none; }
.rgroup.folded .fold { display: inline-flex; }
#ribbon .more, #toolbar .more { align-self: center; width: 30px; height: 30px; border: 0; background: var(--cell); color: var(--sub); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; margin-left: 6px; }

/* ── 서식 도구 ── */
#toolbar { display: flex; align-items: center; height: 36px; padding: 0 6px; border-bottom: 1px solid var(--line); }
#toolbar .items { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow: hidden; }
#toolbar .items > .off { display: none; }
#toolbar .more { align-self: center; height: 26px; }
body.toolbox-hidden #toolbar { display: none; }
.tb { width: 28px; height: 26px; flex: none; border: 1px solid transparent; background: none; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.tb.glyph { background: var(--cell); font-weight: 500; }
.tb.glyph { width: 27px; }
.tb.align { width: 34px; background: var(--cell); }
.tb:hover:not(:disabled) { border-color: var(--line); }
.tb.on { background: var(--accent); color: #fff; }
.tb:disabled { opacity: .38; cursor: default; }
.field { display: flex; align-items: center; width: var(--w); flex: none; }
.field select, .field input { height: 26px; width: 100%; padding: 0 6px; border: 1px solid var(--ctl-line); background: var(--ctl); color: var(--ink); border-radius: 0; font-size: 12.5px; min-width: 0; }
.field :disabled { opacity: .5; }

/* ── 문서 탭과 눈금자 ── */
#doctabs { display: flex; align-items: center; gap: 2px; height: 32px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
body.doctabs-hidden #doctabs { display: none; }
.doctab { display: flex; align-items: center; height: 26px; flex: none; }
.doctab .name { height: 26px; max-width: 220px; min-width: 112px; padding: 0 14px; border: 0; background: var(--cell); color: var(--ink); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doctab.on .name { background: var(--accent); color: #fff; }
.doctab .x { width: 26px; height: 26px; border: 0; background: var(--cell); color: var(--sub); cursor: pointer; margin-left: 2px; }
#ruler { position: relative; height: 30px; overflow: hidden; }
#ruler canvas { position: absolute; left: 0; top: 0; width: 100%; height: 30px; display: block; }
body.ruler-hidden #ruler { display: none; }

/* ── 쪽 ── */
#stage { flex: 1; min-height: 0; overflow: auto; background: var(--desk); position: relative; outline: none; overscroll-behavior: contain; }
#pages { position: relative; display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 20px 24px 48px; width: max-content; min-width: 100%; }
.sheet { position: relative; flex: none; background: #fff; box-shadow: 0 0 0 1px var(--sheet-line), 0 2px 8px rgba(0,0,0,.08); cursor: text; touch-action: pan-x pan-y; }
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ime { position: absolute; left: 0; top: 0; width: 2px; height: 20px; padding: 0; border: 0; margin: 0; resize: none; overflow: hidden; opacity: 0; color: transparent; background: transparent; caret-color: transparent; font-size: 16px; line-height: 1; white-space: pre; z-index: 2; pointer-events: none; }
/* 엔진·글꼴을 받는 동안: 미리 그린 빈 쪽과 위쪽의 가는 진행 막대만 보입니다. */
.sheet.ghost { width: 595px; height: 842px; cursor: default; }
body.mobile .sheet.ghost { width: calc(100vw - 28px); height: auto; aspect-ratio: 210 / 297; }
body.ready .ghost { display: none; }
body:not(.ready) :is(#ribbon .items, #toolbar .items, #mbar .quick, #mtop .mb[data-wait]) { opacity: .45; }
#loading { position: absolute; left: 0; right: 0; top: 0; height: 2px; overflow: hidden; pointer-events: none; }
#loading span { position: absolute; top: 0; bottom: 0; left: -30%; width: 30%; background: var(--accent); animation: loading 1.1s ease-in-out infinite; }
@keyframes loading { to { left: 100%; } }
@media (prefers-reduced-motion: reduce) { #loading span { left: 0; animation: none; opacity: .6; } }
body.ready #loading { display: none; }
body.dragging #stage { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── 상태 표시줄 ── */
#status { flex: none; display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px 0 12px; border-top: 1px solid var(--line); background: var(--bg); color: var(--sub); white-space: nowrap; overflow: hidden; }
body.status-hidden #status { display: none; }
#status.narrow .fit { display: none; }
#status-text { white-space: pre; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
#status .spacer { flex: 1; }
.sb { height: 24px; padding: 0 12px; border: 0; background: var(--cell); color: var(--ink); cursor: pointer; flex: none; }
.sb.step { width: 28px; padding: 0; }
#zoom-slider { width: 100px; accent-color: var(--accent); flex: none; }
#zoom-field { width: 60px; height: 24px; border: 0; background: var(--cell); text-align: center; flex: none; }

/* ── 백스테이지(파일 탭) ── */
#backstage { position: fixed; left: 0; right: 0; bottom: 0; top: 37px; z-index: 20; display: flex; background: var(--bg); }
#backstage .side { width: 230px; flex: none; display: flex; flex-direction: column; gap: 2px; padding: 14px 8px; border-right: 1px solid var(--line); overflow-y: auto; }
#backstage .side button { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 12px; border: 0; background: none; color: var(--ink); cursor: pointer; text-align: left; font-size: 14px; }
#backstage .side button i svg { width: 18px; height: 18px; color: var(--sub); }
#backstage .side button:hover { background: var(--cell); }
#backstage .side button.on { background: var(--on); }
#backstage .side button:disabled { opacity: .4; cursor: default; }
#backstage .side hr { border: 0; height: 1px; background: none; margin: 8px 0; }
#backstage .pane { flex: 1; min-width: 0; overflow-y: auto; padding: 28px 32px 48px; }
#backstage .side { padding-bottom: 52px; }
#backstage .foot { position: absolute; left: 0; bottom: 0; width: 230px; padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#backstage .foot .dl-links { display: none; }
#backstage .foot a { font-size: 12px; color: var(--hint); text-decoration: none; }
#backstage .foot a:hover { color: var(--ink); }
#backstage h1 { font-size: 26px; letter-spacing: -.02em; }
#backstage h3 { margin: 36px 0 16px; font-size: 16px; font-weight: 700; }
.search { display: flex; align-items: center; gap: 8px; width: min(340px, 100%); height: 34px; margin-top: 18px; padding: 0 14px; border: 1px solid var(--line); border-radius: 17px; background: var(--ctl); color: var(--sub); }
.search svg { width: 16px; height: 16px; flex: none; }
.search input { flex: 1; border: 0; background: none; outline: none; min-width: 0; font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, 136px); gap: 28px 40px; margin-top: 28px; }
.card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer; color: var(--ink); }
.card .paper { width: 100%; aspect-ratio: 210 / 297; background: #fff; border: 1px solid var(--line); object-fit: cover; object-position: top; display: block; margin-bottom: 8px; }
.card:hover .paper { border-color: var(--accent); }
.card b { font-size: 14px; font-weight: 600; }
.card small { font-size: 12.5px; color: var(--sub); }
.pane .row { display: flex; gap: 10px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.pane .row input[type=text] { height: 34px; width: min(360px, 100%); padding: 0 10px; border: 1px solid var(--line); background: var(--ctl); font-size: 14px; }
.pane .info { margin-top: 18px; border-collapse: collapse; font-size: 14px; }
.pane .info th, .pane .info td { text-align: left; padding: 8px 18px 8px 0; border-bottom: 1px solid var(--line); font-weight: 400; }
.pane .info th { color: var(--sub); }
.pane p.hint { margin-top: 14px; color: var(--sub); font-size: 13.5px; line-height: 1.6; word-break: keep-all; }
.btn-main, .btn-plain { height: 32px; padding: 0 16px; border: 1px solid var(--ink); cursor: pointer; font-size: 13.5px; }
.btn-main { background: var(--ink); color: var(--bg) !important; }
.btn-plain { background: none; }

/* ── 띄우는 것들 ── */
.popup { position: fixed; z-index: 40; min-width: 180px; max-height: min(70vh, 560px); overflow-y: auto; display: flex; flex-direction: column; padding: 4px; background: var(--bg); border: 1px solid var(--line); box-shadow: 0 10px 28px rgba(0,0,0,.16); }
.popup button { display: flex; align-items: center; gap: 10px; min-height: 30px; padding: 4px 12px; border: 0; background: none; text-align: left; cursor: pointer; color: var(--ink); white-space: nowrap; }
.popup button:hover:not(:disabled) { background: var(--cell); }
.popup button:disabled { opacity: .4; cursor: default; }
.popup button .check { width: 14px; color: var(--accent); }
.popup hr { border: 0; height: 1px; background: var(--line); margin: 4px 0; }
.popup .sub { padding: 6px 12px 2px; color: var(--hint); font-size: 11.5px; }
#apps { min-width: 170px; }
#apps a { display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 4px 12px; color: var(--ink); text-decoration: none; white-space: nowrap; }
#apps a:hover { background: var(--cell); }
#apps svg { width: 18px; height: 18px; flex: none; }
#form { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); margin: auto; padding: 0; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
#form::backdrop { background: rgba(0,0,0,.3); }
#form form { display: flex; flex-direction: column; max-height: calc(100dvh - 50px); }
#form .title { padding: 16px 20px 12px; font-size: 16px; font-weight: 700; border-bottom: 1px solid var(--line); }
#form .body { padding: 6px 20px 12px; overflow-y: auto; }
#form fieldset { border: 0; padding: 0; margin: 12px 0 0; }
#form legend { padding: 0; margin-bottom: 6px; font-size: 12px; color: var(--hint); font-weight: 600; }
#form .f { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 10px; min-height: 32px; }
#form .f > span { color: var(--sub); font-size: 13px; }
#form .f input:not([type=checkbox]), #form .f select { height: 28px; padding: 0 8px; border: 1px solid var(--ctl-line); background: var(--ctl); min-width: 0; }
#form .f.off { opacity: .5; }
#form .error { margin: 0 20px 8px; color: #c0392b; font-size: 13px; }
#form .actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
#findbar { position: fixed; z-index: 30; right: 16px; top: 210px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: calc(100vw - 32px); padding: 8px; background: var(--bg); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.14); }
#findbar input:not([type=checkbox]) { height: 28px; width: 150px; padding: 0 8px; border: 1px solid var(--ctl-line); background: var(--ctl); }
#findbar button { height: 28px; padding: 0 10px; border: 0; background: var(--cell); cursor: pointer; display: inline-flex; align-items: center; }
#toast { position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); z-index: 50; max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; background: var(--ink); color: var(--bg); font-size: 14px; line-height: 1.5; word-break: keep-all; }
#print { display: none; }

/* ── 휴대폰 배치 ── */
#mtop, #mbar, #mpanel { display: none; }
body.mobile #chrome, body.mobile #status { display: none; }
body.mobile #mtop { display: flex; flex: none; align-items: center; gap: 2px; height: 50px; padding: 0 4px; background: var(--bg); border-bottom: 1px solid var(--line); }
body.mobile #mtop .brand { display: flex; align-items: center; gap: 6px; flex: none; padding: 0 4px 0 2px; font-size: 15px; font-weight: 600; white-space: nowrap; }
body.mobile #mtop .mb { width: 38px; }
body.mobile #mtop .title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 4px; }
body.mobile #mtop .brand + .title { margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--line); }
body.mobile #mtop .title b { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.mobile #mtop .title span { font-size: 11px; color: var(--sub); }
.mb { width: 42px; height: 42px; flex: none; border: 0; background: none; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.mb i svg { width: 21px; height: 21px; }
.mb:disabled { opacity: .35; }
.mb.on { color: var(--accent); }
body.mobile #mbar { display: flex; flex: none; align-items: center; height: 48px; background: var(--bg); border-top: 1px solid var(--line); }
body.mobile #mbar .quick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
body.mobile #mbar .quick::-webkit-scrollbar { display: none; }
body.mobile #mbar .quick .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
body.mobile #mbar > .mb { border-left: 1px solid var(--line); }
body.mobile #mpanel:not([hidden]) { display: flex; flex-direction: column; flex: none; height: min(46dvh, 360px); background: var(--bg); border-top: 1px solid var(--line); }
#mpanel .chips { display: flex; gap: 4px; padding: 6px 8px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; flex: none; }
#mpanel .chips button { flex: none; height: 32px; padding: 0 13px; border: 0; border-radius: 16px; background: none; color: var(--ink); font-size: 15px; cursor: pointer; }
#mpanel .chips button.on { background: var(--on); color: var(--accent); font-weight: 600; }
#mpanel .list { flex: 1; overflow-y: auto; }
#mpanel .tool { display: flex; align-items: center; gap: 16px; width: 100%; height: 46px; padding: 0 18px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font-size: 16px; cursor: pointer; text-align: left; }
#mpanel .tool > svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
#mpanel .tool span { flex: 1; }
#mpanel .tool:disabled { opacity: .4; }
#mpanel .tool .mark { color: var(--accent); }
body.mobile #pages { padding: 12px 12px 32px; gap: 12px; }
body.mobile #backstage { top: 0; flex-direction: column; }
body.mobile #backstage .side { width: auto; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
body.mobile #backstage .side button { flex: none; height: 36px; }
body.mobile #backstage .side hr { display: none; }
body.mobile #backstage .pane { padding: 20px 16px 40px; }
body.mobile #backstage .side { padding-bottom: 8px; }
body.mobile #backstage .foot { position: static; width: auto; flex: none; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
body.mobile #backstage .foot .dl-links { display: flex; }
body.mobile .cards { grid-template-columns: repeat(2, 1fr); gap: 18px 14px; }
body.mobile #findbar { top: 56px; left: 8px; right: 8px; }
body.mobile #findbar input:not([type=checkbox]) { flex: 1 1 40%; width: auto; }
body.mobile #form { width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 80dvh; }


@media print {
  @page { margin: 0; }
  html, body.editor { height: auto; overflow: visible; background: #fff; }
  body.editor > *:not(#print) { display: none !important; }
  #print { display: block; }
  #print img { display: block; break-after: page; page-break-after: always; }
  #print img:last-child { break-after: auto; page-break-after: auto; }
}

/* 플랫폼별 받기(탭 줄 오른쪽, 휴대폰은 문서 화면 아래) */
.dl-links { display: flex; align-items: center; gap: 2px; margin-right: 6px; flex: none; }
.dl-links .dl-link { height: 26px; padding: 0 8px; display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 12px; font-weight: 500; }
.dl-links .dl-link:hover { background: var(--cell); }
.dl-links .dl-link svg { width: 15px; height: 15px; flex: none; }
body.mobile #backstage .foot .dl-links .store { height: 34px; padding: 0 10px; border: 1px solid var(--line); font-size: 13px; }
/* 처음 들어왔을 때 알림 */
#welcome { margin: auto; width: min(420px, calc(100% - 32px)); padding: 28px 24px 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--ink); text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
#welcome::backdrop { background: rgba(0,0,0,.45); }
#welcome img { border-radius: 13px; margin: 0 auto; display: block; }
#welcome h2 { margin-top: 14px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
#welcome p { margin-top: 6px; font-size: 14px; color: var(--sub); line-height: 1.5; word-break: keep-all; }
#welcome .w-apps { margin-top: 18px; display: grid; gap: 8px; text-align: left; }
#welcome .w-app { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none; }
#welcome .w-app:hover { background: var(--cell); }
#welcome .w-app svg { width: 24px; height: 24px; flex: none; }
#welcome .w-app span { display: flex; flex-direction: column; font-size: 15px; font-weight: 600; line-height: 1.25; }
#welcome .w-app small { font-size: 12px; font-weight: 400; color: var(--sub); }
#welcome .w-close { margin-top: 14px; width: 100%; height: 40px; border: 0; border-radius: 10px; background: var(--ink); color: var(--bg); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
@media (max-width: 1100px) { #tabs .dl-links .dl-link span { display: none; } #tabs .dl-links .dl-link { padding: 0 6px; } }
#welcome .w-close:focus:not(:focus-visible) { outline: none; }
#welcome:focus, #welcome:focus-visible { outline: none; }
