/* ============================================================
   RADIST · REALMS — shared design system
   Ukrainian-first science simulators. Dark, lime, kid-serious.
   Matches the radist prototype palette (task_validate / browser).
   ============================================================ */

:root {
  /* palette */
  --bg:        #0b0b0c;
  --bg-soft:   #111113;
  --card:      #161618;
  --card-2:    #1d1d20;
  --line:      #2a2a2e;
  --line-2:    #36363c;
  --ink:       #f2f2f0;
  --muted:     #9a9aa0;
  --faint:     #6a6a70;
  --lime:      #c8ff39;
  --lime-dim:  #9fcb2e;
  --lime-ink:  #0b0b0c;
  --good:      #57e08a;
  --bad:       #ff6b6b;
  --warn:      #ffd166;
  --info:      #5ec8ff;

  /* domain accents (overridable per realm via --accent) */
  --accent:    var(--lime);

  /* type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, monospace;

  /* metrics */
  --dock-w: 380px;
  --r: 14px;
  --r-sm: 9px;
  --pad: 18px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell layout ---------- */
.realm {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

.realm-top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.realm-back {
  display: inline-flex; align-items: center; gap: 7px;
  text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-weight: 600; font-size: 13px;
  transition: border-color .15s, transform .05s;
  white-space: nowrap;
}
.realm-back:hover { border-color: var(--accent); }
.realm-back:active { transform: translateY(1px); }

.realm-badges { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.realm-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 4px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  text-transform: uppercase;
}
.realm-badge--grade {
  background: var(--card); color: var(--muted);
  border-color: var(--line-2); text-transform: none; letter-spacing: 0;
}

.realm-titlewrap { display: flex; flex-direction: column; min-width: 0; }
.realm-title { font-size: 16px; font-weight: 800; line-height: 1.15; }
.realm-subtitle { font-size: 12px; color: var(--muted); line-height: 1.1; }

.realm-top-spacer { flex: 1; }

.realm-iconbtn {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 9px; color: var(--ink); cursor: pointer; font-size: 16px;
  transition: border-color .15s;
}
.realm-iconbtn:hover { border-color: var(--accent); }

/* ---------- body: stage + dock ---------- */
.realm-body {
  display: grid;
  grid-template-columns: 1fr var(--dock-w);
  min-height: 0;
}
.realm-stage {
  position: relative;
  min-height: 0; min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 30% -10%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 60%),
    var(--bg);
  display: flex; align-items: stretch; justify-content: stretch;
}
.realm-stage canvas, .realm-stage svg { display: block; }
.realm-stage > * { width: 100%; height: 100%; }

/* floating stage controls (top-left of stage) */
.realm-stagebar {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  pointer-events: none;
}
.realm-stagebar > * { pointer-events: auto; }

/* ---------- dock ---------- */
.realm-dock {
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  display: grid; grid-template-rows: auto 1fr auto;
  min-height: 0;
}
.realm-dock-head {
  padding: 14px var(--pad) 10px;
  border-bottom: 1px solid var(--line);
}
.realm-dock-kicker {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: var(--faint); text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
}
.realm-dock-body {
  padding: var(--pad);
  overflow-y: auto;
  min-height: 0;
}
.realm-dock-foot {
  padding: 12px var(--pad);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

/* progress */
.realm-progress { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.realm-progress-bar {
  height: 7px; border-radius: 999px; background: var(--card-2);
  overflow: hidden; border: 1px solid var(--line);
}
.realm-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #fff));
  transition: width .35s cubic-bezier(.2,.8,.2,1);
}
.realm-progress-label { font-size: 12px; color: var(--muted); }
.realm-progress-label b { color: var(--ink); }

/* task card */
.realm-tasknum {
  font-size: 12px; font-weight: 700; color: var(--accent);
  letter-spacing: .04em; margin-bottom: 6px;
}
.realm-task {
  font-size: 16px; line-height: 1.45; color: var(--ink); font-weight: 500;
}
.realm-task b, .realm-task strong { color: var(--accent); font-weight: 700; }
.realm-task code, .realm-formula {
  font-family: var(--mono); background: var(--card-2);
  padding: 1px 6px; border-radius: 6px; font-size: .92em;
  border: 1px solid var(--line);
}
.realm-hint {
  margin-top: 12px; font-size: 13.5px; line-height: 1.5; color: var(--muted);
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  padding: 10px 12px; border-radius: var(--r-sm);
  display: none;
}
.realm-hint.show { display: block; }
.realm-hint b { color: var(--ink); }

/* generic controls injected by a realm */
.realm-controls { margin-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.realm-field { display: flex; flex-direction: column; gap: 6px; }
.realm-field-row { display: flex; align-items: center; justify-content: space-between; }
.realm-field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.realm-field-val { font-family: var(--mono); font-size: 13px; color: var(--accent); font-weight: 700; }

input[type="range"].realm-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line); outline: none;
}
input[type="range"].realm-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
input[type="range"].realm-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg); cursor: pointer;
}

.realm-input, select.realm-select {
  background: var(--card); border: 1px solid var(--line-2);
  color: var(--ink); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: 14px; font-family: var(--font); width: 100%;
}
.realm-input:focus, select.realm-select:focus { border-color: var(--accent); }
.realm-input.realm-num { font-family: var(--mono); }

/* buttons */
.rbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--card);
  color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer;
  transition: transform .05s, border-color .15s, background .15s;
}
.rbtn:hover { border-color: var(--accent); }
.rbtn:active { transform: translateY(1px); }
.rbtn:disabled { opacity: .45; cursor: not-allowed; }
.rbtn--primary {
  background: var(--accent); color: var(--lime-ink); border-color: var(--accent);
}
.rbtn--primary:hover { background: color-mix(in srgb, var(--accent) 85%, #fff); }
.rbtn--ghost { background: transparent; }
.rbtn--chip { padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.rbtn--block { width: 100%; }

.realm-btnrow { display: flex; gap: 10px; margin-top: 4px; }
.realm-btnrow .rbtn { flex: 1; }

/* feedback */
.realm-feedback {
  margin-top: 12px; padding: 11px 13px; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; line-height: 1.4;
  display: none; align-items: flex-start; gap: 9px;
}
.realm-feedback.show { display: flex; }
.realm-feedback--good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); border: 1px solid color-mix(in srgb, var(--good) 40%, transparent); }
.realm-feedback--bad  { background: color-mix(in srgb, var(--bad) 12%, transparent);  color: var(--bad);  border: 1px solid color-mix(in srgb, var(--bad) 38%, transparent); }
.realm-feedback--info { background: color-mix(in srgb, var(--info) 12%, transparent); color: var(--info); border: 1px solid color-mix(in srgb, var(--info) 36%, transparent); }

/* readouts / data panels on the stage */
.realm-readout {
  background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px; font-family: var(--mono); font-size: 12.5px;
  color: var(--ink); line-height: 1.6;
}
.realm-readout .k { color: var(--muted); }
.realm-readout .v { color: var(--accent); font-weight: 700; }

/* solved chip */
.realm-solved-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; color: var(--good);
}

/* help overlay */
.realm-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6,6,8,.74); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.realm-overlay.show { display: flex; }
.realm-modal {
  background: var(--card); border: 1px solid var(--line-2);
  border-radius: var(--r); padding: 22px 24px; max-width: 460px; width: 100%;
  box-shadow: var(--shadow);
}
.realm-modal h3 { margin: 0 0 12px; font-size: 17px; }
.realm-keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13.5px; }
.realm-keys kbd {
  font-family: var(--mono); background: var(--card-2); border: 1px solid var(--line-2);
  border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px; font-size: 12px; color: var(--ink);
  justify-self: start;
}
.realm-keys .d { color: var(--muted); align-self: center; }

/* toast */
.realm-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--card); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 11px 20px; font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 120;
}
.realm-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.realm-toast--good { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, var(--line-2)); }
.realm-toast--bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 45%, var(--line-2)); }

/* small helpers */
.realm-sep { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.realm-muted { color: var(--muted); }
.realm-small { font-size: 12.5px; }
.realm-tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--card-2); border: 1px solid var(--line-2); color: var(--muted);
}

/* loading splash for heavy (3D) realms */
.realm-loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 50; color: var(--muted); font-size: 14px;
  transition: opacity .4s; text-align: center;
}
.realm-loading.hide { opacity: 0; pointer-events: none; }
.realm-spin {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  border-radius: 50%; animation: realm-spin 0.8s linear infinite;
}
@keyframes realm-spin { to { transform: rotate(360deg); } }

/* ---------- responsive: dock becomes bottom sheet ---------- */
@media (max-width: 860px) {
  :root { --dock-w: 100%; }
  .realm-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .realm-dock {
    border-left: 0; border-top: 1px solid var(--line);
    max-height: 46vh;
  }
  .realm-title { font-size: 15px; }
  .realm-subtitle { display: none; }
}
