:root {
  --ink: #17202a;
  --muted: #5d6978;
  --line: #ccd7e3;
  --soft: #f5f8fb;
  --panel: #fff;
  --blue: #2563eb;
  --green: #12845f;
  --red: #d83f5f;
  --amber: #c77400;
  --shadow: 0 14px 36px rgba(25, 37, 52, .11);
  font-family: "Segoe UI", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--soft); color: var(--ink); line-height: 1.5; }
button, input, select { font: inherit; }
h1, h2, h3, p { margin: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: rgba(245, 248, 251, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1 1 auto; }
.brand > div:last-child { min-width: 0; }
.brand h1 { font-size: 20px; }
.brand h1[hidden] { display: none; }
.brand p { color: var(--ink); font-size: 16px; font-weight: 850; white-space: nowrap; }
.brand-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; margin-left: auto; }
.brand-actions[hidden] { display: none; }
.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 5px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.brand-mark span { background: #dce7fb; border-radius: 3px; }
.brand-mark span:nth-child(1), .brand-mark span:nth-child(4) { background: var(--blue); }

main { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding: 18px 0 48px; }
.screen { display: grid; gap: 18px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.login-panel { max-width: 520px; margin: 34px auto; }
.grid { display: grid; gap: 14px; }
.two-col { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 18px; align-items: start; }
.exercise-head { display: grid; grid-template-columns: auto minmax(240px, 1fr) minmax(220px, 320px); gap: 14px; align-items: end; }
.practice-frame {
  width: 100%;
  min-height: 820px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
}
.layout { display: grid; grid-template-columns: 350px minmax(0, 1fr); gap: 18px; align-items: start; }
.problem-panel { display: grid; gap: 15px; }
.board-panel { min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 750; }
.label { display: block; color: var(--muted); font-size: 13px; font-weight: 750; margin-bottom: 6px; }
.problem-select { min-width: 0; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #b8c5d4;
  border-radius: 7px;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
}
.button {
  min-height: 42px;
  border: 1px solid #b8c5d4;
  background: white;
  color: var(--ink);
  border-radius: 7px;
  cursor: pointer;
  font-weight: 750;
  padding: 9px 13px;
}
.button.primary { background: var(--blue); color: white; border-color: var(--blue); }
.button.ghost { color: var(--muted); }
.button.danger { color: #8d2138; border-color: #e6a8b7; }
.top-actions, .actions, .tabs, .right { display: flex; flex-wrap: wrap; gap: 8px; }
.top-actions { width: 100%; }
.top-actions[hidden] { display: none; }
.right { justify-content: flex-end; }
.link-button { border: 0; padding: 0; background: none; color: var(--blue); text-decoration: underline; cursor: pointer; font-weight: 700; }
.button.compact { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.header-progress {
  width: min(760px, 58vw);
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 6px 10px;
  align-items: center;
}
.header-progress-head {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.header-progress-bar {
  height: 12px;
  border: 0;
  border-radius: 999px;
  background: #e3eaf3;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
}
.header-progress-bar > span { display: block; height: 100%; background: var(--green); }

.mode-list { display: grid; gap: 8px; }
.mode-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  align-items: start;
  padding: 10px;
  border: 1px solid #dbe4ef;
  border-radius: 7px;
  background: white;
  color: var(--muted);
  font-size: 14px;
}
.mode-item strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 2px; }
.mode-item.current {
  border-color: rgba(18, 132, 95, .55);
  background: #eefaf5;
  color: #245c49;
  box-shadow: inset 4px 0 0 var(--green), 0 8px 18px rgba(18, 132, 95, .12);
}
.badge {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #eaf1ff;
  color: var(--blue);
  font-weight: 900;
}
.mode-item.current .badge { background: var(--green); color: white; }
.problem-box {
  min-height: 76px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 13px;
  background: #f4f7fb;
  border: 1px solid #dbe4ef;
  border-radius: 7px;
  font-weight: 800;
  font-size: 20px;
}
.problem-box small { color: var(--muted); font-size: 13px; font-weight: 650; }
.board-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.board-head h2, .board-head h3 { font-size: 20px; }
.board-head p { color: var(--muted); font-size: 14px; }

.progress { display: grid; gap: 6px; }
.progress-head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 750; }
.bar { height: 12px; border-radius: 999px; background: #e3eaf3; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--green); transition: width .2s ease; }

.problem-list { display: grid; gap: 8px; max-height: 560px; overflow: auto; padding-right: 4px; }
.problem-button {
  display: grid;
  gap: 3px;
  width: 100%;
  text-align: left;
  border: 1px solid #dbe4ef;
  border-radius: 7px;
  background: white;
  padding: 10px;
  cursor: pointer;
}
.problem-button.active { border-color: var(--blue); box-shadow: inset 4px 0 0 var(--blue); }
.problem-button.done { background: #eefaf5; border-color: #b7ddcc; }
.problem-button.wrong { background: #fff4f6; border-color: #efb5c2; }
.problem-button small { color: var(--muted); }
.progress[role="button"] { cursor: pointer; }
.progress-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.progress-card {
  display: grid;
  gap: 5px;
  align-content: start;
  padding: 11px;
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  background: white;
}
.progress-card.done { border-color: #b7ddcc; background: #eefaf5; }
.progress-card.wrong { border-color: #efb5c2; background: #fff4f6; }
.progress-card small { color: var(--muted); font-size: 13px; font-weight: 650; }

.prompt {
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 14px;
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  background: #f6f9fd;
  font-size: 20px;
  font-weight: 850;
}
.hint { color: var(--muted); font-size: 13px; font-weight: 600; }
.step-card {
  display: grid;
  gap: 13px;
  padding: 16px;
  border: 2px solid rgba(37, 99, 235, .28);
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff 0%, #fff 130px);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .06), 0 12px 28px rgba(25, 37, 52, .08);
}
.step-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.step-chip {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eaf1ff;
  color: #1645a2;
  font-size: 13px;
  font-weight: 850;
}
.step-prompt {
  padding: 14px;
  border: 2px solid rgba(37, 99, 235, .36);
  border-radius: 7px;
  background: #eef5ff;
  box-shadow: inset 5px 0 0 var(--blue);
  font-size: 18px;
  font-weight: 800;
}
.step-prompt::before {
  content: "지금 해결할 부분";
  display: block;
  width: max-content;
  margin-bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 900;
}
.feedback { min-height: 54px; padding: 12px; border: 1px solid #dbe4ef; border-radius: 7px; background: #f6f9fd; color: var(--muted); }
.feedback.good { border-color: #8fd0b4; background: #eefaf5; color: #0f5138; }
.feedback.bad { border-color: #efb5c2; background: #fff4f6; color: #8d2138; }
.feedback.complete { border-color: #8fd0b4; background: #dff5eb; color: #0f5138; box-shadow: inset 5px 0 0 var(--green); font-weight: 750; }

.kmap-wrap { overflow-x: auto; padding: 8px 0; }
.kmap {
  display: grid;
  grid-template-columns: 62px repeat(var(--cols), 72px);
  grid-template-rows: 38px repeat(var(--rows), 58px);
  width: max-content;
}
.kcell, .klabel {
  display: grid;
  place-items: center;
  border: 1px solid #b9c6d4;
  background: white;
  font-weight: 850;
}
.klabel { background: #e8eef6; color: #3f4f62; font-size: 13px; text-align: center; }
.kcell { position: relative; font-size: 24px; cursor: pointer; user-select: none; }
.kcell small { position: absolute; right: 5px; bottom: 3px; color: #7b8794; font-size: 11px; font-weight: 800; }
.kcell.on { background: #dbe8ff; color: #1645a2; box-shadow: inset 0 0 0 3px rgba(37, 99, 235, .25); }
.kcell.group-draft { background: #fff1d6; box-shadow: inset 0 0 0 4px rgba(199, 116, 0, .24); }
.kcell.group-saved { background: #ddf3e8; box-shadow: inset 0 0 0 4px rgba(18, 132, 95, .24); }
.kcell:disabled { cursor: default; opacity: 1; }
.answer-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.step-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.answer-panel {
  display: none;
  margin-top: 14px;
  padding: 14px;
  border: 2px solid rgba(18, 132, 95, .55);
  border-radius: 8px;
  background: #eefaf5;
  box-shadow: inset 5px 0 0 var(--green), 0 10px 22px rgba(18, 132, 95, .14);
}
.answer-panel.show { display: block; }
.group-summary {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid #dbe4ef;
  border-radius: 7px;
  background: #f6f9fd;
}
.group-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.group-chip {
  padding: 6px 9px;
  border: 1px solid #cfd8e3;
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.group-chip.done { border-color: #8fd0b4; background: #ddf3e8; color: #0f5138; }

table { width: 100%; border-collapse: collapse; background: white; }
th, td { border-bottom: 1px solid #e1e8f0; padding: 9px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
.pill { display: inline-flex; padding: 3px 8px; border-radius: 999px; background: #edf2f7; font-size: 12px; font-weight: 800; }
.pill.good { background: #ddf3e8; color: #0f5138; }
.pill.bad { background: #ffe3e9; color: #8d2138; }
.pill.mid { background: #fff1d6; color: #704700; }

.dialog { max-width: 560px; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(15, 23, 42, .34); }
.dialog form { display: grid; gap: 14px; }

@media (max-width: 860px) {
  .topbar { align-items: center; flex-wrap: wrap; }
  .brand { min-width: 0; flex-wrap: nowrap; }
  .brand p { overflow: hidden; text-overflow: ellipsis; }
  .brand-actions { flex: 0 0 auto; }
  .top-actions { width: 100%; }
  .header-progress {
    width: 100%;
    grid-template-columns: 1fr;
  }
  .header-progress-bar {
    width: 100%;
    height: 16px;
  }
  .header-progress .button {
    width: 100%;
  }
  .two-col, .cards, .exercise-head, .layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  main { width: 100%; padding: 12px 10px 32px; }
  .panel { border-radius: 0; box-shadow: none; padding: 14px; }
  .step-head { display: grid; }
  .answer-row { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .header-progress-head { font-size: 14px; }
  .brand-actions .button { min-height: 38px; padding: 7px 10px; }
  .kmap { grid-template-columns: 50px repeat(var(--cols), 58px); grid-template-rows: 34px repeat(var(--rows), 50px); }
}
