:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #142033;
  --muted: #637083;
  --border: #c8d3e2;
  --primary: #2357c4;
  --primary-dark: #174199;
  --success: #187845;
  --danger: #b42318;
  --warning: #7a4a00;
  --panel-shadow: 0 1px 2px rgba(20, 32, 51, 0.04);
  --shadow: 0 14px 34px rgba(20, 32, 51, 0.08);
  --radius: 8px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: linear-gradient(180deg, #f7f9fc 0%, var(--bg) 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

p,
li,
dd,
dt,
button,
input,
textarea {
  overflow-wrap: anywhere;
}

button {
  cursor: pointer;
}

.container {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  padding: 44px 0 24px;
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: center;
  min-width: 0;
}

.header-card {
  display: grid;
  gap: 6px;
  min-height: 88px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.header-card span {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

h1 {
  font-size: 3.1rem;
  letter-spacing: 0;
}

h2 {
  font-size: 2rem;
}

h3 {
  font-size: 1.15rem;
}

.intro {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.app-shell {
  padding: 12px 0 56px;
}

.screen {
  animation: appear 0.18s ease-out;
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--panel-shadow);
  padding: 20px;
  min-width: 0;
}

#login-screen {
  max-width: 680px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

label {
  font-weight: 750;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

input {
  min-height: 46px;
  padding: 0 14px;
}

textarea {
  min-height: 360px;
  max-height: 70vh;
  resize: vertical;
  padding: 14px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  tab-size: 2;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(35, 87, 196, 0.12);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(20, 32, 51, 0.11);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

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

.button.primary:hover {
  background: var(--primary-dark);
}

.button.success {
  border-color: var(--success);
  background: var(--success);
  color: #ffffff;
}

.button.danger {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
}

.button.compact {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.9rem;
}

.button-row,
.topline {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.topline {
  justify-content: space-between;
}

.compact-row {
  justify-content: flex-end;
}

.message {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.message.error,
.result-box.error {
  color: var(--danger);
}

.message.ok,
.result-box.ok {
  color: var(--success);
}

.progress-wrap {
  margin-top: 18px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
  flex-wrap: wrap;
}

.progress-bar {
  overflow: hidden;
  height: 12px;
  margin-top: 8px;
  border-radius: 999px;
  background: #d8e0ec;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.2s ease;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.1fr) minmax(0, 1.1fr);
  grid-template-areas:
    "instructions editor preview"
    "checks checks checks";
  gap: 16px;
  margin-top: 18px;
  min-width: 0;
  align-items: start;
}

.instructions-panel,
.checks-panel,
.final-panel {
  align-self: start;
}

.instructions-panel {
  grid-area: instructions;
}

.editor-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-panel {
  grid-area: editor;
}

.preview-panel {
  grid-area: preview;
}

.checks-panel {
  grid-area: checks;
}

.goal-text {
  color: var(--muted);
  line-height: 1.6;
}

.requirements-list,
.checks-list {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding-left: 20px;
}

.requirements-list li {
  line-height: 1.45;
}

.tips-box {
  margin-top: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface-soft);
}

.tips-box summary {
  cursor: pointer;
  font-weight: 850;
}

.tips-box ul {
  margin-bottom: 0;
}

.result-box {
  min-height: 1.4em;
  margin-top: 18px;
  font-weight: 850;
}

.editor-heading,
.preview-heading {
  min-height: 42px;
  margin-bottom: 12px;
}

.editor-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(240px, 100%);
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.tab {
  min-height: 34px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.tab.active {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(20, 32, 51, 0.10);
}

.editor-wrap label {
  display: inline-block;
  margin-bottom: 8px;
}

.editor-wrap {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.editor-wrap textarea {
  flex: 1;
}

.editor-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  margin-top: 14px;
  justify-content: flex-end;
}

#preview-frame {
  display: block;
  width: 100%;
  flex: 1;
  height: 452px;
  min-height: 452px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
}

.meta {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
}

.checks-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-left: 0;
  list-style: none;
}

.check-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.check-icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  background: #d8e0ec;
  color: var(--muted);
  font-weight: 900;
}

.check-item.pass .check-icon {
  background: rgba(24, 120, 69, 0.13);
  color: var(--success);
}

.check-item.fail .check-icon {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

.check-title {
  display: block;
  font-weight: 900;
}

.check-detail {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.45;
}

.final-panel {
  margin-top: 18px;
  border-color: rgba(24, 120, 69, 0.4);
}

.summary-list {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.summary-list div {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.summary-list dt {
  color: var(--muted);
  font-weight: 850;
}

.summary-list dd {
  margin: 0;
  font-weight: 850;
}

.final-code {
  display: inline-block;
  padding: 8px 12px;
  max-width: 100%;
  border-radius: var(--radius);
  background: #e8f3ee;
  color: var(--success);
  font-family: "SFMono-Regular", Consolas, monospace;
  overflow-wrap: anywhere;
}

.warning {
  padding: 12px 14px;
  border: 1px solid rgba(122, 74, 0, 0.28);
  border-radius: var(--radius);
  background: #fff8e7;
  color: var(--warning);
  font-weight: 700;
}

.teacher-content {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.teacher-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 16px;
}

.teacher-card h3 {
  margin-bottom: 8px;
}

.teacher-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.teacher-card div {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px;
}

.teacher-card dt {
  color: var(--muted);
  font-weight: 850;
}

.teacher-card dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.teacher-card pre {
  margin: 0;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.teacher-card code {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 7px;
  background: #e8edf6;
}

#help-dialog {
  max-width: 620px;
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

#help-dialog::backdrop {
  background: rgba(20, 32, 51, 0.42);
}

.dialog-box {
  padding: 24px;
}

.dialog-box ol {
  line-height: 1.7;
}

@media (max-width: 920px) {
  .header-grid,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .workspace-grid {
    grid-template-areas:
      "instructions"
      "editor"
      "preview"
      "checks";
  }

  .header-card {
    min-width: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .button-row .button,
  .compact-row .button {
    width: auto;
  }

  .summary-list div,
  .teacher-card div {
    grid-template-columns: 1fr;
  }

  .checks-list {
    grid-template-columns: 1fr;
  }

  #preview-frame {
    height: 420px;
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .container {
    width: min(100% - 20px, 1240px);
  }

  .site-header {
    padding: 28px 0 16px;
  }

  h1 {
    font-size: 2.15rem;
  }

  h2 {
    font-size: 1.55rem;
  }

  .panel {
    padding: 16px;
  }

  textarea {
    min-height: 300px;
  }

  #preview-frame {
    height: 380px;
    min-height: 380px;
  }

  .button-row,
  .topline {
    align-items: stretch;
  }

  .topline {
    flex-direction: column;
  }

  .compact-row {
    width: 100%;
  }

  .button-row .button,
  .compact-row .button {
    width: 100%;
  }

  .editor-actions {
    grid-template-columns: 1fr;
  }
}
