* { box-sizing: border-box; }

:root {
  --bg-page: #0f0f10;
  --bg-panel: #1c1c1f;
  --bg-topbar: #000;
  --bg-code: #0a0a0b;
  --bg-input: #141416;
  --text: #e8e8ea;
  --text-muted: #9a9aa1;
  --border: #2a2a2e;
  --accent: #4a90e2;
  --accent-hover: #3a7bc5;
  --warn-bg: #3a2f1a;
  --warn-text: #e6c47a;
  --danger-bg: #3a1f1f;
  --danger-text: #ff8b8b;
  --ok-bg: #1d3326;
  --ok-text: #6fd99a;
  --bad-bg: #3a1f1f;
  --bad-text: #ff9999;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-topbar);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.topbar .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; font-size: 0.9rem; }
#progress-summary { padding: 4px 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; }

button, .file-btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover, .file-btn:hover { background: #2a2a2e; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #4a3d1f; }
button.danger { background: var(--danger-bg); color: var(--danger-text); border-color: #5a2a2a; }
button.cram-on { background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%); color: #fff; border-color: #ff6b35; animation: cram-pulse 2s infinite; }
@keyframes cram-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.7); } 50% { box-shadow: 0 0 0 6px rgba(255,107,53,0); } }
.file-btn { display: inline-block; }

.howto {
  margin: 16px 20px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.howto summary { font-weight: 600; cursor: pointer; color: var(--text); }
.howto ol { margin: 10px 0 0 0; padding-left: 24px; color: var(--text-muted); }
.howto strong { color: var(--text); }

.screen { max-width: 900px; margin: 0 auto; padding: 20px; }

.exercise-head { margin-bottom: 20px; }
.exercise-head h2 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1.2;
}
.question-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
}
.question-badge .badge-label { opacity: 0.85; font-weight: 500; }
.question-badge .badge-num { font-variant-numeric: tabular-nums; }
.exercise-head .part {
  margin: 0 0 6px 0;
  color: var(--text);
  font-size: 1rem;
}
.exercise-head .part-label {
  color: var(--text-muted);
  margin-right: 6px;
}
.exercise-head .part strong {
  color: var(--text);
  font-weight: 600;
}
.exercise-head .streak { margin: 6px 0 0 0; font-size: 0.9rem; color: var(--text-muted); }
.exercise-head code {
  background: var(--bg-panel);
  padding: 2px 8px;
  margin-left: 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
  max-width: 360px;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.95rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in 0.25s ease-out;
  border-left: 4px solid var(--accent);
}
.toast.success { border-left-color: var(--ok-text); }
.toast.warn    { border-left-color: var(--warn-text); }
.toast.danger  { border-left-color: var(--danger-text); }
.toast.info    { border-left-color: var(--accent); }
.toast.mastered {
  border-left-color: var(--ok-text);
  background: linear-gradient(135deg, var(--bg-panel) 0%, rgba(111, 217, 154, 0.15) 100%);
}
.toast .toast-icon { font-size: 1.2rem; line-height: 1.2; }
.toast .toast-body { flex: 1; }
.toast .toast-title { font-weight: 600; margin-bottom: 2px; }
.toast .toast-sub { color: var(--text-muted); font-size: 0.85rem; }
.toast.leaving { animation: toast-out 0.25s ease-in forwards; }

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

#ex-explanation {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
#ex-explanation summary { font-weight: 600; cursor: pointer; color: var(--text); }
#ex-steps {
  margin: 12px 0 0 0;
  padding-left: 24px;
}
#ex-steps li { margin-bottom: 10px; }
#ex-steps .explain { display: block; margin-bottom: 4px; color: var(--text); }
#ex-steps pre {
  margin: 0;
  padding: 8px 12px;
  background: var(--bg-code);
  color: #d4d4d8;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.9rem;
  overflow-x: auto;
}

.editor-wrap label { font-weight: 600; display: inline-block; margin-bottom: 6px; color: var(--text); }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.cheat { font-size: 0.85rem; color: var(--text-muted); }
.cheat summary { cursor: pointer; padding: 4px 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; user-select: none; }
.cheat summary:hover { background: #2a2a2e; }
.cheat[open] summary { background: var(--accent); color: #fff; border-color: var(--accent); }
.cheat ul {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 16px;
}
.cheat ul li {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cheat code {
  display: inline-block;
  min-width: 50px;
  padding: 1px 6px;
  background: var(--bg-code);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-right: 4px;
}
.cheat .cheat-arrow { color: var(--text-muted); margin-right: 4px; }
.cheat .cheat-body { color: var(--text); }

#ex-input {
  width: 100%;
  min-height: 240px;
  padding: 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.95rem;
  resize: vertical;
  tab-size: 2;
  caret-color: var(--accent);
}
#ex-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  align-items: center;
}
.postup-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: #2d3a5a;
  color: #d4e0f5;
  border: 1px solid #3a5078;
  border-radius: 4px;
  text-decoration: none;
  font-size: inherit;
}
.postup-link:hover { background: #3a4a6a; }

.diff {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  color: var(--text);
}
.diff:empty { display: none; }
.diff.ok { background: var(--ok-bg); border-color: #2d5a3a; color: var(--ok-text); }
.diff.bad { background: var(--bad-bg); border-color: #5a2d2d; color: var(--bad-text); }
.diff .bad-char { background: #6b1f1f; color: #ffd0d0; text-decoration: underline; padding: 0 2px; border-radius: 2px; }
.diff .ref-line { display: block; color: #c0c0c5; }
.diff .ref-line.diff-here { color: #ff8888; font-weight: 600; }

.footer { padding: 12px 20px; text-align: center; color: var(--text-muted); }
.empty { font-size: 1.1rem; color: var(--text); }

::selection { background: rgba(74, 144, 226, 0.3); }

@media (max-width: 600px) {
  .screen { padding: 12px; }
  .topbar { padding: 10px 12px; }
}
