:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --ui-canvas: #07090d;
  --ui-surface: rgba(18, 21, 27, 0.88);
  --ui-surface-solid: #12151b;
  --ui-surface-hover: rgba(255, 255, 255, 0.09);
  --ui-scrim: rgba(2, 4, 8, 0.58);
  --ui-text: #f7f8fa;
  --ui-muted: #adb3bd;
  --ui-line: rgba(255, 255, 255, 0.13);
  --ui-accent: #39b8f2;
  --ui-accent-ink: #06151d;
  --ui-danger: #ff9b92;
  --ui-focus: #7ad7ff;
  --ui-shadow: 0 16px 48px rgba(0, 0, 0, 0.34);
  --touch-control-size: 48px;
  --touch-control-gap: 2px;
  --fg: var(--ui-text);
  --muted: var(--ui-muted);
  --accent: var(--ui-accent);
  --accent-dim: color-mix(in srgb, var(--ui-accent) 18%, transparent);
  --warn: var(--ui-danger);
  --panel: var(--ui-surface);
  --panel-solid: var(--ui-surface-solid);
  --line: var(--ui-line);
  --bg: var(--ui-canvas);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ui-canvas: #e9edf2;
  --ui-surface: rgba(255, 255, 255, 0.9);
  --ui-surface-solid: #ffffff;
  --ui-surface-hover: rgba(10, 17, 28, 0.07);
  --ui-scrim: rgba(13, 20, 31, 0.36);
  --ui-text: #101722;
  --ui-muted: #596270;
  --ui-line: rgba(16, 23, 34, 0.14);
  --ui-accent: #0878d1;
  --ui-accent-ink: #ffffff;
  --ui-danger: #b42318;
  --ui-focus: #006fc4;
  --ui-shadow: 0 16px 48px rgba(24, 35, 50, 0.2);
}

:root[data-theme="hc-light"] {
  color-scheme: light;
  --ui-canvas: #ffffff;
  --ui-surface: #ffffff;
  --ui-surface-solid: #ffffff;
  --ui-surface-hover: #e8e8e8;
  --ui-scrim: rgba(0, 0, 0, 0.48);
  --ui-text: #000000;
  --ui-muted: #292929;
  --ui-line: #000000;
  --ui-accent: #005fcc;
  --ui-accent-ink: #ffffff;
  --ui-danger: #9d0000;
  --ui-focus: #005fcc;
  --ui-shadow: none;
}

:root[data-theme="hc-dark"] {
  color-scheme: dark;
  --ui-canvas: #000000;
  --ui-surface: #000000;
  --ui-surface-solid: #000000;
  --ui-surface-hover: #242424;
  --ui-scrim: rgba(0, 0, 0, 0.76);
  --ui-text: #ffffff;
  --ui-muted: #ededed;
  --ui-line: #ffffff;
  --ui-accent: #7bdcff;
  --ui-accent-ink: #000000;
  --ui-danger: #ffb3ac;
  --ui-focus: #fff200;
  --ui-shadow: none;
}

:root[data-theme="colorblind"] {
  color-scheme: dark;
  --ui-canvas: #081018;
  --ui-surface: rgba(15, 27, 38, 0.92);
  --ui-surface-solid: #0f1b26;
  --ui-surface-hover: rgba(255, 255, 255, 0.1);
  --ui-scrim: rgba(2, 6, 10, 0.66);
  --ui-text: #ffffff;
  --ui-muted: #c4ccd4;
  --ui-line: rgba(255, 255, 255, 0.2);
  --ui-accent: #f0b429;
  --ui-accent-ink: #171000;
  --ui-danger: #ff8f70;
  --ui-focus: #66d9ef;
  --ui-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  background: var(--ui-canvas);
}

body {
  font-family: "Instrument Sans", "Noto Sans KR", "Segoe UI", system-ui, sans-serif;
  color: var(--ui-text);
}

#hud {
  isolation: isolate;
}

#place-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: clip;
  pointer-events: none !important;
  contain: strict;
}

#place-layer[hidden],
#btn-places[hidden] {
  display: none !important;
}

.depth-place-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  transform: translate3d(var(--place-x), var(--place-y), 0);
  will-change: transform;
}

.depth-place-icon {
  position: absolute;
  left: calc(var(--place-icon-size) / -2);
  width: var(--place-icon-size);
  height: var(--place-icon-size);
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.58));
  user-select: none;
  -webkit-user-drag: none;
}

.depth-place-marker[data-anchor="bottom"] .depth-place-icon {
  top: calc(var(--place-icon-size) * -1);
}

.depth-place-marker[data-anchor="center"] .depth-place-icon {
  top: calc(var(--place-icon-size) / -2);
}

.depth-place-label {
  position: absolute;
  top: var(--place-label-top);
  left: var(--place-label-left);
  width: var(--place-label-width);
  max-height: 40px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
  word-break: keep-all;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  -webkit-text-stroke: 3px rgba(0, 0, 0, 0.9);
  paint-order: stroke fill;
}

.depth-place-marker[data-side="left"] .depth-place-label {
  text-align: right;
}

:focus-visible {
  outline: 2px solid var(--ui-focus) !important;
  outline-offset: 3px !important;
}

button,
select,
input {
  font: inherit;
}

button,
select {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--ui-text);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease, opacity 140ms ease, transform 140ms ease;
}

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

button:active {
  transform: translateY(1px);
}

button.primary,
.seg button[aria-pressed="true"] {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-accent-ink);
}

button.primary:hover,
.seg button[aria-pressed="true"]:hover {
  filter: none;
  background: color-mix(in srgb, var(--ui-accent) 88%, white);
}

button.danger {
  color: var(--ui-danger);
}

.panel {
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  backdrop-filter: blur(18px) saturate(130%);
}

#topbar {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  right: auto;
  width: min(1040px, calc(100% - 32px));
  min-height: 56px;
  padding: 7px;
  display: grid;
  grid-template-columns: minmax(128px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--ui-line);
  border-radius: 16px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  backdrop-filter: blur(18px) saturate(130%);
  transform: translateX(-50%);
  animation: toolbar-in 280ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#brand,
#modes,
#hud-actions {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

#brand {
  min-height: 40px;
  padding-inline: 4px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

#viewer-back {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--ui-muted);
  text-decoration: none;
  transition: background-color 140ms ease, color 140ms ease, transform 140ms ease;
}

#viewer-back:hover {
  background: var(--ui-surface-hover);
  color: var(--ui-text);
}

#viewer-back:active {
  transform: translateY(1px);
}

#brand b {
  max-width: 200px;
  overflow: hidden;
  color: var(--ui-text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#world-label,
#topbar > .spacer,
#btn-ui {
  display: none !important;
}

#btn-vr[hidden] {
  display: none !important;
}

#modes {
  justify-self: center;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

#modes::-webkit-scrollbar {
  display: none;
}

#modes button {
  min-width: 64px;
  padding: 0 12px;
  flex: 0 0 auto;
  border-radius: 10px;
  color: var(--ui-muted);
  font-size: 13px;
  font-weight: 600;
}

#modes button[aria-pressed="true"] {
  color: var(--ui-accent-ink);
}

#modes button kbd {
  display: none;
}

#hud-actions {
  justify-self: end;
  display: flex;
  gap: 2px;
}

#hud-actions button {
  min-width: 40px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--ui-muted);
}

#hud-actions button:hover,
#hud-actions button[aria-expanded="true"] {
  color: var(--ui-text);
}

#hud-actions #btn-vr[aria-pressed="true"] {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-accent-ink);
}

.action-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.action-label {
  font-size: 12px;
  font-weight: 650;
}

.compact-only {
  display: inline-flex;
}

#compact-scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: block;
  background: var(--ui-scrim);
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(2px);
  transition: opacity 140ms ease;
}

#compact-scrim.on {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

#side,
#help {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  z-index: 22;
  width: min(392px, calc(100% - 24px));
  max-width: none;
  max-height: none;
  padding: 0 0 max(12px, env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  border: 0;
  border-left: 1px solid var(--ui-line);
  border-radius: 0;
  background: var(--ui-surface-solid);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  transform: translateX(20px);
  animation: drawer-in 160ms ease both;
  overscroll-behavior: contain;
}

#side.compact-open,
#help.compact-open,
#help.hidden.compact-open {
  display: flex;
}

.compact-sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 64px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 0;
  border-bottom: 1px solid var(--ui-line);
  border-radius: 0;
  background: var(--ui-surface-solid);
}

.compact-sheet-head strong {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.compact-close {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

#side .panel {
  padding: 18px 20px;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--ui-line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.panel h3 {
  min-height: 20px;
  margin: 0;
  color: var(--ui-text);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.panel h3 span {
  color: var(--ui-muted);
  font-size: 12px;
  font-weight: 550;
}

.row {
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.row > label {
  flex: 0 0 72px;
  color: var(--ui-muted);
  font-size: 12px;
}

.row input[type="range"] {
  min-width: 0;
  flex: 1 1 auto;
  accent-color: var(--ui-accent);
}

.row output {
  flex: 0 0 44px;
  color: var(--ui-text);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.row.wide > label {
  flex: 1 1 auto;
}

.toggle {
  min-height: 32px;
  color: var(--ui-text) !important;
}

.chips {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chips button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  font-size: 11px;
}

.hint {
  margin: 0;
  color: var(--ui-muted);
  font-size: 11px;
  line-height: 1.55;
}

#help {
  padding-bottom: 24px;
  font-size: 13px;
  line-height: 1.55;
}

#help .compact-sheet-head {
  width: 100%;
}

.help-list {
  margin: 0;
  padding: 16px 20px;
  display: grid;
  gap: 0;
}

.help-list div {
  padding: 12px 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--ui-line);
}

.help-list div:last-child {
  border-bottom: 0;
}

.help-list dt {
  color: var(--ui-text);
  font-weight: 700;
}

.help-list dd {
  margin: 0;
  color: var(--ui-muted);
}

#help kbd,
.hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--ui-line);
  border-radius: 5px;
  background: var(--ui-surface-hover);
  color: var(--ui-text);
  font: 11px/1.3 "JetBrains Mono", ui-monospace, monospace;
}

#cinedock {
  top: auto;
  right: auto;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  width: min(1040px, calc(100% - 32px));
  max-height: calc(100% - 104px);
  padding: 14px;
  gap: 10px;
  overflow-y: auto;
  border-radius: 16px;
  transform: translateX(-50%);
}

#cinedock.on {
  display: flex;
}

#track {
  border-color: var(--ui-line);
  background: var(--ui-surface-hover);
}

#kfedit input[type="number"],
select {
  border-color: var(--ui-line);
  background: var(--ui-surface-hover);
  color: var(--ui-text);
}

#status,
#site-note {
  display: none !important;
}

#touch-controls {
  display: none;
}

#touch-controls[hidden] {
  display: none !important;
}

.touch-dpad,
.touch-actions {
  pointer-events: auto;
  padding: 6px;
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  backdrop-filter: blur(18px) saturate(130%);
}

.touch-dpad {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(3, var(--touch-control-size));
  grid-template-rows: repeat(3, var(--touch-control-size));
  gap: var(--touch-control-gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-direction,
.touch-actions button {
  min-width: var(--touch-control-size);
  min-height: var(--touch-control-size);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
  color: var(--ui-text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-direction[aria-pressed="true"],
.touch-actions button[aria-pressed="true"] {
  background: var(--ui-accent);
  color: var(--ui-accent-ink);
  transform: scale(0.96);
}

.touch-direction-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.touch-forward {
  grid-column: 2;
  grid-row: 1;
}

.touch-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-left .touch-direction-icon {
  transform: rotate(-90deg);
}

.touch-dpad-center {
  grid-column: 2;
  grid-row: 2;
  width: 18px;
  height: 18px;
  place-self: center;
  border-radius: 50%;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface-hover);
  pointer-events: none;
  transform: translate(var(--touch-stick-x, 0), var(--touch-stick-y, 0));
  transition: transform 80ms ease, border-color 80ms ease, background-color 80ms ease;
}

.touch-dpad.is-active .touch-dpad-center {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
}

.touch-right {
  grid-column: 3;
  grid-row: 2;
}

.touch-right .touch-direction-icon {
  transform: rotate(90deg);
}

.touch-back {
  grid-column: 2;
  grid-row: 3;
}

.touch-back .touch-direction-icon {
  transform: rotate(180deg);
}

.touch-actions {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: var(--touch-control-gap);
}

.touch-actions button {
  width: 84px;
  padding: 0 10px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  text-align: left;
}

.touch-action-icon {
  font-size: 16px;
  line-height: 1;
}

.touch-action-label {
  overflow: hidden;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#touch-hint {
  position: absolute;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 170px);
  left: 50%;
  margin: 0;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  color: var(--ui-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  opacity: 1;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 140ms ease, transform 140ms ease;
}

.touch-hint-icon {
  color: var(--ui-text);
  font-size: 14px;
  line-height: 1;
}

#touch-controls.touch-engaged #touch-hint {
  opacity: 0;
  transform: translate(-50%, 6px);
}

#touch-tour-toggle {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  padding: 0 16px;
  display: none;
  align-items: center;
  gap: 8px;
  min-height: var(--touch-control-size);
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  font-size: 12px;
  font-weight: 700;
  pointer-events: auto;
  touch-action: manipulation;
  transform: translateX(-50%);
}

#touch-tour-toggle[aria-pressed="true"] {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-accent-ink);
}

#action-feedback {
  position: fixed;
  z-index: 24;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: var(--ui-surface-solid);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

#action-feedback.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#loading {
  gap: 0;
  background: var(--ui-canvas);
  color: var(--ui-text);
  transition: opacity 180ms ease;
}

#loading[hidden] {
  display: none;
}

#loading-back {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 0 14px 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  backdrop-filter: blur(18px) saturate(130%);
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

#loading-back:hover {
  border-color: var(--ui-text);
  background: var(--ui-surface-hover);
}

#loading-back:active {
  transform: translateY(1px);
}

.loading-content {
  width: min(320px, calc(100% - 48px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#loading h1 {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  font-size: 24px;
  font-weight: 720;
  letter-spacing: -0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#loading-sub {
  display: none;
}

#loadbar {
  width: min(240px, 100%);
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--ui-line);
}

#loadbar > div {
  border-radius: inherit;
  background: var(--ui-accent);
}

#loading.loading-error #loadbar > div {
  background: var(--ui-danger);
}

#loadmsg {
  min-height: 1.5em;
  color: var(--ui-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  word-break: keep-all;
}

@keyframes toolbar-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes drawer-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 860px) {
  #topbar {
    grid-template-columns: minmax(88px, auto) minmax(0, 1fr) auto;
  }

  .action-label {
    display: none;
  }

  #hud-actions button {
    padding-inline: 8px;
  }
}

@media (max-width: 640px) {
  #loading-back {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
  }

  #topbar {
    top: max(8px, env(safe-area-inset-top));
    width: calc(100% - 16px);
    min-height: 0;
    padding: 6px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "modes modes";
    gap: 4px;
    border-radius: 14px;
  }

  #brand {
    grid-area: brand;
    padding-inline: 0 8px;
  }

  #brand b {
    max-width: none;
    font-size: 14px;
  }

  #modes {
    grid-area: modes;
    width: 100%;
    justify-self: stretch;
    justify-content: flex-start;
  }

  #modes button {
    min-width: 58px;
    min-height: 40px;
    padding-inline: 11px;
    font-size: 12px;
  }

  #hud-actions {
    grid-area: actions;
  }

  #hud-actions button {
    min-width: 40px;
    min-height: 40px;
  }

  #hud-actions > #btn-share {
    display: inline-flex !important;
  }

  #hud-actions > #btn-places:not([hidden]) {
    display: inline-flex !important;
  }

  #hud-actions > #btn-vr:not([hidden]) {
    display: inline-flex;
  }

  #side,
  #help {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: none;
    border-left: 0;
  }

  #cinedock {
    top: 112px;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: calc(100% - 120px);
    border-radius: 14px;
    transform: none;
  }
}

@media (max-width: 640px), (any-pointer: coarse) {
  #touch-controls {
    position: fixed;
    inset: auto 0 0;
    z-index: 12;
    height: calc((var(--touch-control-size) * 3) + (var(--touch-control-gap) * 2) + 12px + max(12px, env(safe-area-inset-bottom)));
    display: block;
    pointer-events: none;
  }

  #touch-controls[data-mode="tour"] .touch-dpad,
  #touch-controls[data-mode="tour"] .touch-actions {
    display: none;
  }

  #touch-controls[data-mode="tour"] #touch-hint {
    right: auto;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--touch-control-size) + 8px);
    left: 50%;
    width: fit-content;
  }

  #touch-controls[data-mode="tour"] #touch-tour-toggle {
    display: inline-flex;
  }

  #action-feedback {
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + (var(--touch-control-size) * 3) + (var(--touch-control-gap) * 2) + 12px);
  }
}

@media (max-height: 420px) and (any-pointer: coarse) {
  #touch-hint {
    display: none;
  }
}

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