:root {
  --page-bg: #08090d;
  --card-bg: #12131a;
  --text: #e2e5ee;
  --text-title: #fafbfd;
  --text-sub: #c9ccd9;
  --text-dim: #989baa;
  --text-label: #868a9a;
  --sep: #262935;
  --border: #292c3a;
  --btn-bg: #1a1c26;
  --btn-border: #373b4c;
  --green: #5adc8c;
  --red: #ff6e6e;
  --cyan: #50c8ff;
  --facing: #50c8ff;
  --amber: #ffba52;
  --ctrl-move: #ff9430;
  --ctrl-interact: #ff60c8;
  --grid-border: #80859e;
  --rail: 230px;
  --grid: 640px;
}

* { box-sizing: border-box; }

.play-host {
  position: relative;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  outline: none;
}

.play-host:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 90, 156, 0.35);
  border-radius: 22px;
}

.play-host .card,
.play-host #end .panel {
  color: var(--text);
}

/* Keep player chrome independent of any site-wide CSS. */
.play-host .card h1,
.play-host .card h2,
.play-host .card p,
.play-host .card ul,
.play-host .card li,
.play-host .card button,
.play-host #end h2,
.play-host #end p,
.play-host #end td,
.play-host #end th,
.play-host #end button,
.play-host #end .play-download {
  margin: 0;
  padding: 0;
  font: inherit;
  line-height: inherit;
  list-style: none;
  background: none;
  border: none;
}

.play-host #error,
#play-the-maze #error {
  display: none;
  max-width: 40rem;
  padding: 1.5rem;
  white-space: pre-wrap;
  color: var(--red);
}

.play-host .card {
  display: none;
  width: max-content;
  max-width: 100%;
  background: var(--card-bg);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.play-host .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--sep);
}

.play-host .brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-title);
}

.play-host .task-id {
  color: var(--text-sub);
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 2px;
}

.play-host .nav {
  display: flex;
  gap: 8px;
}

.play-host .nav button,
.play-host .ctrl button,
.play-host #splash-play,
.play-host .end-actions button {
  font: inherit;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.play-host .nav button:hover,
.play-host .ctrl button:hover,
.play-host #splash-play:hover {
  border-color: var(--text-dim);
}

.play-host .board {
  display: grid;
  grid-template-columns: var(--rail) var(--grid) var(--rail);
  /* Row height is the maze — rails must not grow the card. */
  grid-template-rows: var(--grid);
  align-items: stretch;
}

.play-host .rail {
  padding: 18px 16px;
  border-right: 1px solid var(--sep);
  font-size: 0.9rem;
  min-width: 0;
  width: var(--rail);
  height: 100%;
  max-height: var(--grid);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.play-host .rail.right {
  border-right: 0;
  border-left: 1px solid var(--sep);
}

.play-host .section {
  letter-spacing: 0.18em;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-title);
  margin: 0 0 12px;
  text-transform: uppercase;
}

.play-host .section.muted {
  color: var(--text);
}

.play-host .rail p#task-text {
  margin: 0 0 10px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.play-host .stat {
  margin: 0 0 14px;
}

.play-host .stat .stat-label {
  display: block;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.play-host .stat .stat-value {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 1.4rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-title);
  line-height: 1.3;
}

.play-host .stat.facing .stat-value { color: var(--facing); }

.play-host .facing-icon {
  display: inline-block;
  font-size: 1.1rem;
  line-height: 1;
}

/* Avoid Bulma .icon / .progress collisions on the R1 page. */
.play-host .play-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: inline-block;
  vertical-align: middle;
}

.play-host .play-icon.bullet {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin: 5px;
}

.play-host .play-progress {
  list-style: none;
  padding: 14px 0 0;
  margin: 14px 0 0;
  border-top: 1px solid var(--sep);
  /* Fill leftover left-rail height; scroll inside the card only. */
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  width: auto;
  display: block;
  appearance: none;
  -webkit-appearance: none;
  scrollbar-width: thin;
  scrollbar-color: #3a3f52 transparent;
}

.play-host .play-progress::-webkit-scrollbar {
  width: 6px;
}

.play-host .play-progress::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}

.play-host .play-progress::-webkit-scrollbar-thumb {
  background: #3a3f52;
  border-radius: 999px;
}

.play-host .play-progress::-webkit-scrollbar-thumb:hover {
  background: #52586e;
}

.play-host .play-progress li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.play-host .play-progress li .play-icon {
  margin-top: 2px;
}

.play-host .play-progress li .progress-text {
  min-width: 0;
}

.play-host .play-progress li .mech {
  font-weight: 700;
}

.play-host .play-progress .label {
  letter-spacing: 0.18em;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  margin-bottom: 12px;
  display: block;
}

.play-host .stage {
  position: relative;
  width: var(--grid);
  height: var(--grid);
  background: #0b0c11;
  overflow: hidden;
}

#grid {
  position: relative;
  z-index: 1;
  width: var(--grid);
  height: var(--grid);
  max-width: none;
  display: block;
  border: 4px solid var(--grid-border);
  image-rendering: pixelated;
  box-sizing: border-box;
  object-fit: fill;
  will-change: transform;
}

.play-host .fx-layer {
  position: absolute;
  inset: 4px; /* sit inside the grid border */
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

.play-host .fx-pulse {
  position: absolute;
  border-radius: 2px;
  background: rgba(90, 220, 140, 0);
  mix-blend-mode: screen;
  will-change: background-color;
}

.play-host .fx-cell {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
}

.play-host .fx-cell img {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: fill;
}

.play-host .fx-flash-white {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

.play-host .fx-cell.press {
  background: #12131a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-host .fx-cell.press img {
  width: 100%;
  height: 100%;
  transform-origin: center center;
}

.play-host .stat strong {
  color: var(--text-title);
}

.play-host .ctrl {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.play-host .ctrl button {
  display: grid;
  grid-template-columns: 3.4rem 1fr;
  column-gap: 10px;
  align-items: start;
  text-align: left;
  font-weight: 700;
}

.play-host .ctrl button .key {
  font-weight: 700;
  white-space: nowrap;
}

.play-host .ctrl button .desc {
  min-width: 0;
}

.play-host .ctrl button.move .key { color: var(--ctrl-move); }
.play-host .ctrl button.interact .key { color: var(--ctrl-interact); }
.play-host .ctrl button.meta .key { color: var(--text-dim); }
.play-host .ctrl button .desc { color: var(--text-sub); }

.play-host .nav button {
  min-width: 36px;
  font-weight: 700;
}

.play-host .hint {
  padding: 10px 18px 12px;
  border-top: 1px solid var(--sep);
  text-align: center;
}

.play-host .hint-main {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.play-host .hint-meta {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
}

.play-host #end .play-download,
.play-host .play-download {
  display: inline-block;
  margin: 14px auto 4px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-title);
  background: #1c1f2c;
  border: 1px solid #3a3f52;
  border-radius: 8px;
  cursor: pointer;
}

.play-host #end .play-download:hover,
.play-host .play-download:hover {
  border-color: #5a6280;
  background: #242838;
}

.play-host .play-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 9, 13, 0.82);
  box-sizing: border-box;
}

.play-host .play-overlay[hidden] {
  display: none !important;
}

.play-host .play-overlay-card {
  width: min(560px, 100%);
  max-height: min(520px, 90%);
  display: flex;
  flex-direction: column;
  background: rgba(22, 24, 34, 0.98);
  border: 1px solid #2e3344;
  border-left: 6px solid #4c7dff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.play-host .play-overlay-card.model {
  width: min(640px, 100%);
  border-left-color: #9b59ff;
}

.play-host .play-overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--sep);
}

.play-host .play-overlay-head h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-title);
}

.play-host .play-overlay-head button {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid #3a3f52;
  border-radius: 6px;
  cursor: pointer;
}

.play-host .play-overlay-body {
  padding: 12px 16px 18px;
  overflow: auto;
  min-height: 0;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: #3a3f52 transparent;
}

.play-host .play-overlay-help {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.play-host .settings-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 8px;
}

.play-host .settings-row.is-editable {
  cursor: pointer;
  padding: 4px 6px;
  margin-left: -6px;
  margin-right: -6px;
  border-radius: 6px;
}

.play-host .settings-row.is-editable:hover {
  background: rgba(76, 125, 255, 0.12);
}

.play-host .settings-key {
  flex: 0 0 auto;
  min-width: 1.6rem;
  padding: 2px 6px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #9db4ff;
  background: #151826;
  border: 1px solid #2f3a5c;
  border-radius: 5px;
}

.play-host .settings-attr {
  color: var(--text-sub);
  word-break: break-word;
}

.play-host .settings-attr strong {
  color: var(--text-title);
  font-weight: 700;
}

.play-host .overlay-section {
  margin: 0 0 14px;
}

.play-host .overlay-section h4 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #b39bff;
}

.play-host .overlay-section pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text);
  background: #12141c;
  border: 1px solid #2a2e3c;
  border-radius: 8px;
  padding: 10px 12px;
}

.play-host .manifest-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--sep);
}

.play-host .manifest-block h4 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #c9a0ff;
}

.play-host .manifest-block p {
  margin: 0 0 4px;
  color: var(--text-sub);
  font-size: 0.82rem;
}

#splash {
  display: none;
  position: relative;
  background: rgba(8, 9, 13, 0.92);
  place-items: center;
  z-index: 5;
  text-align: center;
  padding: 24px;
  border-radius: 20px;
  min-height: 420px;
  width: min(1100px, 96vw);
}

#splash.show {
  display: grid;
}

#splash h1 {
  margin: 0 0 12px;
  color: var(--text-title);
  font-size: clamp(2rem, 5vw, 3.4rem);
}

#splash p {
  margin: 0 0 10px;
  color: var(--text-sub);
}

#splash-play {
  margin-top: 28px;
  padding: 12px 22px;
  font-weight: 700;
}

#end {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  background: rgba(8, 9, 13, 0.82);
  padding: 28px;
  box-sizing: border-box;
}

#end.show {
  display: grid;
  place-items: center;
}

/* State is carried by a full accent-tinted border and a wash of the same
   colour, not a bar on one edge - the same idiom the site's cards use, and
   symmetric on all four sides. One variable, so the fail case is a colour
   swap rather than a second rule set. */
#end .panel {
  --state: var(--green);
  width: 100%;
  height: 100%;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--state) 12%, rgba(22, 24, 34, 0.98)) 0%,
      rgba(22, 24, 34, 0.98) 58%);
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--state) 42%, transparent);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--state) 22%, transparent),
    0 18px 44px rgba(0, 0, 0, 0.38);
  padding: 28px 32px;
  text-align: center;
  overflow: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#end.fail .panel {
  --state: var(--red);
}

#end h2 {
  margin: 0 0 14px;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#end.fail h2 { color: var(--red); }
#end.success h2 { color: var(--green); }

#end p {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
}

#end-diff {
  font-weight: 700;
}

#end-steps {
  color: var(--text-title) !important;
  font-weight: 700 !important;
}

#end-frame.good { color: var(--green) !important; }
#end-frame.neutral { color: var(--text-sub) !important; }

#end-score .score {
  font-weight: 700;
}

#end-score .score.hi { color: var(--green); }
#end-score .score.mid { color: var(--cyan); }
#end-score .score.low { color: var(--amber); }
#end-score .score.bad { color: var(--red); }

.play-host .compare {
  /* Two even columns, each centred over its own header, so the table reads
     as a pair of aligned lists rather than one ragged left edge. */
  width: min(100%, 460px);
  table-layout: fixed;
  border-collapse: collapse;
  margin: 14px auto 0;
  text-align: center;
}

.play-host .compare th {
  color: var(--text-label);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 0 0 8px;
  font-weight: 700;
}

.play-host .compare td {
  padding: 8px 0;
  border-top: 1px solid var(--sep);
  color: var(--text);
  font-weight: 700;
}

.play-host .compare .you {
  color: var(--green);
}

#end.fail .compare .you {
  color: var(--red);
}

.play-host .compare .fail-result {
  color: #ff8c8c;
}

.play-host .compare .ok-result {
  color: var(--green);
}

#end-hint {
  margin-top: 16px !important;
  color: var(--text-dim) !important;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
}

/* Scale down before the board can outgrow a 1200px-wide container. */
@media (max-width: 1200px) {
:root {
    --rail: 180px;
    --grid: 520px;
  }

  .play-host .rail,
  .play-host .ctrl button {
    font-size: 0.82rem;
  }
}

@media (max-width: 900px) {
:root {
    --rail: 150px;
    --grid: 420px;
  }
}

@media (max-width: 720px) {
.play-host .board {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

.play-host .rail {
    width: auto;
    height: auto;
    max-height: none;
    border: 0;
    border-bottom: 1px solid var(--sep);
  }

  .play-host .rail:not(.right) {
    max-height: min(280px, 50vh);
  }

.play-host .rail.right {
    border-left: 0;
  }

  .play-host .stage,
  .play-host #grid {
    width: min(var(--grid), 100%);
    height: auto;
    aspect-ratio: 1;
  }

  .play-host .stage {
    order: -1;
    justify-self: center;
  }
}
