:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --success: #15803d;
  --success-bg: #dcfce7;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard",
    "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }

/* --- header nav ------------------------------------------------------------ */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.nav-brand a { color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: -.2px; }
.nav-brand a:hover { text-decoration: none; }
.nav-links { display: flex; gap: 2px; align-items: center; }
.nav-links a, .nav-links .user, .nav-links form button {
  padding: 6px 12px; border-radius: var(--radius-sm); font-size: 14px;
  color: var(--text-muted); font-weight: 500;
}
.nav-links a:hover, .nav-links form button:hover {
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
.nav-links .user { color: var(--text); }
.nav-links form { display: inline; margin: 0; }
.nav-links form button { background: none; border: 0; cursor: pointer; font-family: inherit; }

/* --- containers ------------------------------------------------------------ */
.container { max-width: 960px; margin: 28px auto 60px; padding: 0 24px; }
.container-narrow { max-width: 440px; margin: 80px auto 60px; padding: 0 24px; }

h1 { font-size: 22px; margin: 0 0 8px 0; letter-spacing: -.3px; font-weight: 700; }
h2 { font-size: 17px; margin: 28px 0 12px 0; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 10px 0; color: var(--text); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; }
p { margin: 0 0 12px 0; }
.subtitle { color: var(--text-muted); font-size: 14px; margin: 4px 0 20px 0; }

/* --- card ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 12px 0;
}
.card + .card { margin-top: 14px; }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.card-title { font-weight: 600; font-size: 16px; }
.card-meta { color: var(--text-muted); font-size: 13px; }
.card-section + .card-section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* --- icons ----------------------------------------------------------------- */
.icon { display: inline-block; flex-shrink: 0; vertical-align: middle; }
.icon-folder { color: #ca8a04; }   /* amber-600 */
.icon-file   { color: #94a3b8; }   /* slate-400 */

/* --- buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 14px;
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  font-family: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-ghost {
  background: none; color: var(--text-muted); padding: 4px 8px;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--error); border-color: var(--error); background: var(--surface); }
.btn-danger:hover { background: var(--error-bg); color: var(--error); border-color: var(--error); }

/* --- form ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.field input[type=text],
.field input[type=password],
.field input[type=email] {
  padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}
.field input:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.field-row { display: flex; gap: 8px; align-items: center; }
input[type=file] { font-size: 14px; color: var(--text-muted); }

/* --- messages -------------------------------------------------------------- */
.msg {
  padding: 10px 14px; border-radius: var(--radius-sm); margin: 10px 0;
  font-size: 14px; border: 1px solid transparent;
}
.msg.success { background: var(--success-bg); color: var(--success); border-color: rgba(21, 128, 61, .2); }
.msg.error { background: var(--error-bg); color: var(--error); border-color: rgba(185, 28, 28, .2); }
.msg.warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(180, 83, 9, .2); }

/* --- breadcrumbs ----------------------------------------------------------- */
.breadcrumbs { font-size: 14px; color: var(--text-muted); margin: 12px 0 12px 0; }
.breadcrumbs a { color: var(--primary); }
.breadcrumbs .sep { margin: 0 6px; color: var(--text-soft); }
.breadcrumbs .active { color: var(--text); font-weight: 600; }

/* --- file list ------------------------------------------------------------- */
.file-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.file-row {
  display: grid;
  grid-template-columns: 28px 1fr 90px 150px 120px;
  gap: 12px;
  padding: 8px 14px;
  align-items: center;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: var(--bg); }
.file-row.selectable { cursor: pointer; }
.file-check { display: flex; align-items: center; justify-content: center; }
.file-check input { margin: 0; }
.file-name {
  display: flex; align-items: center; gap: 8px;
  overflow: hidden;
}
.file-name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name.dir .label a { color: var(--text); font-weight: 500; }
.file-name.dir .label a:hover { color: var(--primary); }
.file-name.file .label { color: var(--text); }
.file-name.up .label a { color: var(--text-muted); }
.file-lead {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-soft);
}
.file-size { color: var(--text-muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.file-mtime { color: var(--text-muted); font-size: 13px; }
.file-actions { text-align: right; }
.file-actions a { font-size: 13px; }
.file-actions .file-preview-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--primary); margin-right: 8px;
}
.file-actions .file-preview-btn:hover { text-decoration: underline; }
.file-actions .delete-form { display: inline; margin-left: 8px; }
.file-delete-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--error);
}
.file-delete-btn:hover { text-decoration: underline; }
.file-list-header {
  display: grid;
  grid-template-columns: 28px 1fr 90px 150px 120px;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px;
  font-weight: 500;
}

/* --- file header row (breadcrumb 왼쪽 · toolbar 오른쪽) --------------------- */
.file-header-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
  margin: 8px 0 16px 0;
}
.file-header-row .breadcrumbs { margin: 0; }
.file-header-row .file-toolbar { margin: 0; }
.file-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* --- hidden (dot) files: 기본 숨김. body.show-hidden 이 켜지면 표시 -------- */
.file-row.hidden-item { display: none; }
body.show-hidden .file-row.hidden-item { display: grid; }

/* --- badge (덮어쓰기 표시 등) ---------------------------------------------- */
.badge {
  display: inline-block;
  padding: 1px 8px; font-size: 11px; font-weight: 600;
  border-radius: 999px;
  letter-spacing: .2px;
}
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.new  { background: var(--surface-2); color: var(--text-muted); }

/* --- modal (native <dialog>) ----------------------------------------------- */
dialog.modal {
  border: 0; padding: 0;
  border-radius: var(--radius);
  max-width: 480px; width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
  background: var(--surface);
  color: var(--text);
}
dialog.modal::backdrop { background: rgba(17, 24, 39, .5); backdrop-filter: blur(2px); }
.modal-inner { padding: 20px 24px 22px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; gap: 12px;
}
.modal-title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.2px; }
.modal-close {
  background: none; border: 0; cursor: pointer; padding: 6px;
  border-radius: var(--radius-sm); color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
}

/* --- dropzone -------------------------------------------------------------- */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text-muted);
  transition: background .12s, border-color .12s, color .12s;
}
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.dropzone p { margin: 6px 0 4px 0; font-size: 14px; }
.dropzone label.btn { cursor: pointer; }
.dropzone-list { list-style: none; padding: 0; margin: 14px 0 0 0; max-height: 200px; overflow-y: auto; }
.dropzone-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 7px 12px; background: var(--surface-2);
  border-radius: var(--radius-sm); margin: 4px 0; font-size: 13px;
}
.dropzone-list .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.dropzone-list .fs { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.dropzone-list li button {
  background: none; border: 0; color: var(--text-muted); cursor: pointer;
  font: inherit; padding: 4px 8px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center;
}
.dropzone-list li button:hover { background: var(--error-bg); color: var(--error); }

/* --- picked list (submission) ---------------------------------------------- */
.picked-list { list-style: none; padding: 0; margin: 10px 0 0 0; }
.picked-list li {
  padding: 8px 12px;
  background: var(--primary-soft); border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  margin: 6px 0;
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--mono); font-size: 13px;
}
.picked-list li button {
  background: none; border: 0; color: var(--error);
  font: inherit; cursor: pointer; padding: 2px 8px; border-radius: var(--radius-sm);
}
.picked-list li button:hover { background: rgba(185, 28, 28, .1); }
.picked-empty { color: var(--text-soft); font-size: 13px; padding: 4px 0; }

/* --- utilities ------------------------------------------------------------- */
.muted { color: var(--text-muted); font-size: 13px; }
.strong { font-weight: 600; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.mt-lg { margin-top: 24px; }
.pill {
  display: inline-block; padding: 2px 8px; font-size: 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); font-weight: 500;
}
.pill.success { background: var(--success-bg); color: var(--success); }
.pill.warn { background: var(--warning-bg); color: var(--warning); }
.file-inline { font-family: var(--mono); font-size: 13px; color: var(--text); }

/* --- dashboard tiles ------------------------------------------------------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.tile {
  display: block;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.tile:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  color: var(--text);
  text-decoration: none;
  transform: translateY(-1px);
}
.tile:hover .tile-arrow { color: var(--primary); transform: translateX(2px); }
.tile-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 14px;
}
.tile-arrow {
  position: absolute; top: 22px; right: 22px;
  color: var(--text-soft);
  transition: color .12s, transform .12s;
}
.tile h2 { margin: 0 0 4px 0; font-size: 17px; font-weight: 600; letter-spacing: -.2px; }
.tile p { margin: 0; color: var(--text-muted); font-size: 14px; line-height: 1.5; }

/* --- markdown content ------------------------------------------------------ */
.md { color: var(--text); font-size: 14px; line-height: 1.65; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px 0; font-weight: 600; }
.md h1 { font-size: 17px; }
.md h2 { font-size: 15px; }
.md h3 { font-size: 14px; }
.md h4 { font-size: 13px; color: var(--text-muted); }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; font-family: var(--mono); font-size: 12px; }
.md pre { background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; }
.md pre code { background: transparent; padding: 0; font-size: 12.5px; }
.md a { color: var(--primary); }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.md table th, .md table td { border: 1px solid var(--border); padding: 4px 10px; }
.md table th { background: var(--surface-2); font-weight: 600; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md-wrap {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 10px 0 4px 0;
}

/* --- login page ------------------------------------------------------------ */
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}
.login-title { font-size: 20px; margin: 0 0 4px 0; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.login-brand { text-align: center; font-weight: 700; color: var(--text); margin-bottom: 20px; letter-spacing: -.3px; font-size: 18px; }

/* --- terminal (dark full-screen) ------------------------------------------- */
body.terminal-body { background: #0d1117; margin: 0; }
.terminal-nav {
  background: #161b22; border-bottom: 1px solid #30363d;
  color: #c9d1d9;
  padding: 8px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  font-size: 14px;
}
.terminal-nav .nav-brand a { color: #c9d1d9; }
.terminal-nav .nav-links a,
.terminal-nav .nav-links .user,
.terminal-nav .nav-links form button {
  color: #8b949e; padding: 4px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.terminal-nav .nav-links a:hover, .terminal-nav .nav-links form button:hover {
  background: #21262d; color: #c9d1d9;
}
.terminal-nav .nav-links .user { color: #c9d1d9; }
.terminal-frame { display: block; width: 100%; height: calc(100vh - 40px); border: 0; background: #000; }

/* --- terminal loading (첫 진입 시 Traefik 라우터 등록 + ttyd 부팅 대기) --- */
.term-status {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: calc(100vh - 40px);
  color: #8b949e;
  font-family: var(--mono);
  font-size: 13px;
  background: #0d1117;
  gap: 14px;
}
.term-status.error { color: #f97583; }
.term-spinner {
  width: 22px; height: 22px;
  border: 2px solid #30363d;
  border-top-color: #58a6ff;
  border-radius: 50%;
  animation: term-spin .8s linear infinite;
}
@keyframes term-spin { to { transform: rotate(360deg); } }

/* --- responsive ------------------------------------------------------------ */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .container { padding: 0 16px; margin: 20px auto 40px; }
  .nav { padding: 10px 16px; }
  .card { padding: 14px 16px; }
  h1 { font-size: 20px; }
  .file-row, .file-list-header { grid-template-columns: 24px 1fr 80px; }
  .file-row .file-mtime, .file-list-header .file-mtime { display: none; }
  .file-row .file-actions, .file-list-header .file-actions { display: none; }
}

/* --- 채점 · 미리보기 · 결과 알림 ------------------------------------------- */
.grade-details { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.grade-details summary {
  cursor: pointer; font-size: 13px; color: var(--text-muted);
  font-weight: 500; user-select: none;
}
.grade-details summary:hover { color: var(--text); }
.grade-form { margin-top: 10px; }
.grade-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.grade-row label { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.grade-row input[type="number"] { width: 84px; }
.grade-row input[type="number"], .grade-form textarea {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 6px 8px; font-family: inherit; font-size: 13px;
}
.grade-form textarea { width: 100%; resize: vertical; box-sizing: border-box; }
dialog.modal-wide { max-width: 780px; }
.preview-pre {
  max-height: 62vh; overflow: auto; margin: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 14px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
}
.result-list {
  list-style: none; padding: 0; margin: 0 0 16px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 55vh; overflow-y: auto;
}
.result-list li { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.result-feedback { margin-top: 8px; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
