:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --text: #2a2420;
  --muted: #6f655c;
  --border: #e3dbcf;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --error: #fca5a5;
  --code-bg: #1f1b18;
  --code-text: #f5efe6;
  /* Code colours. The editor is dark in both themes, so these don't change with it. */
  --tok-keyword: #fb923c;
  --tok-literal: #fcd34d;
  --tok-string: #86efac;
  --tok-number: #93c5fd;
  --tok-builtin: #f0abfc;
  --tok-comment: #9c8f82;
  --tok-punct: #fdba74;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #211d1a;
    --surface-2: #2a2521;
    --text: #efe8de;
    --muted: #a89d91;
    --border: #3a332d;
    --accent: #fb923c;
    --accent-text: #1a1310;
    --error: #fca5a5;
    --code-bg: #120f0d;
    --code-text: #efe8de;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.site-header {
  padding: 32px 0 20px;
}

h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

h2 {
  margin: 0;
  font-size: 1rem;
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-row > div { flex: 1 1 280px; }
#lesson-toggle { flex: none; }

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 36px;
  margin-bottom: 10px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

select, button {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status {
  color: var(--muted);
  font-size: 0.8rem;
}

button {
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

textarea, pre {
  flex: 1;
  min-height: 380px;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 14px/1.6 var(--mono);
  tab-size: 2;
}

textarea {
  resize: vertical;
  outline: none;
}
textarea:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

/* File tabs above the editor. */
.file-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}
.file-tab { display: inline-flex; }
.file-tab button, .file-add {
  font: 12px/1.4 var(--mono);
  padding: 4px 8px;
}
.file-tab button[aria-selected="true"] {
  background: var(--code-bg);
  border-color: var(--code-bg);
  color: var(--code-text);
}
.file-tab .file-close {
  margin-left: -1px;
  padding: 4px 6px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.file-tab button:first-child:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.file-add { color: var(--muted); border-style: dashed; }
.hint code { font-family: var(--mono); font-size: 0.95em; }

/* The coloured copy of the code sits exactly under the textarea, whose own text is
   transparent. Both use the same font, padding and no line wrapping, so they line up. */
.editor {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 380px;
}

.editor pre,
.editor textarea {
  font: 14px/1.6 var(--mono);
  padding: 12px;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  tab-size: 2;
}

.editor pre {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: hidden;
  pointer-events: none;
}

.editor textarea {
  position: relative;
  flex: 1;
  background: transparent;
  color: transparent;
  caret-color: var(--code-text);
  overflow: auto;
}

.editor textarea::selection { background: rgba(251, 146, 60, 0.35); color: transparent; }

.tok-keyword { color: var(--tok-keyword); font-weight: 600; }
.tok-literal { color: var(--tok-literal); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-builtin { color: var(--tok-builtin); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-punct { color: var(--tok-punct); }

pre {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* The output panel is dark in both themes. */
.error { color: var(--error); }

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

kbd {
  font: 0.75rem var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
}

/* Sikh (lessons) panel. */
.lesson { margin-bottom: 16px; }
.lesson-body p, .exercise p { margin: 0 0 8px; }
.lesson code, .exercise code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--accent);
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 4px;
}
.exercise {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.exercise h3 { margin: 0 0 6px; font-size: 0.95rem; }
.exercise .actions { margin: 10px 0 0; }
button:disabled { opacity: 0.45; cursor: default; }

.lesson-result p { margin: 10px 0 6px; font-weight: 600; }
.lesson-result.ok p { color: #15803d; }
.lesson-result.wrong p { color: var(--accent); }
.lesson-result pre {
  min-height: 0;
  margin: 0 0 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.lesson-result pre.want { border-left: 3px solid #22c55e; }
.lesson-result .label { display: block; font-size: 0.75rem; color: var(--muted); margin: 6px 0 2px; }
@media (prefers-color-scheme: dark) {
  .lesson-result.ok p { color: #4ade80; }
}

/* Console: the interactive prompt in the page. Dark like the editor. */
.console {
  margin-top: 16px;
  background: var(--code-bg);
  border-color: var(--code-bg);
}
.console h2 { color: var(--code-text); }

.console-log {
  max-height: 320px;
  overflow: auto;
  font: 14px/1.6 var(--mono);
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.console-in, .console-out, .console-result, .console-error, .console-note { min-height: 1.6em; }
.console-result { color: var(--tok-number); }
.console-error { color: var(--error); }
.console-note { color: var(--tok-comment); font-style: italic; }

.console-entry {
  display: flex;
  align-items: flex-start;
  gap: 0;
  border-top: 1px solid #3a332d;
  margin-top: 8px;
  padding-top: 8px;
}

.console-entry pre,
.console-entry textarea {
  flex: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  font: 14px/1.6 var(--mono);
  background: transparent;
  color: var(--code-text);
  white-space: pre;
}

.console-prompt { color: var(--tok-keyword); padding-right: 1ch; user-select: none; }
.console-entry .console-prompt { width: 11ch; color: var(--tok-keyword); }

.console-entry textarea {
  flex: 1;
  resize: none;
  overflow: hidden;
  caret-color: var(--tok-keyword);
}
.console-entry textarea:focus-visible { box-shadow: none; }
.console:focus-within { box-shadow: 0 0 0 2px var(--accent); }

.cheatsheet {
  margin: 24px 0 48px;
}

.cheatsheet h2 { margin-bottom: 10px; }
.cheatsheet .subhead { margin-top: 24px; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
}

tr:last-child td { border-bottom: 0; }

td code {
  font-family: var(--mono);
  color: var(--accent);
  white-space: nowrap;
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  textarea, pre, .editor { min-height: 260px; }
}
