:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #475569;
  --secondary-dark: #334155;
  --border: #d7e0ea;
  --success: #15803d;
  --success-bg: #ecfdf3;
  --success-border: #bbf7d0;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --max-width: 1300px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 2rem 1rem;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 240px);
}

.exercise-container,
.status-bar,
.actions {
  width: min(100%, var(--max-width));
  margin-left: auto;
  margin-right: auto;
}

.exercise-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.15;
  margin-top: 0;
  margin-bottom: 1rem;
  color: #0f172a;
}

h2 {
  font-size: 1.2rem;
  margin-top: 0;
  color: #12315f;
}

p {
  margin-top: 0;
}

ul,
ol {
  padding-left: 1.4rem;
}

li + li {
  margin-top: 0.35rem;
}

code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.95em;
  background: #eaf2ff;
  color: #11315f;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.instructions {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.editor-panel,
.preview-panel {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

#editor {
  min-height: 460px;
  border: 1px solid #1e293b;
  border-radius: 12px;
  overflow: hidden;
}

#preview {
  width: 100%;
  min-height: 460px;
  border: 1px solid #c7d2e0;
  border-radius: 12px;
  background: #ffffff;
}

.cm-editor {
  height: 460px;
  font-size: 15px;
}

.cm-scroller {
  overflow: auto;
}

.status-bar {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
  border-radius: 10px;
  font-size: 0.95rem;
}

.actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.2rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

button.primary {
  background: var(--primary);
  color: #fff;
}

button.primary:hover,
button.primary:focus {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--secondary);
  color: #fff;
}

button.secondary:hover,
button.secondary:focus {
  background: var(--secondary-dark);
  transform: translateY(-1px);
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.back-link:hover,
.back-link:focus {
  color: var(--primary-dark);
}

@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: 1rem 0.75rem;
  }

  .exercise-container {
    padding: 1rem;
  }

  .actions {
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  #editor,
  #preview,
  .cm-editor {
    min-height: 360px;
    height: 360px;
  }
}
