:root {
  color-scheme: light;
  --bg: #f4f5ee;
  --surface: #fffdf7;
  --surface-muted: #f0f3e8;
  --text: #1e2a20;
  --text-muted: #697467;
  --text-secondary: #334036;
  --text-tertiary: #536155;
  --placeholder: #8d998b;
  --border: #dde3d4;
  --border-strong: #c8d1bf;
  --header-bg: rgb(255 253 247 / 92%);
  --neutral-soft: #e9eee2;
  --track: #e5ebdd;
  --primary: #5f7447;
  --primary-dark: #4f633a;
  --primary-soft: #e7eedc;
  --on-primary: #ffffff;
  --success: #2f7d50;
  --success-soft: #e7f4e9;
  --success-border: #8bbf98;
  --warning: #b54708;
  --warning-soft: #fff7e8;
  --warning-border: #fedf89;
  --open-border: #f5c573;
  --danger: #c4320a;
  --danger-soft: #fff0ec;
  --danger-border: #ffd6cc;
  --info: #356d67;
  --info-soft: #e7f2ef;
  --card-hover-border: #b7c3ad;
  --toast-bg: #253126;
  --toast-text: #ffffff;
  --toast-error: #912018;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgb(16 24 40 / 4%), 0 8px 24px rgb(16 24 40 / 5%);
  --focus: 0 0 0 3px rgb(95 116 71 / 22%);
  font-family: Inter, Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10160f;
  --surface: #182117;
  --surface-muted: #141c13;
  --text: #f0f4eb;
  --text-muted: #a7b2a1;
  --text-secondary: #d5ddcf;
  --text-tertiary: #bdc8b6;
  --placeholder: #7e8c78;
  --border: #2d3b2a;
  --border-strong: #40503b;
  --header-bg: rgb(16 22 15 / 90%);
  --neutral-soft: #243222;
  --track: #2a3827;
  --primary: #a9c78a;
  --primary-dark: #91b573;
  --primary-soft: #293a24;
  --on-primary: #142010;
  --success: #68d095;
  --success-soft: #173823;
  --success-border: #387852;
  --warning: #ffc16b;
  --warning-soft: #382817;
  --warning-border: #735124;
  --open-border: #805d2d;
  --danger: #ff917a;
  --danger-soft: #3b1e1c;
  --danger-border: #74352e;
  --info: #79beb2;
  --info-soft: #183631;
  --card-hover-border: #52634c;
  --toast-bg: #e9efe3;
  --toast-text: #1e2a20;
  --toast-error: #a53229;
  --shadow: 0 1px 2px rgb(0 0 0 / 20%), 0 12px 32px rgb(0 0 0 / 20%);
  --focus: 0 0 0 3px rgb(169 199 138 / 27%);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.55;
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }

button:disabled,
input:disabled { cursor: not-allowed; opacity: .55; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--primary);
}

.hidden { display: none !important; }

.app-shell { min-height: 100vh; }

.app-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--on-primary);
  background: var(--primary);
  border-radius: 11px;
  font-weight: 800;
  letter-spacing: -.03em;
}

.brand strong,
.brand small { display: block; }

.brand strong { font-size: 15px; line-height: 1.2; white-space: nowrap; }
.brand small { margin-top: 2px; color: var(--text-muted); font-size: 12px; }

.header-tools,
.header-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 11px;
  color: var(--text-tertiary);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }

.main-content {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
  padding: 46px 0 72px;
}

.auth-layout {
  min-height: calc(100vh - 190px);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .11em;
}

.dashboard-heading h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.12;
  letter-spacing: -.045em;
}

.auth-card,
.activity-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth-card { width: min(100%, 460px); padding: 30px; }
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -.025em; }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading.compact { margin-bottom: 22px; }
.section-heading h2 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.section-heading p { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }
.section-heading .eyebrow { margin-bottom: 6px; }

.form-stack { display: grid; gap: 16px; }

.field { display: grid; gap: 7px; }
.field > span { color: var(--text-secondary); font-size: 14px; font-weight: 700; }

.field input,
.field select,
.pin-form input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.field input::placeholder,
.pin-form input::placeholder { color: var(--placeholder); }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text-tertiary);
  font-size: 14px;
  cursor: pointer;
}

.check-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 750;
  font-size: 14px;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.button:not(:disabled):active { transform: translateY(1px); }
.button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { color: var(--on-primary); background: var(--primary); }
.button-primary:hover:not(:disabled) { background: var(--primary-dark); }
.button-secondary { color: var(--text-secondary); background: var(--surface); border-color: var(--border-strong); }
.button-secondary:hover:not(:disabled), .button-ghost:hover:not(:disabled) { background: var(--surface-muted); }
.button-danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.button-warning { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.button-ghost { color: var(--text-tertiary); background: transparent; border-color: transparent; }
.button-block { width: 100%; }
.button-small { min-height: 38px; padding: 7px 12px; }

.form-error {
  margin: 0;
  padding: 10px 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.privacy-note { margin: 18px 0 0; color: var(--text-muted); font-size: 12px; text-align: center; }

.dashboard-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.dashboard-heading h1 { font-size: clamp(30px, 4vw, 42px); }
.dashboard-heading p { margin: 9px 0 0; color: var(--text-muted); }

.usage-guide {
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(16 24 40 / 3%);
}

.usage-guide summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  cursor: pointer;
  list-style: none;
}

.usage-guide summary::-webkit-details-marker { display: none; }
.usage-guide summary strong,
.usage-guide summary small { display: block; }
.usage-guide summary strong { font-size: 16px; }
.usage-guide summary small { margin-top: 2px; color: var(--text-muted); font-size: 13px; font-weight: 500; }
.guide-toggle { color: var(--primary); font-size: 13px; font-weight: 750; }
.usage-guide:not([open]) .guide-toggle { font-size: 0; }
.usage-guide:not([open]) .guide-toggle::after { content: "펼치기"; font-size: 13px; }

.guide-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 18px;
  border-top: 1px solid var(--border);
}

.guide-step {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  padding: 0 18px;
  border-left: 1px solid var(--border);
}

.guide-step:first-child { padding-left: 0; border-left: 0; }
.guide-step:last-child { padding-right: 0; }
.step-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
}
.guide-step strong { display: block; font-size: 14px; }
.guide-step p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }

.guide-choice {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 18px 18px;
}

.guide-choice p {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
}
.guide-choice strong,
.guide-choice span { display: block; }
.guide-choice strong { font-size: 13px; }
.guide-choice span { margin-top: 3px; color: var(--text-muted); font-size: 12px; }

.status-chip,
.course-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.connection-label-short { display: none; }
.status-idle { color: var(--text-muted); background: var(--neutral-soft); }
.status-connecting, .status-reconnecting { color: var(--warning); background: var(--warning-soft); }
.status-connected, .status-success, .status-complete { color: var(--success); background: var(--success-soft); }
.status-open, .status-solving, .status-submitting { color: var(--warning); background: var(--warning-soft); }
.status-auto_waiting { color: var(--warning); background: var(--warning-soft); }
.status-monitoring, .status-preparing { color: var(--info); background: var(--info-soft); }
.status-error, .status-failed, .status-timeout { color: var(--danger); background: var(--danger-soft); }
.status-stopped, .status-unknown { color: var(--text-muted); background: var(--neutral-soft); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.summary-card span { display: block; color: var(--text-muted); font-size: 13px; font-weight: 650; }
.summary-card strong { display: block; margin-top: 3px; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 10px; font-weight: 800; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 22px;
  align-items: start;
}

.course-list { display: grid; gap: 14px; }

.course-card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.course-card:hover { border-color: var(--card-hover-border); box-shadow: 0 5px 18px rgb(0 0 0 / 7%); }
.course-card.is-open { border-color: var(--open-border); }
.course-card.is-success { border-color: var(--success-border); }

.course-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.course-title { min-width: 0; }
.course-title h3 { margin: 0; font-size: 17px; line-height: 1.4; letter-spacing: -.015em; overflow-wrap: anywhere; }
.course-key { margin: 4px 0 0; color: var(--text-muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.course-detail { margin: 16px 0 0; color: var(--text-tertiary); font-size: 14px; }

.progress-wrap { margin-top: 16px; }
.progress-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.progress-track {
  width: 100%;
  height: 8px;
  display: block;
  overflow: hidden;
  appearance: none;
  background: var(--track);
  border: 0;
  border-radius: 999px;
}
.progress-track::-webkit-progress-bar { background: var(--track); border-radius: 999px; }
.progress-track::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
.progress-track::-moz-progress-bar { background: var(--primary); border-radius: 999px; }

.course-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 11px;
  color: var(--warning);
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.auto-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--warning); }

.delay-setting {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 13px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.delay-copy strong,
.delay-copy span { display: block; }
.delay-copy strong { color: var(--text-secondary); font-size: 13px; }
.delay-copy span { margin-top: 2px; color: var(--text-muted); font-size: 12px; }

.delay-stepper {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.delay-stepper button,
.delay-stepper input {
  height: 38px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.delay-stepper button {
  width: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 18px;
  font-weight: 750;
}
.delay-stepper button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.delay-stepper button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.delay-stepper button:hover:not(:disabled) { color: var(--primary); background: var(--primary-soft); }

.delay-stepper input {
  width: 64px;
  padding: 6px 4px 6px 9px;
  border-inline: 0;
  border-radius: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.delay-unit {
  height: 38px;
  display: grid;
  place-items: center;
  padding-right: 7px;
  color: var(--text-muted);
  background: var(--surface);
  border-block: 1px solid var(--border-strong);
  font-size: 12px;
}

.pin-form { display: flex; gap: 8px; flex: 1 1 250px; }
.pin-form input { min-width: 110px; font-variant-numeric: tabular-nums; letter-spacing: .16em; }

.admin-note {
  flex: 1 0 100%;
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.empty-state {
  padding: 48px 24px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
}

.activity-panel {
  position: sticky;
  top: 94px;
  max-height: calc(100vh - 118px);
  padding: 20px;
  overflow: hidden;
}

.activity-list {
  display: grid;
  gap: 0;
  max-height: calc(100vh - 215px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.activity-item {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.activity-item:first-child { border-top: 0; padding-top: 0; }
.activity-time { color: var(--placeholder); font-variant-numeric: tabular-nums; }
.activity-message { color: var(--text-tertiary); overflow-wrap: anywhere; }
.activity-item.level-success .activity-message { color: var(--success); }
.activity-item.level-warning .activity-message { color: var(--warning); }
.activity-item.level-error .activity-message { color: var(--danger); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  color: var(--toast-text);
  background: var(--toast-bg);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgb(16 24 40 / 22%);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  font-size: 14px;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { color: #fff; background: var(--toast-error); }

@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .guide-steps { grid-template-columns: 1fr; gap: 16px; }
  .guide-step,
  .guide-step:first-child,
  .guide-step:last-child { padding: 0; border-left: 0; }
  .content-grid { grid-template-columns: 1fr; }
  .activity-panel { position: static; max-height: none; }
  .activity-list { max-height: 420px; }
}

@media (max-width: 600px) {
  .app-header { height: 64px; padding: 0 16px; }
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .header-actions { gap: 4px; }
  .header-actions .button { padding-inline: 9px; white-space: nowrap; }
  .status-chip { padding-inline: 8px; }
  .theme-toggle { width: 38px; padding: 7px; }
  .theme-label { display: none; }
  .connection-label-full { display: none; }
  .connection-label-short { display: inline; }
  .main-content { width: min(100% - 32px, 1240px); padding: 28px 0 52px; }
  .auth-layout { min-height: auto; }
  .auth-card { padding: 22px 18px; }
  .dashboard-heading { align-items: stretch; flex-direction: column; margin-bottom: 22px; }
  .dashboard-heading .button { width: 100%; }
  .summary-grid { gap: 10px; }
  .usage-guide summary { padding-inline: 15px; }
  .guide-steps { padding: 16px 15px; }
  .guide-choice { grid-template-columns: 1fr; padding: 0 15px 15px; }
  .summary-card { padding: 15px; }
  .summary-card strong { font-size: 23px; }
  .summary-icon { display: none; }
  .course-card { padding: 17px 15px; }
  .course-top { flex-direction: column; }
  .course-actions > .button,
  .course-actions > .auto-toggle { flex: 1 1 auto; }
  .pin-form { flex-basis: 100%; }
  .delay-setting { align-items: stretch; flex-direction: column; gap: 9px; }
  .delay-stepper { width: 100%; }
  .delay-stepper input { flex: 1 1 auto; width: 0; }
  .activity-panel { padding: 18px 15px; }
  .toast { right: 16px; bottom: 16px; }
}

@media (max-width: 360px) {
  .connection-label-short { display: none; }
  .status-chip { padding-inline: 7px; }
  .logout-label { display: none; }
  .header-actions .button {
    width: 38px;
    padding-inline: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
