:root {
  --blue: #2b7de9;
  --blue-dark: #1c5fb8;
  --green: #22a06b;
  --red: #d64545;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #223;
  --line: #dde5ef;
  --mono: 'Consolas', 'Menlo', 'BIZ UDGothic', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Hiragino Kaku Gothic ProN', 'BIZ UDPGothic', 'Yu Gothic UI', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 3px solid var(--blue);
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 26px; font-weight: 800; color: var(--blue); letter-spacing: 1px; }
.tagline { font-size: 13px; color: #667; }

.status {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.status.loading { background: #fff3cd; color: #7a5c00; }
.status.ready   { background: #d9f2e5; color: #14683f; }
.status.running { background: #dbe9ff; color: #1c5fb8; }

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px 1fr 1.2fr;
  gap: 14px;
  padding: 14px 20px;
  align-items: stretch;
  overflow: hidden;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar h2 { margin: 4px 4px 10px; font-size: 15px; }
.sidebar nav { min-height: 0; overflow-y: auto; padding: 0 2px; }
.course { margin-bottom: 14px; }
.course-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #556;
  margin: 0 2px 6px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.course:first-child .course-title { border-top: none; padding-top: 0; }
.course-progress {
  font-weight: 400;
  color: #889;
  white-space: nowrap;
}
.course-progress.complete { color: var(--green); font-weight: 700; }
.crumb { font-size: 12px; color: #778; margin-bottom: 2px; }
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}
.nav-item:hover { border-color: var(--blue); }
.nav-item.active { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; }

.lesson-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  line-height: 1.9;
  font-size: 15px;
  min-height: 0;
  overflow-y: auto;
}
.lesson-pane h1 { font-size: 21px; margin: 0 0 12px; color: var(--blue-dark); }
.lesson-pane pre.code {
  background: #f0f4fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 14px;
  overflow-x: auto;
}
.lesson-pane .task {
  background: #fff8e6;
  border: 2px solid #f0c040;
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 14px;
}
.lesson-pane .task h3 { margin: 0 0 6px; font-size: 15px; }

.work-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

#editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
#editor .cm-editor { min-height: 220px; max-height: 45vh; }
#editor .cm-scroller { overflow: auto; }

.toolbar { display: flex; gap: 10px; align-items: center; }

.btn {
  font-size: 16px;
  font-weight: 700;
  padding: 10px 26px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--green); }
.btn.primary:hover:not(:disabled) { background: #1b8557; }
.btn.danger { background: var(--red); }
.btn.danger:hover:not(:disabled) { background: #b93a3a; }

.console {
  margin: 0;
  background: #1e2430;
  color: #e8edf5;
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 140px;
  max-height: 32vh;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}
.console .err { color: #ff9d9d; }
.console .in  { color: #9fd8ff; }
.console .sys { color: #ffd479; }

.stdin-input {
  background: #2c3547;
  border: 1px solid #4a5a78;
  border-radius: 6px;
  color: #9fd8ff;
  font-family: var(--mono);
  font-size: 14px;
  padding: 2px 8px;
  width: 60%;
}

.judge { border-radius: 12px; font-size: 16px; }
.judge.pass, .judge.fail { padding: 14px 18px; }
.judge.pass { background: #d9f2e5; border: 2px solid var(--green); }
.judge.fail { background: #fdecec; border: 2px solid var(--red); }
.judge p { margin: 0 0 8px; font-weight: 700; }
.judge .btn.next { background: var(--blue); font-size: 14px; padding: 8px 18px; }
.judge .btn.answer {
  display: block;
  background: #8892a6;
  font-size: 13px;
  padding: 6px 14px;
  margin-top: 10px;
}
.judge .answer-code {
  background: #1e2430;
  color: #e8edf5;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.site-footer {
  text-align: center;
  font-size: 12px;
  color: #778;
  padding: 12px;
}

@media (max-width: 900px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .app { grid-template-columns: 1fr; overflow: visible; }
  .sidebar, .lesson-pane, .work-pane { overflow: visible; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 6px; overflow: visible; }
  .nav-item { width: auto; }
}
