:root {
  color-scheme: only light;
  font-family: system-ui, sans-serif;
}

html,
body,
#viewport {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e9e8e4;
}

#viewport {
  position: relative;
  touch-action: none;
  cursor: grab;
}

#viewport.is-dragging {
  cursor: grabbing;
}

#board {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: white;
}

.scene-layer,
.scene-image,
.scene-text,
.scene-link,
.scene-svg {
  position: absolute;
  transform-origin: 0 0;
}

.scene-svg {
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.scene-image,
.scene-vector-artwork,
.scene-path {
  pointer-events: none;
}

.scene-text {
  left: 0;
  top: 0;
  white-space: pre;
  line-height: 1;
  transform-origin: 0 0;
}

.scene-link {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.scene-embed {
  width: 100%;
  height: 100%;
  border: 0;
  background: black;
}

.scene-game-icon {
  position: absolute;
  right: 5%;
  bottom: 5%;
  box-sizing: border-box;
  width: 38%;
  height: 38%;
  padding: 7%;
  border-radius: 28%;
  color: white;
  background: #6d28d9;
  box-shadow: 0 4px 12px rgb(0 0 0 / 28%);
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.scene-game-link:hover .scene-game-icon {
  background: #4c1d95;
}

#viewport:focus-visible,
.scene-link:focus-visible,
#controls button:focus-visible,
#topic-list button:focus-visible,
#topic-search:focus-visible {
  outline: 3px solid #087ea4;
  outline-offset: 3px;
}

#status {
  position: fixed;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  color: #45443f;
  font-size: 14px;
}

#controls {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
  background: rgb(24 24 22 / 82%);
  box-shadow: 0 8px 28px rgb(0 0 0 / 20%);
  backdrop-filter: blur(14px);
}

#controls[hidden],
#topic-panel[hidden] {
  display: none;
}

#controls button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: white;
  background: rgb(255 255 255 / 18%);
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}

#controls svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#topic-panel {
  position: fixed;
  bottom: calc(78px + env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: min(292px, calc(100vw - 28px));
  max-height: min(65vh, 560px);
  padding: 18px 10px 12px;
  overflow-y: auto;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 22px;
  color: white;
  background: rgb(24 24 22 / 86%);
  box-shadow: 0 16px 48px rgb(0 0 0 / 24%);
  backdrop-filter: blur(18px);
}

.topic-panel-title {
  margin: 0 10px 12px;
  color: rgb(255 255 255 / 58%);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topic-search {
  display: block;
  margin: 0 4px 10px;
}

.topic-search[hidden] {
  display: none;
}

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

#topic-search {
  box-sizing: border-box;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 11px;
  color: white;
  background: rgb(255 255 255 / 10%);
  font: 500 13px system-ui, sans-serif;
}

#topic-search::placeholder {
  color: rgb(255 255 255 / 52%);
}

#topic-list {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 4px;
  overflow: visible;
  list-style: none;
}

#topic-list li + li {
  margin-top: 3px;
}

#topic-list button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: baseline;
  width: 100%;
  padding: 10px 8px;
  overflow: hidden;
  border: 0;
  border-radius: 12px;
  color: rgb(255 255 255 / 90%);
  background: transparent;
  font: 560 13px/1.3 system-ui, sans-serif;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

#topic-list button:hover {
  background: rgb(255 255 255 / 9%);
}

#topic-list button[aria-current="true"] {
  color: white;
  background: rgb(255 255 255 / 16%);
}

.topic-number {
  color: #f6ca55;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

#topic-empty {
  margin: 0 8px;
  color: rgb(255 255 255 / 58%);
  font-size: 13px;
  text-align: center;
}

#topic-empty:not(:empty) {
  margin-block: 12px;
}

@media (max-width: 720px) {
  #topic-panel {
    max-height: min(56vh, 440px);
  }
}
