:root {
  color-scheme: dark;
  --app-height: 100vh;
  --mobile-viewer-height: clamp(220px, 32vh, 310px);
  --bg: #05060b;
  --panel: #11131a;
  --panel-strong: #171a23;
  --line: rgba(255, 255, 255, 0.13);
  --text: #f4f7fb;
  --muted: #a5adba;
  --cyan: #28e7ff;
  --cyan-soft: rgba(40, 231, 255, 0.18);
  --magenta: #ff3bbd;
  --yellow: #ffe35b;
  --danger: #ff6d89;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
    --mobile-viewer-height: clamp(220px, 32dvh, 310px);
  }
}

body.light-mode {
  color-scheme: light;
  --bg: #f8fbff;
  --panel: #ffffff;
  --panel-strong: #f1f3f5;
  --line: rgba(0, 0, 0, 0.08);
  --text: #000000;
  --muted: #6c757d;
  --cyan: #0d6efd;
  --cyan-soft: rgba(13, 110, 253, 0.08);
  --magenta: #ea5343;
  --yellow: #ffc107;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Noto Sans KR", Inter, system-ui, -apple-system, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(306px, 360px) minmax(0, 1fr);
  width: 100vw;
  height: var(--app-height);
  background: var(--bg);
}

.control-panel {
  display: block;
  min-width: 0;
  height: calc(var(--app-height) - 40px);
  margin: 20px 0 20px 20px;
  overflow: hidden;
  border: 5px solid var(--magenta);
  border-radius: 32px;
  background: var(--panel);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

.panel-scroll-inner {
  display: flex;
  height: 100%;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 24px 20px 18px;
}

/* Custom Scrollbar to keep it inside rounding */
.panel-scroll-inner::-webkit-scrollbar {
  width: 10px;
}

.panel-scroll-inner::-webkit-scrollbar-track {
  background: transparent;
  margin: 20px 0;
}

.panel-scroll-inner::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  border: 3px solid var(--panel);
}

body.light-mode .panel-scroll-inner::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

body.light-mode .control-panel {
  border-color: #ea5343;
}

.panel-header {
  padding-bottom: 4px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: none;
}

body.light-mode .eyebrow {
  color: #000;
}

h1,
h2 {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: 1.7rem;
  line-height: 1.08;
}

h2 {
  color: var(--text);
  font-size: 0.79rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.control-section {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.button-grid,
.preset-list,
.surface-row,
.annotation-tools,
.action-row,
.segmented {
  display: grid;
  gap: 8px;
}

.mode-grid {
  grid-template-columns: 1fr;
}

.segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.player-control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.player-control-grid .field-label {
  text-align: center;
}

.segmented.compact {
  gap: 5px;
}

.segmented.compact .segment-button {
  padding: 8px 4px;
}

.tool-button,
.preset-button,
.action-button,
.chip,
.icon-button,
.segment-button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 700;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

body.light-mode .tool-button,
body.light-mode .preset-button,
body.light-mode .action-button,
body.light-mode .chip,
body.light-mode .icon-button,
body.light-mode .segment-button {
  border-color: #dee2e6;
  background: #f8f9fa;
  color: #212529;
}

.tool-button:hover,
.preset-button:hover,
.action-button:hover,
.chip:hover,
.icon-button:hover,
.segment-button:hover {
  border-color: rgba(40, 231, 255, 0.45);
  background: #1a1e29;
}

body.light-mode .tool-button:hover,
body.light-mode .preset-button:hover,
body.light-mode .action-button:hover,
body.light-mode .chip:hover,
body.light-mode .icon-button:hover,
body.light-mode .segment-button:hover {
  border-color: #adb5bd;
  background: #e9ecef;
}

.tool-button:active,
.preset-button:active,
.action-button:active,
.chip:active,
.icon-button:active,
.segment-button:active {
  transform: translateY(1px);
}

.tool-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  min-height: 42px;
  gap: 9px;
  padding: 8px 10px;
  text-align: left;
}

.tool-icon {
  display: inline-grid;
  place-items: center;
  color: var(--cyan);
}

.tool-icon svg,
.icon-button svg {
  width: 19px;
  height: 19px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.tool-button.active,
.chip.active,
.icon-button.active,
.segment-button.active {
  border-color: var(--cyan);
  background: var(--cyan);
  color: #fff;
}

body.light-mode .tool-button.active,
body.light-mode .chip.active,
body.light-mode .icon-button.active,
body.light-mode .segment-button.active {
  border-color: var(--cyan);
  background: var(--cyan);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 110, 253, 0.25);
}

.segment-button[data-active-player="p1"],
.segment-button[data-shooter="p1"] {
  border-color: rgba(13, 110, 253, 0.52);
  color: #6aa7ff;
}

.segment-button[data-active-player="p2"],
.segment-button[data-shooter="p2"] {
  border-color: rgba(215, 25, 32, 0.58);
  color: #ff7b82;
}

body.light-mode .segment-button[data-active-player="p1"],
body.light-mode .segment-button[data-shooter="p1"] {
  border-color: rgba(13, 110, 253, 0.52);
  color: #0d6efd;
}

body.light-mode .segment-button[data-active-player="p2"],
body.light-mode .segment-button[data-shooter="p2"] {
  border-color: rgba(215, 25, 32, 0.58);
  color: #d71920;
}

.segment-button[data-active-player="p1"].active,
.segment-button[data-shooter="p1"].active,
body.light-mode .segment-button[data-active-player="p1"].active,
body.light-mode .segment-button[data-shooter="p1"].active {
  border-color: #0d6efd;
  background: #0d6efd;
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 110, 253, 0.28);
}

.segment-button[data-active-player="p2"].active,
.segment-button[data-shooter="p2"].active,
body.light-mode .segment-button[data-active-player="p2"].active,
body.light-mode .segment-button[data-shooter="p2"].active {
  border-color: #d71920;
  background: #d71920;
  color: #fff;
  box-shadow: 0 4px 12px rgba(215, 25, 32, 0.26);
}

.surface-row {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.chip,
.segment-button {
  min-width: 0;
  padding: 9px 6px;
  font-size: 0.82rem;
  font-weight: 760;
}

.chip.disabled,
.segment-button.disabled,
.action-button:disabled {
  opacity: 0.42;
  box-shadow: none;
}

.preset-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.preset-button {
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 730;
}

.annotation-tools {
  grid-template-columns: repeat(4, 42px);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 40px;
  place-items: center;
  color: var(--text);
}

.field-label,
.toggle-line {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.field-label output {
  float: right;
  color: var(--yellow);
  font-weight: 800;
  text-transform: none;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 28px;
}

.mode-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 8px 10px;
}

body.light-mode .mode-toggle {
  background: #f8f9fa;
}

.mode-toggle.disabled {
  opacity: 0.48;
}

.toggle-line input {
  width: 16px;
  height: 16px;
  accent-color: var(--cyan);
}

.range-input {
  width: 100%;
  accent-color: var(--magenta);
}

.text-input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  padding: 10px 11px;
}

body.light-mode .text-input {
  border-color: rgba(8, 23, 42, 0.2);
  background: #f8fbff;
}

.theme-switch {
  display: grid;
  grid-template-columns: auto 52px auto;
  align-items: center;
  justify-content: start;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.theme-switch input {
  position: relative;
  width: 52px;
  height: 28px;
  margin: 0;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: var(--panel-strong);
  outline: none;
  transition: background 160ms ease, border-color 160ms ease;
}

body.light-mode .theme-switch input {
  border-color: rgba(8, 23, 42, 0.24);
}

.theme-switch input::before {
  position: absolute;
  top: 3px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--cyan);
  content: "";
  transition: transform 160ms ease;
}

.theme-switch input:checked::before {
  transform: translateX(22px);
}

.text-input:focus {
  border-color: rgba(255, 59, 189, 0.78);
  box-shadow: 0 0 0 3px rgba(255, 59, 189, 0.13);
}

body.light-mode .text-input:focus {
  border-color: rgba(215, 25, 32, 0.78);
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.14);
}

.action-section {
  margin-top: auto;
}

.action-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.shot-path-actions {
  margin-top: -2px;
}

.output-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.playback-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.playback-slider {
  min-height: 28px;
}

.action-button {
  display: flex;
  min-width: 0;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 780;
  text-decoration: none;
}

.index-link {
  width: 100%;
}

.action-button.primary {
  border-color: rgba(255, 227, 91, 0.55);
  background: rgba(255, 227, 91, 0.14);
}

body.light-mode .action-button.primary {
  border-color: #ea5343;
  background: #ea5343;
  color: #fff;
}

body.light-mode .action-button.primary:hover {
  background: #d43f30;
  border-color: #d43f30;
}

.action-button.recording {
  border-color: var(--danger);
  background: rgba(255, 109, 137, 0.16);
  color: var(--danger);
}

body.light-mode .action-button.recording {
  border-color: #d71920;
  background: #d71920;
  color: #fff;
}

.action-button.playing {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: var(--cyan);
}

body.light-mode .action-button.playing {
  border-color: #0d6efd;
  background: rgba(13, 110, 253, 0.12);
  color: #0d6efd;
}

.sequence-readout,
.status-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.sequence-readout {
  min-height: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
}

body.light-mode .sequence-readout {
  border-color: rgba(8, 23, 42, 0.16);
  background: rgba(8, 23, 42, 0.04);
}

.status-line {
  min-height: 24px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.scene-host {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.scene-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.export-modal[hidden] {
  display: none;
}

.export-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.export-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
}

.export-modal__panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(520px, 100%);
  max-height: 92dvh;
  gap: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  padding: 18px;
}

.export-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.export-modal__eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.export-modal__header h2 {
  font-size: 1.2rem;
  text-transform: none;
}

.export-modal__close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
}

.export-modal__help {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.export-modal__image-wrap {
  max-height: min(56dvh, 460px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  padding: 8px;
  touch-action: auto;
  -webkit-overflow-scrolling: touch;
}

.export-modal__image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  touch-action: auto;
  pointer-events: auto;
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-touch-callout: default;
  -webkit-user-drag: auto;
}

.export-modal__video-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #000;
}

.export-modal__video {
  display: block;
  width: 100%;
  max-height: min(56dvh, 460px);
  background: #000;
}

.export-modal__actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

#exportModalHelpMobile,
#exportMobileActions {
  display: none;
}

@media (hover: none),
(pointer: coarse),
(max-width: 850px) {

  #exportModalHelpDesktop,
  #exportDownloadActions {
    display: none !important;
  }

  #exportModalHelpMobile {
    display: block !important;
  }

  #exportMobileActions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .export-modal .export-modal__image-wrap {
    max-height: none;
    overflow: visible;
  }

  .export-modal .export-modal__image {
    -webkit-touch-callout: default;
    -webkit-user-select: auto;
    user-select: auto;
  }
}

.recording-modal .export-modal__actions {
  grid-template-columns: 1fr;
}

.share-url-input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
  font-size: 0.84rem;
}

body.light-mode .share-url-input {
  background: #f8fbff;
}

@media (hover: hover) and (pointer: fine) and (min-width: 851px) {
  .output-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 850px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(410px, 62vh) auto;
    height: auto;
    min-height: var(--app-height);
  }

  .viewer-panel {
    grid-row: 1;
    min-height: 410px;
  }

  .control-panel {
    grid-row: 2;
    width: 100%;
    height: auto;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }
}

@media (max-width: 850px) and (orientation: portrait) {

  html,
  body {
    height: var(--app-height);
    overflow: hidden;
  }

  .app-shell {
    display: block;
    height: var(--app-height);
    min-height: var(--app-height);
    overflow: hidden;
  }

  .viewer-panel {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 10;
    height: var(--mobile-viewer-height);
    min-height: 0;
    max-height: none;
    border-bottom: 1px solid var(--line);
  }

  .control-panel {
    position: absolute;
    top: var(--mobile-viewer-height);
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    margin: 0;
    overflow: hidden;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    padding: 0;
  }

  body.light-mode .control-panel {
    border-color: var(--line);
  }

  .panel-scroll-inner {
    height: 100%;
    gap: 14px;
    overflow-y: auto;
    padding: 20px 20px 18px;
    -webkit-overflow-scrolling: touch;
  }

  .panel-header {
    padding-top: 2px;
  }

  h1 {
    font-size: 1.36rem;
  }

  .eyebrow {
    font-size: 1rem;
  }

  .player-control-grid {
    gap: 7px;
  }

  .tool-button {
    min-height: 41px;
  }
}

@media (max-width: 430px) and (orientation: portrait) {
  .viewer-panel {
    height: var(--mobile-viewer-height);
  }

  .control-panel {
    top: var(--mobile-viewer-height);
    right: 0;
    left: 0;
    border-radius: 0;
  }

  .panel-scroll-inner {
    padding: 18px 16px 18px;
  }

  .player-control-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .segmented.compact {
    gap: 4px;
  }

  .segmented.compact .segment-button {
    padding-right: 2px;
    padding-left: 2px;
    font-size: 0.8rem;
  }
}

@media (max-height: 540px) and (orientation: landscape) {

  html,
  body {
    height: var(--app-height);
    overflow: hidden;
  }

  .app-shell {
    display: grid;
    grid-template-columns: minmax(260px, 34vw) minmax(0, 1fr);
    grid-template-rows: 1fr;
    height: var(--app-height);
    min-height: 0;
    overflow: hidden;
  }

  .control-panel {
    position: relative;
    grid-column: 1;
    grid-row: 1;
    inset: auto;
    width: auto;
    height: var(--app-height);
    min-height: 0;
    margin: 0;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
  }

  .viewer-panel {
    position: relative;
    grid-column: 2;
    grid-row: 1;
    height: var(--app-height);
    min-height: 0;
    border-bottom: 0;
  }

  .panel-scroll-inner {
    height: 100%;
    gap: 10px;
    overflow-y: auto;
    padding: 13px 12px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .panel-header {
    padding-bottom: 0;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: 0.82rem;
  }

  h1 {
    font-size: 1.08rem;
    line-height: 1.05;
  }

  h2 {
    font-size: 0.66rem;
  }

  .control-section {
    gap: 7px;
  }

  .player-control-grid {
    gap: 5px;
  }

  .player-control-grid .field-label {
    font-size: 0.62rem;
  }

  .segment-button,
  .tool-button,
  .action-button,
  .toggle-line,
  .text-input {
    min-height: 32px;
    padding: 7px 9px;
    font-size: 0.78rem;
  }

  .segmented.compact {
    gap: 4px;
  }

  .segmented.compact .segment-button {
    padding-right: 2px;
    padding-left: 2px;
  }

  .tool-button {
    justify-content: flex-start;
  }

  .tool-icon,
  .icon-button svg {
    width: 18px;
    height: 18px;
  }

  .annotation-tools {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .icon-button {
    min-height: 30px;
  }

  .action-row {
    gap: 6px;
  }

  .status-line,
  .readout {
    font-size: 0.72rem;
  }
}

@media (max-width: 740px) and (max-height: 420px) and (orientation: landscape) {
  .app-shell {
    grid-template-columns: minmax(232px, 38vw) minmax(0, 1fr);
  }

  .control-panel {
    height: var(--app-height);
  }

  .panel-scroll-inner {
    padding: 10px;
  }
}