:root {
  --ink: #14212b; --muted: #5d6b77; --line: #d9e0e6; --bg: #f6f8fa; --card: #fff;
  --brand: #123b5c; --brand2: #1f6f8b; --accent: #e69f00; --ok: #0f7a4f; --warn: #a15c00; --bad: #b3261e;
  --radius: 10px;
  font-family: Pretendard, "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body { line-height: 1.55; font-size: 15px; }
button, select, input { font: inherit; }
code { background: #eef2f5; padding: 0 4px; border-radius: 4px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* 상단 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: var(--brand); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand em { font-style: normal; font-size: 11px; background: var(--accent); color: #111; border-radius: 4px; padding: 0 5px; }
.engine { flex: 1 1 200px; display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; }
.engine span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ebar { flex: 0 0 90px; height: 6px; background: rgba(255,255,255,.25); border-radius: 3px; overflow: hidden; }
.ebar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.engine.ready .ebar { display: none; }
.top .ghost { color: #fff; border-color: rgba(255,255,255,.5); }

button { cursor: pointer; border-radius: 8px; padding: 7px 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
button.primary { background: var(--brand2); color: #fff; border-color: var(--brand2); font-weight: 600; }
button.secondary { background: #e8f1f5; border-color: #bcd3de; color: var(--brand); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #f0c060; outline-offset: 1px; }

.settings { display: grid; gap: 10px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.settings label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.switch { align-items: flex-start !important; }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }

/* 첫 화면 */
.home h1 { font-size: clamp(22px, 4.2vw, 34px); line-height: 1.3; margin: 18px 0 12px; color: var(--brand); word-break: keep-all; }
.privacy { display: flex; gap: 10px; align-items: flex-start; background: #e9f6ef; border: 1px solid #b9e0c9; color: #0d4f33;
  padding: 12px 14px; border-radius: var(--radius); }
.privacy svg { flex: 0 0 auto; margin-top: 2px; }
.drop { margin: 18px 0 12px; padding: 28px 16px; border: 2px dashed #9fb5c4; border-radius: 14px; text-align: center; background: #fff; }
.drop.over { background: #eef7fb; border-color: var(--brand2); }
.drop p { margin: 6px 0; }
.drop small { color: var(--muted); display: block; margin-top: 8px; word-break: keep-all; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.examples small { flex-basis: 100%; color: var(--muted); }
.features { margin: 22px 0; padding-left: 18px; display: grid; gap: 6px; word-break: keep-all; }

/* 작업 영역 */
.filebar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.filebar b { word-break: break-all; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; scrollbar-width: thin; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; white-space: nowrap; padding: 8px 12px; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--brand2); font-weight: 700; color: var(--brand); }

.analysis { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; }
.menu { display: grid; gap: 10px; align-content: start; }
.menu h4 { margin: 6px 0 2px; font-size: 12px; color: var(--muted); letter-spacing: .05em; }
.menu button { text-align: left; width: 100%; }
.menu button[aria-pressed="true"] { background: var(--brand2); color: #fff; border-color: var(--brand2); }
.form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.form h3 { margin: 0 0 4px; }
.form .help { color: var(--muted); margin: 0 0 12px; font-size: 14px; word-break: keep-all; }
.field { margin-bottom: 12px; }
.field > label, .field > .lab { display: block; font-weight: 600; margin-bottom: 4px; }
.field select, .field input[type=text], .field input[type=number] { width: 100%; max-width: 420px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 12px; max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.checks label { display: inline-flex; gap: 4px; align-items: center; font-weight: 400; white-space: nowrap; }
.checks .tag { font-size: 11px; color: var(--muted); }
.field .row { display: flex; gap: 6px; flex-wrap: wrap; }
.field .row select { width: auto; max-width: 100%; }
.posthoc-note { font-size: 13px; color: var(--warn); }

.results-head { display: flex; justify-content: space-between; align-items: center; margin-top: 22px; flex-wrap: wrap; gap: 8px; }
.results-head h2 { margin: 0; }
.result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; min-width: 0; }
.result > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.result > header h3 { margin: 0 0 6px; }
.result .when { color: var(--muted); font-size: 13px; }
.warn { background: #fff5e5; border: 1px solid #f0d199; color: #6b3d00; border-radius: 8px; padding: 8px 10px; margin: 8px 0; word-break: keep-all; }
.method { font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 10px; word-break: break-word; }
.exports { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* APA 표 */
.apa-wrap { margin: 14px 0; }
.apa-cap { font-family: "Times New Roman", "바탕", Batang, serif; margin-bottom: 4px; font-size: 15px; }
.apa-cap.kr b { font-weight: 700; }
.apa-cap.kr i { font-style: normal; }
.scroll-x { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.apa { border-collapse: collapse; font-family: "Times New Roman", "바탕", Batang, serif; font-size: 14px; min-width: 100%; }
table.apa thead th { border-top: 1.5px solid #000; border-bottom: 1px solid #000; font-weight: normal; padding: 4px 8px; text-align: center; white-space: nowrap; }
table.apa td { padding: 3px 8px; text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.apa .l { text-align: left; }
table.apa tbody tr:last-child td { border-bottom: 1.5px solid #000; }
.apa-note { font-family: "Times New Roman", "바탕", Batang, serif; font-size: 13px; margin: 4px 0 0; word-break: keep-all; }

/* 해석 */
.interp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.interp section { background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.interp h4 { margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.interp h4 button { font-size: 12px; padding: 2px 8px; }
.interp p { margin: 4px 0; word-break: keep-all; overflow-wrap: anywhere; }
.interp .paper p { font-family: "Times New Roman", "바탕", Batang, serif; }
details.rules { margin-top: 8px; font-size: 13px; }
details.rules table { border-collapse: collapse; }
details.rules td { border-bottom: 1px solid var(--line); padding: 2px 6px; vertical-align: top; }

/* 그림 */
.figtools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 10px 0 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 10px; background: #fff; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.chart { width: 100%; max-width: 640px; min-height: 60px; overflow: hidden; }
.chart svg { max-width: 100%; height: auto; }

.gb-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gb-controls label { display: flex; gap: 4px; align-items: center; }
.gb-controls select { max-width: 160px; }

/* 표 격자(변수·데이터) */
table.grid { border-collapse: collapse; font-size: 13px; background: #fff; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 3px 6px; white-space: nowrap; }
table.grid th { background: #eef2f5; position: sticky; top: 0; }
table.grid input[type=text] { width: 9em; border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; }
table.grid input.wide { width: 15em; }
.preview { max-height: 60vh; overflow: auto; }

.log { padding-left: 20px; }
.log li { margin: 6px 0; word-break: break-word; }
.log .flag { color: var(--bad); font-weight: 700; }

.foot { max-width: 1180px; margin: 30px auto; padding: 0 16px; font-size: 12.5px; color: var(--muted); word-break: keep-all; }
.foot a { color: var(--brand2); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px;
  border-radius: 8px; max-width: calc(100vw - 32px); z-index: 50; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }

.busy { opacity: .6; pointer-events: none; }

@media (max-width: 760px) {
  .analysis { grid-template-columns: minmax(0, 1fr); }
  .menu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu h4 { grid-column: 1 / -1; }
  .interp { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px; }
  .engine { order: 3; flex-basis: 100%; }
}
