:root {
  --bg: #fff;
  --fg: #1f2328;
  --muted: #6e7781;
  --line: #d0d7de;
  --subtle: #f6f8fa;
  --err: #cf222e;
  --err-bg: #ffebe9;
  --kw: #1f2328;
  --num: #0550ae;
  --var: #116329;
  --op: #8250df;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "D2Coding", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1000px; margin: 0 auto; padding: 16px;
}
h1 { margin: 0; font-size: 15px; font-weight: 600; }
h1 small { color: var(--muted); font-weight: 400; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
button, select {
  -webkit-tap-highlight-color: transparent;
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer;
}
button:hover:not(:disabled), select:hover { background: var(--subtle); }
button:disabled { color: var(--muted); cursor: default; }
button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); min-width: 6.5em; }
button.primary:hover:not(:disabled) { background: var(--fg); opacity: .85; }
button.primary:disabled { opacity: .4; color: var(--bg); }

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

/* 에디터: 투명한 textarea 뒤에 색칠한 pre를 겹친다 */
.editor { display: flex; height: 55vh; min-height: 260px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.gutter, .highlight, #code {
  font: 13px/1.6 var(--mono); tab-size: 4; margin: 0; padding: 10px 12px; white-space: pre;
}
.gutter {
  min-width: 3em; text-align: right; color: var(--muted); background: var(--subtle);
  border-right: 1px solid var(--line); overflow: hidden; user-select: none; padding-right: 8px;
}
.gutter .err { color: var(--err); font-weight: 600; }
.code { position: relative; flex: 1; overflow: hidden; }
.highlight, #code { position: absolute; inset: 0; overflow: auto; border: 0; }
.highlight { pointer-events: none; color: var(--fg); }
#code {
  width: 100%; height: 100%; resize: none; outline: none; background: transparent;
  color: transparent; caret-color: var(--fg);
}
.highlight .ln { display: block; }
.highlight .ln.err { background: var(--err-bg); }

.t-loop, .t-break, .t-out { color: var(--kw); font-weight: 600; }
.t-num { color: var(--num); }
.t-var { color: var(--var); }
.t-sign, .t-in { color: var(--op); }
.t-bad { text-decoration: underline wavy var(--err); }

.io { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; margin-top: 16px; }
.io section { min-width: 0; }
h2 { margin: 0 0 6px; font-size: 12px; font-weight: 600; }
#time { color: var(--muted); font-weight: 400; margin-left: 4px; }
#stdin, #output {
  display: block; width: 100%; margin: 0; height: 160px;
  font: 13px/1.6 var(--mono); color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
}
#stdin { resize: vertical; outline: none; }
#stdin:focus { border-color: var(--muted); }
#output { overflow: auto; white-space: pre-wrap; word-break: break-all; background: var(--subtle); }
#output .err { color: var(--err); }
#output .note { color: var(--muted); }

details { margin-top: 20px; color: var(--muted); }
summary { cursor: pointer; }
table { border-collapse: collapse; margin-top: 8px; color: var(--fg); }
td { padding: 4px 16px 4px 0; vertical-align: top; }
code { font-family: var(--mono); font-size: 12px; white-space: nowrap; }

@media (max-width: 700px) {
  .toolbar { width: 100%; flex-wrap: nowrap; }
  .toolbar select { flex: 1; min-width: 0; }
  .io { grid-template-columns: 1fr; }
  .editor { height: 45vh; }
  #stdin { height: 90px; }
  .gutter, .highlight, #code, #stdin, #output { font-size: 12.5px; }
  .gutter, .highlight, #code { padding: 8px 10px; }
  .gutter { min-width: 2.6em; padding-right: 6px; }
  button, select { padding: 4px 10px; }
}
