
/* =========================================================
   PHYSICS PLAYGROUND
   Library and workspace for the maintained HTML labs.
   ========================================================= */

:root {
  color-scheme: dark;

  --bg: #101419;
  --panel: #171d24;
  --raised: #202832;
  --hover: #252f3a;
  --border: #303c49;

  --text: #edf1f5;
  --muted: #a9b5c2;
  --subtle: #8292a3;
  --accent: #e9b86a;
  --accent-ink: #241b0d;
  --cyan: #7bc9d2;
  --green: #a4cfb0;

  --radius: 14px;
  --rail-width: 244px;

  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-size: 15px;
  line-height: 1.55;
}

button, input, select {
  font: inherit;
}

button, a, input, select {
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }

a {
  color: inherit;
  text-decoration: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 4px;
}

button:disabled {
  cursor: default;
  opacity: .5;
}

[hidden] { display: none !important; }

::selection {
  background: #e9b86a;
  color: #101419;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 12px 18px;
  transform: translateY(-160%);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
}

.skip-link:focus { transform: translateY(0); }

button {
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 13px;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

button:hover { background: var(--hover); }

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

button.primary:hover {
  background: #f1c783;
  border-color: #f1c783;
}

button.quiet {
  background: transparent;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}

.muted { color: var(--muted); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------- Sidebar ---------------- */

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  padding: 26px 20px 20px;
  background: #131920;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-mark {
  width: 39px;
  height: 39px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid #6b5637;
  border-radius: 12px;
  color: var(--accent);
}

.brand-mark svg { width: 27px; height: 27px; }

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: -.025em;
}

.brand small {
  display: block;
  color: var(--subtle);
  font-size: 11px;
  letter-spacing: .05em;
}

.nav-label {
  margin: 25px 10px 9px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 3px 0;
  padding: 10px 11px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 9px;
  color: var(--muted);
  text-align: left;
  font-size: 13px;
}

.nav-item:hover {
  background: var(--raised);
  color: var(--text);
}

.nav-item.active {
  color: var(--accent);
  background: #29251e;
  border-color: #443a2b;
}

.nav-count {
  font-size: 11px;
  color: var(--subtle);
}

.recent-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.recent-item:hover {
  background: var(--raised);
  color: var(--text);
}

.rail-bottom {
  margin-top: auto;
  padding-top: 30px;
}

.passport {
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}

.passport-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.passport progress {
  display: block;
  width: 100%;
  height: 5px;
  margin: 12px 0 8px;
  border: 0;
  border-radius: 20px;
  overflow: hidden;
  accent-color: var(--accent);
}

progress::-webkit-progress-bar { background: var(--raised); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.passport small {
  color: var(--subtle);
  font-size: 10px;
}

.rail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.rail-footer button {
  padding: 5px 8px;
  font-size: 11px;
  color: var(--muted);
}

/* ---------------- Application header ---------------- */

.app {
  margin-left: var(--rail-width);
  min-width: 0;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 34px;
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.breadcrumb a:hover { color: var(--accent); }

.breadcrumb strong {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-note {
  font-size: 11px;
  color: var(--subtle);
  white-space: nowrap;
}

/* ---------------- Explore page ---------------- */

.explore {
  max-width: 1500px;
  margin: auto;
  padding: 42px 34px 56px;
}

.intro {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 28px;
  margin-bottom: 28px;
}

.intro h1 {
  margin: 10px 0 12px;
  font-size: clamp(30px, 3.6vw, 49px);
  line-height: 1.1;
  letter-spacing: -.055em;
  font-weight: 650;
}

.intro-copy {
  max-width: 590px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.continue-button {
  flex: 0 0 auto;
  max-width: 260px;
  text-align: left;
}

.continue-button small {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  opacity: .8;
}

.continue-button span {
  display: block;
  font-size: 13px;
}

/* Featured experiment */

.featured {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  min-height: 225px;
  margin: 32px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}

.featured-content {
  align-self: center;
  padding: 30px;
}

.featured h2 {
  margin: 9px 0;
  font-size: 27px;
  letter-spacing: -.04em;
  line-height: 1.2;
}

.featured p:not(.eyebrow) {
  margin: 0 0 20px;
  max-width: 420px;
  font-size: 13px;
  color: var(--muted);
}

.featured-art {
  min-height: 220px;
  position: relative;
  background: #111a22;
  overflow: hidden;
}

.featured-art svg {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  object-fit: cover;
}

/* Search and filters */

.library-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin: 32px 0 17px;
}

.library-tools h2 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -.025em;
}

.library-tools p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.search {
  position: relative;
  width: min(360px, 100%);
}

.search svg {
  position: absolute;
  width: 17px;
  height: 17px;
  left: 14px;
  top: 14px;
  color: var(--subtle);
  pointer-events: none;
}

.search input {
  width: 100%;
  min-height: 45px;
  padding: 10px 12px 10px 41px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.search input::placeholder { color: var(--subtle); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 22px;
}

.filter {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  background: transparent;
  color: var(--muted);
}

.filter[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

/* World cards */

.world-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.world-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  transition: transform 160ms ease, border-color 160ms ease;
}

.world-card:hover {
  transform: translateY(-3px);
  border-color: #566574;
}

.card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview {
  position: relative;
  height: 157px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: #111a22;
}

.preview svg {
  display: block;
  width: 100%;
  height: 100%;
}

.preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-label {
  position: absolute;
  left: 12px;
  bottom: 10px;
  color: #c5d1de;
  font-size: 8px;
  font-weight: 650;
  letter-spacing: .15em;
  text-transform: uppercase;
  background: #101419cc;
  padding: 3px 6px;
  border-radius: 4px;
}

.favorite {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: #101419e8;
  border-color: #46515e;
  font-size: 19px;
}

.favorite[aria-pressed="true"] {
  color: var(--accent);
  border-color: #8c7146;
}

.card-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 18px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 10px;
  color: var(--subtle);
}

.card-meta .visited { color: var(--green); }

.world-card h3 {
  margin: 0 0 7px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.025em;
}

.world-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  font-size: 10px;
  color: var(--subtle);
}

.card-open {
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty h3 { margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0 0 20px; }

.explore-footer {
  margin-top: 34px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--subtle);
  font-size: 11px;
}

/* ---------------- Lab workspace ---------------- */

.lab {
  padding: 24px;
}

.lab-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 19px;
}

.lab-heading h1 {
  margin: 5px 0 4px;
  font-size: clamp(23px, 2.5vw, 32px);
  line-height: 1.2;
  letter-spacing: -.04em;
}

.lab-heading p:not(.eyebrow) {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.world-select-wrap {
  flex: 0 0 auto;
  max-width: 270px;
}

.world-select-wrap label {
  display: block;
  margin-bottom: 5px;
  color: var(--subtle);
  font-size: 10px;
}

select {
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
}

.workspace {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.workspace-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.workspace-tools button {
  padding: 7px 10px;
  font-size: 11px;
}

.page-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.page-status[data-state="loaded"] .status-dot {
  background: var(--green);
}

.embed-stage {
  position: relative;
  min-height: 580px;
  height: max(580px, calc(100dvh - 270px));
  background: #080c11;
}

.embed-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #080c11;
}

.embed-stage:fullscreen {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
}

.loading {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: #101419;
}

.loading-ring {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading strong {
  display: block;
  margin-top: 18px;
  font-weight: 500;
  font-size: 15px;
}

.loading p {
  max-width: 390px;
  color: var(--muted);
  font-size: 12px;
}

.loading-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.workspace-foot {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--subtle);
  font-size: 10px;
}

.style-option {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.style-option input { accent-color: var(--accent); }

.guidance {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
  margin-top: 18px;
}

.guide-block {
  padding: 19px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.guide-block h2 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.guide-block p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.8;
}

/* ---------------- Dialog and notifications ---------------- */

dialog {
  width: min(540px, calc(100vw - 32px));
  padding: 26px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 100px #0008;
}

dialog::backdrop { background: #000a; }

dialog h2 {
  margin: 0 0 14px;
  font-size: 23px;
  letter-spacing: -.03em;
}

dialog p, dialog li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

dialog ul { padding-left: 20px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.toast {
  position: fixed;
  z-index: 100;
  left: calc(50% + var(--rail-width) / 2);
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 11px 18px;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  box-shadow: 0 8px 35px #0004;
  font-size: 12px;
}

/* ---------------- Responsive layout ---------------- */

@media (min-width: 1700px) {
  .world-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1200px) {
  :root { --rail-width: 215px; }
  .rail { padding-inline: 15px; }
  .world-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guidance { grid-template-columns: 1fr; }
  .guide-block { padding: 16px 19px; }
}

@media (max-width: 860px) {
  :root { --rail-width: 0px; }

  .rail {
    position: relative;
    width: 100%;
    height: auto;
    padding: 15px 20px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .brand { margin: 0; }
  .rail-navigation, .rail-recents, .passport { display: none; }
  .rail-bottom { margin: 0; padding: 0; }
  .rail-footer { margin: 0; }
  .rail-footer .reset-progress { display: none; }
  .app { margin: 0; }

  .topbar { min-height: 54px; padding: 12px 20px; }
  .explore { padding: 30px 20px 40px; }
  .lab { padding: 20px; }

  .intro { align-items: flex-start; }
  .intro-copy { font-size: 14px; }
  .featured-content { padding: 24px; }
  .featured { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 580px) {
  .brand strong { font-size: 14px; }
  .brand-mark { width: 34px; height: 34px; }
  .topbar-note { display: none; }

  .intro { display: block; }
  .continue-button { margin-top: 20px; max-width: none; }

  .featured { grid-template-columns: 1fr; }
  .featured-art { min-height: 150px; order: -1; }
  .featured h2 { font-size: 24px; }

  .library-tools {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .search { width: 100%; }
  .world-grid { grid-template-columns: 1fr; }
  .preview { height: 175px; }

  .lab { padding: 16px 12px; }
  .lab-heading { align-items: stretch; flex-direction: column; }
  .world-select-wrap { max-width: none; }
  .world-select-wrap select { width: 100%; }

  .embed-stage {
    height: 72dvh;
    min-height: 500px;
  }

  .workspace-tools { padding: 10px; }
  .page-status { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

.page-status[data-state="error"] .status-dot { background: #f38b9c; }
