:root {
  --bg: #0e1116;
  --panel: #151a21;
  --border: #29313c;
  --text: #e4eaf0;
  --muted: #93a1b0;
  --teal: #2dd4bf;
  --amber: #f5a524;
  --rose: #fb7185;
  --sky: #60a5fa;
  --ui: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d5dce3;
  --text: #17202b;
  --muted: #5b6977;
  --teal: #0f9f8f;
  --amber: #c7780a;
  --rose: #d9465f;
  --sky: #2f7fd6;
  --shadow: 0 8px 24px rgba(23, 32, 43, 0.14);
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
kbd {
  font: 600 11px var(--mono);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--muted);
  background: var(--bg);
}

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 5;
  pointer-events: none;
}
.card {
  pointer-events: auto;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
}
.card h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.card h1::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  margin-right: 8px;
  vertical-align: 1px;
}
.sub {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 12.5px;
}
.row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}
.speed {
  font-family: var(--mono);
  color: var(--text);
}
.speed span {
  font-size: 26px;
  font-weight: 600;
  display: inline-block;
  min-width: 2.2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.speed small {
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
}
.actions {
  display: flex;
  gap: 6px;
}
.btn {
  font: 600 12.5px var(--ui);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.3;
}
.btn:hover {
  border-color: var(--muted);
}
.btn:focus-visible,
#open:focus-visible,
#items a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
#skip {
  border-color: color-mix(in srgb, var(--amber) 60%, var(--border));
}

.help {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  color: var(--muted);
  font-size: 12.5px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  gap: 4px;
  align-items: center;
}
.help kbd {
  margin-right: 0;
}
.msg {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 5;
  max-width: min(360px, calc(100vw - 24px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--amber);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
}
.msg[hidden] {
  display: none;
}

.prompt {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 44px);
  transform: translateX(-50%);
  z-index: 6;
  width: max-content;
  max-width: calc(100vw - 24px);
}
.prompt[hidden] {
  display: none;
}
.lt {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--border);
  border-left: 3px solid var(--amber);
  border-radius: 12px;
  padding: 10px 12px 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
  max-width: 100%;
}
.lt__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 11px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lt__cat {
  color: var(--text);
}
.lt__n {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lt__title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.lt__title b {
  font-weight: 700;
}
.lt__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lt__acts[hidden],
#studio[hidden] {
  display: none;
}
.lt .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}
#open {
  border-color: var(--amber);
}
.chip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  flex: none;
}

/* tour */
.btn-tour {
  border-color: color-mix(in srgb, var(--teal) 65%, var(--border));
}
.btn-tour[aria-pressed="true"] {
  background: var(--teal);
  color: #04201c;
  border-color: var(--teal);
}
.tourbar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--teal);
  border-radius: 999px;
  padding: 6px 8px 6px 16px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 24px);
}
.tourbar[hidden] {
  display: none;
}
.tourbar__n {
  font: 600 12px var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tourbar__t {
  color: var(--muted);
  font-size: 12.5px;
}
.tourbar .btn {
  white-space: nowrap;
  min-height: 36px;
  border-radius: 999px;
}
@media (max-width: 700px) {
  body.touring .hud {
    visibility: hidden;
  }
}
body.touch-ui .lt kbd {
  display: none;
}

/* minimap */
.mapwrap {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.mapwrap[hidden] {
  display: none;
}
.mini {
  display: block;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  box-shadow: var(--shadow);
}
.mapwrap.collapsed .mini {
  display: none;
}
.maptoggle {
  min-height: 32px;
  border-radius: 999px;
  padding: 4px 12px;
}

.touch {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 5;
  touch-action: none;
}
.touch[hidden] {
  display: none;
}
#stick {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 1px solid var(--border);
  position: relative;
  touch-action: none;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  backdrop-filter: blur(4px);
}
#stick::before,
#stick::after {
  content: "";
  position: absolute;
  background: var(--border);
  left: 50%;
  top: 50%;
}
#stick::before {
  width: 1px;
  height: 70%;
  transform: translate(-50%, -50%);
}
#stick::after {
  height: 1px;
  width: 70%;
  transform: translate(-50%, -50%);
}
#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: var(--amber);
  opacity: 0.85;
  box-shadow: var(--shadow);
}
body.touch-ui .help {
  display: none;
}
body.touch-ui .prompt {
  bottom: 174px;
}
body.touch-ui .btn,
body.touch-ui .lt .btn,
body.touch-ui .tourbar .btn,
body.touch-ui .maptoggle {
  min-height: 44px;
  min-width: 44px;
}
@media (pointer: coarse) {
  .btn,
  .lt .btn,
  .tourbar .btn,
  .maptoggle {
    min-height: 44px;
    min-width: 44px;
  }
}

/* project list: always in DOM, revealed on demand / on focus / when WebGL is unavailable */
#list {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  overflow: auto;
  padding: max(18px, env(safe-area-inset-top)) 18px 40px;
  outline: none;
}
#list:not(.open):not(:focus-within) {
  position: absolute;
  inset: auto;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  margin: -1px;
}
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1000px;
  margin: 0 auto 14px;
}
.list-head h2 {
  margin: 0;
  font-size: 20px;
}
#items {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 1000px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
#items li {
  margin: 0;
}
#items a {
  display: block;
  height: 100%;
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-weight: 600;
  font-size: 14px;
}
#items a:hover {
  border-color: var(--teal);
}
#items img {
  display: block;
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
#items .t {
  display: block;
  padding: 10px 12px 4px;
}
#items .c {
  display: block;
  padding: 0 12px 12px;
  font: 500 11px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cc, var(--muted));
}
#items a:not(:has(img)) {
  padding: 12px;
}

body.no-gl {
  overflow: auto;
}
body.no-gl #gl,
body.no-gl .help,
body.no-gl .touch,
body.no-gl .prompt,
body.no-gl .speed,
body.no-gl #reset,
body.no-gl #tour,
body.no-gl .mapwrap,
body.no-gl .tourbar,
body.no-gl #skip,
body.no-gl #back {
  display: none;
}
body.no-gl #list {
  position: static;
  min-height: 100%;
  padding-top: 150px;
}
body.no-gl .hud {
  position: absolute;
}
body.no-gl .row {
  display: none;
}

@media (max-width: 600px) {
  .card {
    min-width: 0;
    padding: 9px 11px;
  }
  .card h1 {
    font-size: 15px;
  }
  .sub {
    display: none;
  }
  .row {
    gap: 10px;
    align-items: center;
  }
  .speed span {
    font-size: 20px;
  }
  .btn {
    padding: 5px 8px;
    font-size: 12px;
  }
  .help {
    display: none;
  }
  .tourbar__t {
    display: none;
  }
  .tourbar .btn {
    white-space: nowrap;
  }
  .mapwrap {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
  }
  .mini {
    width: 104px;
    height: 104px;
  }
  .lt__title {
    font-size: 14.5px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
