:root {
  color-scheme: dark;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #e8edf4;
  background: #111925;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --bg: #111925;
  --panel: #1a2533;
  --muted: #8290a0;
  --line: #2b3745;
  --mint: #72ebbb;
  --orange: #ffbf75;
  --mono: Consolas, "Cascadia Code", monospace;
}

* { box-sizing: border-box; }
body { min-width: 350px; min-height: 100vh; margin: 0; background: var(--bg); }
button, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  height: 62px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #2b3745;
  background: #151f2b;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: #edf3f6; font-size: 18px; font-weight: 700; letter-spacing: -.7px; text-decoration: none; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid #41665e; border-radius: 8px; color: var(--mint); background: #243b39; font: 500 12px var(--mono); }
.course-label, .topbar-right, .eyebrow, .world-coordinates, .world-legend, .kit-label { font: 500 10px var(--mono); letter-spacing: 1px; }
.course-label { margin-left: 38px; color: #9ba9b8; }
.course-dot { display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; background: var(--mint); vertical-align: 1px; }
.slash { padding: 0 6px; color: #526072; }
.topbar-right { margin-left: auto; color: #778594; }

.workspace { min-height: calc(100vh - 62px); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.world-side { min-width: 0; min-height: calc(100vh - 62px); padding: clamp(25px, 4vh, 44px) clamp(24px, 4vw, 62px) 26px; display: flex; flex-direction: column; border-right: 1px solid #34404d; background: radial-gradient(ellipse at 45% 48%, rgb(50 82 72 / 14%), transparent 52%), #131d29; }
.world-panel { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.world-heading { display: flex; align-items: end; justify-content: space-between; gap: 15px; }
.eyebrow { color: var(--mint); }
.eyebrow-line { display: inline-block; width: 19px; height: 1px; margin: 0 8px 3px 0; background: var(--mint); }
.world-heading h1, .editor-heading h2 { margin: 9px 0 0; color: #eff3f5; font-size: clamp(24px, 2.8vw, 36px); font-weight: 600; letter-spacing: -1.5px; }
.world-coordinates { padding-bottom: 6px; color: #7c8997; font-size: 9px; white-space: nowrap; }
.world-instructions { margin: 10px 0 0; color: #9daab8; font-size: 13px; line-height: 1.5; }
.board-wrap { min-height: 0; flex: 1; padding: 24px 0; display: grid; place-items: center; }
.game-board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: clamp(4px, .65vw, 8px); width: min(100%, 550px); }
.tile { position: relative; display: grid; aspect-ratio: 1.18; place-items: center; overflow: hidden; border: 1px solid #30433f; border-radius: 8px; background: linear-gradient(145deg, #273a39, #253733); }
.tile::after { position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(135deg, rgb(255 255 255 / 3%), transparent 55%); content: ""; pointer-events: none; }
.tile:nth-child(16n + 2), .tile:nth-child(16n + 4), .tile:nth-child(16n + 6), .tile:nth-child(16n + 8), .tile:nth-child(16n + 9), .tile:nth-child(16n + 11), .tile:nth-child(16n + 13), .tile:nth-child(16n + 15) { background: linear-gradient(145deg, #293c3a, #263834); }
.tile.rock { border-color: #47505a; background: linear-gradient(145deg, #3e464d, #313a43); }
.tile.rock::before { width: 55%; height: 42%; border: 1px solid #68737d; border-radius: 7px 8px 10px 7px; background: linear-gradient(145deg, #68717a, #48515c); box-shadow: 0 4px 0 #252e36; clip-path: polygon(18% 0, 78% 0, 100% 30%, 87% 100%, 8% 92%, 0 35%); content: ""; }
.tile.goal { border-color: #75634a; background: linear-gradient(145deg, #3d3b32, #34372f); }
.goal-mark { z-index: 1; color: #ffd58b; font-size: clamp(20px, 3.2vw, 32px); line-height: 1; text-shadow: 0 0 14px rgb(255 198 109 / 68%); animation: beacon-glow 2s ease-in-out infinite; }
.tile.hero::before { position: absolute; width: 65%; height: 65%; border-radius: 50%; background: rgb(114 235 187 / 15%); box-shadow: 0 0 17px 6px rgb(114 235 187 / 20%); content: ""; }
.hero-mark { z-index: 1; display: grid; width: 42%; height: 48%; place-items: center; border: 2px solid #d0f8e4; border-radius: 48% 48% 42% 42%; color: #154334; background: linear-gradient(#a5f4cf, #54d9a5); box-shadow: 0 4px 0 #2ca979; font: 700 clamp(10px, 1.6vw, 16px) var(--mono); transition: transform .18s; }
.tile.hero[data-facing="east"] .hero-mark { transform: rotate(90deg); }
.tile.hero[data-facing="south"] .hero-mark { transform: rotate(180deg); }
.tile.hero[data-facing="west"] .hero-mark { transform: rotate(-90deg); }
.game-status { min-height: 42px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid #34443f; border-radius: 7px; color: #b8c9c3; background: #202f31; font-size: 11px; }
.status-icon { color: var(--mint); font-size: 11px; }
.game-status.is-won { border-color: #587b53; color: #d6f3c6; background: #253c32; }
.game-status.is-won .status-icon { color: #a5ea72; }
.game-status.is-failed { border-color: #79504d; color: #f0c6b9; background: #3a2b30; }
.game-status.is-failed .status-icon { color: #ff967e; }
.game-status.is-error { border-color: #785a3b; color: #f2d4aa; background: #392f2a; }
.game-status.is-error .status-icon { color: var(--orange); }
.world-footer { min-height: 75px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.world-legend { display: flex; align-items: center; gap: 16px; color: #8c9aab; font-size: 9px; }
.world-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-hero { display: grid; width: 15px; height: 15px; place-items: center; border-radius: 50%; color: #153a2c; background: #8deac1; font: 10px var(--mono); }
.legend-wall { width: 13px; height: 11px; border: 1px solid #75808b; border-radius: 3px; background: #4c5660; }
.legend-goal { color: #ffd58b; font-size: 14px; }
.world-actions { min-width: 138px; display: flex; align-items: center; gap: 10px; }
.progress-track { height: 5px; flex: 1; overflow: hidden; border-radius: 5px; background: #35414a; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--mint); transition: width .2s; }
.run-button, .reset-button { width: 42px; height: 42px; display: grid; flex: 0 0 42px; place-items: center; border-radius: 8px; cursor: pointer; }
.run-button { border: 0; color: #14261f; background: var(--mint); transition: filter .18s, transform .18s; }
.run-button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.run-button:disabled { opacity: .58; cursor: wait; transform: none; }
.play-icon { font-size: 15px; }
.reset-button { border: 1px solid #3b4857; color: #aab5c1; background: transparent; font-size: 22px; }
.reset-button:hover { border-color: #788696; color: #eef3f7; }
.dpad { width: 128px; margin-top: 9px; display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 35px); justify-content: center; align-content: center; gap: 4px; }
.dpad button { border: 1px solid #3c4b58; border-radius: 7px; color: #c6d5d7; background: #202d38; font-size: 16px; cursor: pointer; }
.dpad button:hover { border-color: #5b927b; color: var(--mint); background: #263a39; }
.dpad button[data-step="north"] { grid-column: 2; grid-row: 1; }
.dpad button[data-step="west"] { grid-column: 1; grid-row: 2; }
.dpad span { display: grid; grid-column: 2; grid-row: 2; place-items: center; color: #536172; }
.dpad button[data-step="east"] { grid-column: 3; grid-row: 2; }
.dpad button[data-step="south"] { grid-column: 2; grid-row: 3; }

.editor-side { position: relative; min-width: 0; min-height: calc(100vh - 62px); padding: clamp(25px, 4vh, 44px) clamp(24px, 4vw, 62px) 24px; display: flex; flex-direction: column; background: #182330; }
.editor-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.editor-heading h2 { font-size: clamp(29px, 3.5vw, 43px); }
.hints-button { min-height: 38px; padding: 0 13px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid #52624e; border-radius: 7px; color: #f4d29a; background: #302f2a; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; cursor: pointer; }
.hints-button:hover, .hints-button[aria-expanded="true"] { border-color: #94734d; background: #3a352d; }
.hint-popover { position: absolute; z-index: 2; top: 116px; right: clamp(24px, 4vw, 62px); width: min(290px, 70%); padding: 14px 16px; display: grid; gap: 6px; border: 1px solid #635744; border-radius: 9px; color: #d9c9ac; background: #302e29; box-shadow: 0 10px 28px rgb(0 0 0 / 30%); font-size: 12px; line-height: 1.5; }
.hint-popover[hidden] { display: none; }
.hint-popover strong { color: #f5d79e; }
.editor-help { margin: 20px 0 12px; color: #929faf; font-size: 12px; line-height: 1.5; }
.editor-wrap { min-height: 220px; flex: 1; padding: 14px 18px 14px 0; display: flex; overflow: auto; border: 1px solid #2d3a48; border-radius: 9px; background: #131d28; }
.line-numbers { min-width: 50px; margin: 0; padding: 0 13px 0 0; color: #5a6879; text-align: right; user-select: none; font: 13px/27px var(--mono); white-space: pre; }
#program { width: 100%; min-height: 190px; padding: 0; resize: none; outline: none; border: 0; color: #cfe6db; background: transparent; caret-color: var(--mint); font: 13px/27px var(--mono); tab-size: 2; white-space: pre; }
#program::placeholder { color: #617181; }
#program::selection { color: #ecf8f3; background: #285c4a; }
.command-kit { min-height: 60px; padding: 13px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kit-label { margin-right: 4px; color: #718092; font-size: 9px; }
.command-chip { padding: 7px 10px; border: 1px solid #354354; border-radius: 5px; color: #b4c4d0; background: #202c39; font: 11px var(--mono); cursor: pointer; transition: border-color .16s, color .16s, background .16s; }
.command-chip:hover { border-color: #568575; color: var(--mint); background: #233932; }
.editor-note { min-height: 43px; padding-top: 12px; display: flex; align-items: center; gap: 8px; border-top: 1px solid #2b3745; color: #778798; font-size: 11px; }
.note-mark { width: 15px; height: 15px; display: inline-grid; place-items: center; border: 1px solid #556577; border-radius: 50%; color: #a6b4c1; font: 10px var(--mono); }

@keyframes beacon-glow { 50% { opacity: .68; transform: scale(.91); } }
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .world-side, .editor-side { padding-right: 24px; padding-left: 24px; }
  .world-legend { gap: 10px; }
  .world-legend, .kit-label { font-size: 8px; }
}
@media (max-width: 680px) {
  .topbar { height: 56px; padding: 0 16px; }
  .course-label { margin-left: 17px; font-size: 8px; }
  .topbar-right { font-size: 8px; }
  .workspace { min-height: calc(100vh - 56px); grid-template-columns: 1fr; }
  .world-side { min-height: 65vh; padding: 23px 19px 16px; border-right: 0; border-bottom: 1px solid #34404d; }
  .editor-side { min-height: 70vh; padding: 25px 19px 18px; }
  .world-heading h1 { font-size: 27px; }
  .board-wrap { min-height: 220px; padding: 18px 0; }
  .game-board { width: min(100%, 470px); gap: 4px; }
  .tile { aspect-ratio: 1.12; border-radius: 5px; }
  .world-footer { min-height: 59px; }
  .world-actions { min-width: 104px; gap: 7px; }
  .run-button, .reset-button { width: 36px; height: 36px; flex-basis: 36px; }
  .dpad { width: 118px; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 31px); }
  .editor-wrap { min-height: 250px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
