:root {
  color-scheme: light;
  --foreground: #172235;
  --secondary: #546175;
  --primary: #2367e5;
  --primary-hover: #184baf;
  --primary-text: #fff;
  --brand: #163559;
  --page: #f5f7fb;
  --surface: #fff;
  --inset: #eaf2ff;
  --inset-hover: #dde9fb;
  --line: #dee6f0;
  --input-line: #889bb7;
  --drop-line: #729bd8;
  --focus: #2367e5;
  --danger: #8b281d;
  --danger-bg: #fff0ee;
  --radius: 14px;
  --frame-radius: 20px;
  --frame-shadow: 0 14px 35px #1934560d;
  --font: "Pretendard Variable", Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --desk-height: max(565px, calc(100dvh - 112px));
}
:root[data-theme="gisan"] {
  --foreground: #4a3a2c;
  --secondary: #6b5848;
  --primary: #2f6b45;
  --primary-hover: #245537;
  --page: #fff8ec;
  --surface: #fffdf8;
  --inset: #f8eedc;
  --inset-hover: #f5e4c7;
  --line: #e3d6c6;
  --input-line: #9c8b7a;
  --drop-line: #a28c71;
  --focus: #8a5122;
  --danger: #a2412f;
  --danger-bg: #fbe6e1;
  --frame-radius: 14px;
  --frame-shadow: 0 1px 0 #5b46361a, 0 8px 20px -14px #4a3a2c73;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--foreground); background: var(--page); font: 16px/1.5 var(--font); }
h1, h2, h3, p { margin: 0; }
button { font: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.app-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px 20px;
  flex-wrap: wrap; padding: 12px clamp(16px, 3vw, 38px); background: var(--surface); border-bottom: 1px solid var(--line);
}
.identity { display: flex; gap: 11px; min-width: 0; align-items: center; }
.brand {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px;
  background: var(--brand); color: white; font-size: 19px; font-weight: 780;
}
[data-theme="gisan"] .brand {
  font-size: 0;
  background: var(--inset) center / cover url('./gisan-icon.png');
}
h1 { font-size: 20px; letter-spacing: -.035em; line-height: 1.3; }
#document-status { color: var(--secondary); font-size: 13px; overflow-wrap: anywhere; }
.file-actions { display: flex; flex-wrap: wrap; gap: 7px; }
body[data-document="start"] .file-actions { display: none; }

.file-actions button, .start-page button, .selection-edit-panel button {
  min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--foreground); font-size: 14px; font-weight: 700; cursor: pointer;
}
:is(.file-actions, .start-page, .selection-edit-panel) button:hover:not(:disabled) {
  background: var(--inset);
}
.file-actions button[aria-expanded="true"] { background: var(--inset); color: var(--primary-hover); }
:is(.file-actions, .start-page) .primary, .selection-edit-panel .selection-edit-primary {
  border-color: var(--primary); background: var(--primary); color: var(--primary-text);
}
:is(.file-actions, .start-page) .primary:hover:not(:disabled),
.selection-edit-panel .selection-edit-primary:hover:not(:disabled) {
  border-color: var(--primary-hover); background: var(--primary-hover);
}
:is(.file-actions, .start-page, .selection-edit-panel) button:disabled { opacity: .54; cursor: default; }

main { position: relative; margin: 18px clamp(10px, 2.2vw, 32px); }
.start-page {
  display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: center;
  gap: 22px clamp(28px, 5vw, 74px); max-width: 1130px;
  margin: clamp(28px, 8vh, 86px) auto;
  padding: clamp(26px, 5vw, 68px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--frame-radius);
  box-shadow: var(--frame-shadow);
}
.start-copy h2 {
  font-size: clamp(30px, 3.85vw, 50px); line-height: 1.12;
  letter-spacing: -.055em; word-break: keep-all;
}
.start-copy p { margin-top: 17px; color: var(--secondary); word-break: keep-all; }
.start-copy .secondary { margin-top: 22px; }
.file-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 303px; gap: 6px; padding: 24px 14px; text-align: center;
  border: 1.5px dashed var(--drop-line); border-radius: var(--frame-radius);
  background: var(--inset);
}
.file-drop.over { background: var(--inset-hover); border-color: var(--primary); }
.file-mark {
  display: grid; place-items: center; width: 54px; height: 62px; margin: 0 0 9px;
  border: 1px solid var(--line); border-radius: 9px 14px 9px 9px;
  background: var(--surface); color: var(--primary); font-size: 23px; font-weight: 750;
}
.file-drop strong { font-size: 17px; }
.file-drop p, .local-note { color: var(--secondary); font-size: 13px; }
.file-drop .primary { margin-top: 12px; }
.local-note { grid-column: 1 / -1; }
.local-editor-link { color: var(--primary-hover); text-underline-offset: .2em; }
.local-note .local-editor-link { margin-inline-start: .4em; }
.file-actions .local-editor-link { display: inline-flex; align-items: center; padding-inline: 8px; font-size: 14px; }
.error { margin: 0 0 12px; padding: 10px 15px; background: var(--danger-bg); color: var(--danger); border-radius: 8px; overflow-wrap: anywhere; }

body:not([data-document="start"]) .start-page { display: none; }
body[data-document="start"] .editor-workspace { position: absolute; inset: 0 0 auto; visibility: hidden; pointer-events: none; }
.editor-workspace {
  display: flex; align-items: stretch; overflow: hidden; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--frame-radius); box-shadow: var(--frame-shadow);
}
#studio { flex: 1; min-width: 0; height: var(--desk-height); background: white; }
#studio iframe { display: block; width: 100%; height: 100%; border: 0; }

.selection-edit-panel {
  width: clamp(310px, 29vw, 394px); height: var(--desk-height); padding: 17px;
  border-left: 1px solid var(--line); overflow: auto; overflow-wrap: anywhere;
  background: var(--surface);
}
.selection-edit-panel header { display: flex; align-items: center; gap: 9px; }
.selection-edit-panel header > div { flex: 1; min-width: 0; }
.selection-edit-panel h2 { font-size: 19px; line-height: 1.25; letter-spacing: -.025em; }
.selection-edit-panel header p { margin-top: 3px; color: var(--secondary); font-size: 13px; }
.selection-edit-panel :is(#selection-edit-close, #journal-draft-close) {
  flex: none; min-width: 44px; background: transparent; border: 0; padding-inline: 7px;
}
.selection-edit-panel .selection-edit-quiet { background: var(--surface); }
.selection-edit-status { margin: 10px 0 7px; color: var(--secondary); font-size: 14px; }
.selection-edit-error { margin: 7px 0; color: var(--danger); font-size: 14px; }
.selection-edit-review { display: grid; gap: 6px; margin: 13px 0 10px; }
.selection-edit-review h3, .selection-edit-review label { font-size: 14px; font-weight: 700; }
.selection-edit-original {
  margin: 3px 0 4px; padding: 8px 10px; background: var(--inset);
  border-radius: 8px; white-space: pre-wrap;
}
.selection-edit-review textarea {
  width: 100%; resize: vertical; min-height: 76px; padding: 8px 9px; font: inherit; font-weight: 400;
  border: 1px solid var(--input-line); border-radius: 8px; color: var(--foreground); background: var(--surface);
}

.journal-draft-panel { display: flex; flex-direction: column; gap: 10px; padding: 0; overflow: hidden; }
.journal-draft-header, .journal-draft-panel > :is(.selection-edit-status, .selection-edit-error) { margin-inline: 16px; }
.journal-draft-header { margin-top: 15px; }
.assistant-mark {
  display: grid; place-items: center; flex: none; width: 38px; height: 38px;
  border-radius: 11px; background: var(--inset); color: var(--primary); font-size: 21px;
}
.journal-draft-panel > :is(.selection-edit-status, .selection-edit-error) { margin-block: 0; }
.journal-draft-scroll { flex: 1; min-height: 0; overflow: auto; padding: 2px 16px 12px; scroll-padding: 12px 0; }
.journal-draft-review, .journal-draft-fields { display: grid; gap: 10px; margin: 0; }
.journal-draft-item { display: grid; gap: 6px; padding: 11px; border: 1px solid var(--line); border-radius: var(--radius); }
.journal-compose summary {
  min-height: 44px; padding: 10px 11px; border-radius: 8px; cursor: pointer;
  background: var(--inset); color: var(--foreground); font-size: 14px; font-weight: 700;
}
.journal-compose summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.journal-memo { padding: 9px 0 4px; border: 0; }
.journal-memo .selection-edit-status { margin-block: 2px 0; font-size: 12px; }
.journal-draft-item .journal-draft-pick {
  display: flex; align-items: center; gap: 8px; min-height: 34px; color: var(--foreground);
}
.journal-draft-pick input { flex: none; margin: 0; width: 18px; height: 18px; accent-color: var(--primary); }
.journal-draft-location { color: var(--secondary); font-size: 12px; }
.journal-draft-item-label { display: grid; gap: 4px; }
.journal-draft-item h3 { color: var(--secondary); font-size: 13px; }
.journal-draft-item .selection-edit-original { margin: 0; max-height: 7em; overflow: auto; font-size: 14px; }
.journal-draft-item textarea { min-height: 66px; }
.journal-draft-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.journal-draft-phase {
  margin-left: auto; flex: none; padding: 2px 7px; color: var(--secondary);
  background: var(--inset); border-radius: 999px; font-size: 12px; font-weight: 650;
}
.journal-draft-footer {
  display: grid; gap: 6px; flex: none; padding: 10px 16px 13px;
  border-top: 1px solid var(--line); background: var(--surface);
}
.journal-draft-footer .journal-draft-actions { justify-content: end; }
.journal-draft-footer .selection-edit-quiet { border-color: transparent; }

.editor-chat-panel {
  display: flex; flex-direction: column; gap: 10px; overflow: hidden; padding: 14px 0 0;
}
.editor-chat-panel #editor-chat-close { flex: none; padding-inline: 9px; border: 0; }
.editor-chat-header, .editor-chat-provider, .editor-chat-panel > .selection-edit-status { margin: 0 15px; }
.editor-chat-provider {
  display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; align-items: center;
  padding: 8px 10px; border-radius: 9px; background: var(--inset); font-size: 13px;
}
.editor-chat-provider select {
  min-height: 30px; max-width: 100%; padding: 1px 6px; color: var(--foreground); background: var(--surface);
  border: 1px solid var(--input-line); border-radius: 7px; font: inherit;
}
.editor-chat-provider p { grid-column: 1 / -1; color: var(--secondary); font-size: 12px; }
.editor-chat-log { flex: 1; min-height: 0; overflow: auto; display: grid; align-content: start; gap: 10px; padding: 4px 15px; }
.editor-chat-bubble {
  justify-self: start; min-width: 0; max-width: 100%; padding: 8px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px;
}
.editor-chat-bubble[data-role="user"] { justify-self: end; background: var(--inset); }
.editor-chat-speaker { margin-bottom: 3px; color: var(--secondary); font-size: 12px; font-weight: 700; }
.editor-chat-text { white-space: pre-wrap; }
.editor-chat-bubble button { margin-top: 8px; min-height: 36px; }
.editor-chat-table-wrap { max-width: 100%; overflow-x: auto; margin-top: 7px; }
.editor-chat-table { border-collapse: collapse; font-size: 13px; }
.editor-chat-table :is(th, td) { min-width: 45px; border: 1px solid var(--line); padding: 4px 7px; text-align: left; }
.editor-chat-table th { background: var(--inset); }
.editor-chat-field-list { display: grid; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.editor-chat-field { padding: 7px 9px; background: var(--inset); border-radius: 8px; }
.editor-chat-field strong { font-size: 12px; }
.editor-chat-panel > .selection-edit-status:empty { display: none; }
.editor-chat-form {
  display: grid; gap: 5px; flex: none; padding: 9px 15px 12px; border-top: 1px solid var(--line);
}
.editor-chat-form label { font-size: 13px; font-weight: 700; }
.editor-chat-form textarea {
  width: 100%; min-height: 56px; max-height: 145px; padding: 7px 8px; resize: vertical;
  color: var(--foreground); background: var(--surface); border: 1px solid var(--input-line);
  border-radius: 8px; font: 14px/1.45 var(--font);
}
.editor-chat-actions { display: flex; justify-content: end; gap: 7px; }

@media (max-width: 800px) {
  .editor-workspace { flex-direction: column; }
  #studio { width: 100%; flex: none; }
  .selection-edit-panel { order: -1; width: 100%; height: auto; border-left: 0; border-bottom: 1px solid var(--line); }
  .journal-draft-panel, .editor-chat-panel { height: min(560px, 72dvh); }
}
@media (max-width: 625px) {
  :root { --desk-height: min(640px, 83dvh); }
  .app-header { padding: 10px 12px; }
  .file-actions { gap: 5px; }
  .file-actions button { padding-inline: 8px; }
  .start-page { grid-template-columns: minmax(0, 1fr); gap: 18px; margin-block: 20px; }
  .start-copy p { margin-top: 10px; }
  .start-copy .secondary { margin-top: 13px; }
  .desktop-break { display: none; }
  .file-drop { min-height: 220px; padding-block: 14px; }
}
