:root {
  --bg-0: #0b1526;
  --bg-1: #10233d;
  --panel: rgba(8, 14, 28, 0.88);
  --panel-border: rgba(168, 197, 255, 0.28);
  --text: #f3f7ff;
  --muted: #a8b7d2;
  --accent: #66d1ff;
  --danger: #ff6d5c;
  --shadow: rgba(0, 0, 0, 0.4);
  --controller-width: clamp(250px, 26vw, 300px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 18% 20%, #1a3457, var(--bg-0) 50%),
    linear-gradient(160deg, #06111f, #0a1d35 42%, #0d213f);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#file-protocol-warning {
  position: fixed;
  z-index: 20;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(255, 125, 88, 0.8);
  border-radius: 8px;
  background: rgba(77, 19, 12, 0.88);
  color: #ffd7cb;
  font-size: 0.79rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

#viewport {
  position: absolute;
  inset: 0;
}

#sidebar {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 10;
  width: min(248px, calc(100vw - 1.7rem));
  display: grid;
  gap: 0.55rem;
  pointer-events: auto;
}

.sidebar-group {
  margin: 0;
  padding: 0.55rem 0.62rem 0.62rem;
  border-radius: 12px;
  border: 1px solid rgba(167, 206, 255, 0.35);
  background: linear-gradient(165deg, rgba(11, 22, 39, 0.95), rgba(10, 20, 35, 0.82));
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(4px);
}

.sidebar-group legend {
  padding: 0 0.38rem;
  color: #dce9ff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sidebar-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.42rem;
  color: #d6e4fa;
  font-size: 0.84rem;
  line-height: 1.2;
  cursor: pointer;
}

.sidebar-option input[type="radio"],
.sidebar-option input[type="checkbox"] {
  margin: 0;
  accent-color: #74d6ff;
}

.sidebar-option code {
  font-size: 0.76rem;
  color: #9ec5ee;
}

#full-code-panel {
  position: absolute;
  right: 0.85rem;
  bottom: 188px;
  z-index: 8;
  width: min(390px, calc(100vw - 1.7rem));
  display: none;
  gap: 0.48rem;
  padding: 0.52rem;
  border-radius: 14px;
  border: 1px solid rgba(173, 211, 255, 0.34);
  background: linear-gradient(160deg, rgba(11, 21, 38, 0.89), rgba(11, 23, 41, 0.74));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.37);
  backdrop-filter: blur(3px);
  pointer-events: auto;
}

#full-code-panel.is-visible {
  display: grid;
}

.full-code-title {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #dbe8ff;
}

.full-code-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 0.52rem;
}

.full-code-sphere-card {
  display: grid;
  gap: 0.34rem;
}

.full-code-sphere-label {
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: #adc0dd;
  padding-left: 0.18rem;
}

.full-code-sphere-host {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid rgba(173, 201, 231, 0.35);
  background: radial-gradient(circle at 35% 30%, #25364d, #132338 67%, #0e1c30);
  touch-action: none;
}

.full-code-sphere-host canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

#controllers-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  gap: 0.8rem;
  padding: 0.8rem;
  padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(
    to top,
    rgba(3, 8, 17, 0.95) 5%,
    rgba(3, 8, 17, 0.76) 52%,
    rgba(3, 8, 17, 0.12) 100%
  );
  pointer-events: none;
}

#controllers-list {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  pointer-events: auto;
  scrollbar-width: thin;
}

#add-line-btn {
  align-self: center;
  height: fit-content;
  border: 1px solid rgba(102, 209, 255, 0.85);
  border-radius: 999px;
  padding: 0.62rem 1rem;
  background: linear-gradient(135deg, #0f4f6c, #1d7398);
  color: #f8fdff;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 9px 24px rgba(16, 45, 81, 0.45);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

#add-line-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 12px 25px rgba(41, 113, 165, 0.42);
}

.line-controller {
  display: grid;
  flex: 0 0 var(--controller-width);
  width: var(--controller-width);
  gap: 0.45rem;
  padding: 0.52rem;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(165deg, rgba(16, 28, 49, 0.96), var(--panel));
  box-shadow: 0 9px 20px var(--shadow);
  transition: border-color 110ms ease, box-shadow 110ms ease, transform 110ms ease;
}

.line-controller:hover {
  border-color: rgba(176, 224, 255, 0.58);
}

.line-controller.is-hovered {
  border-color: #ffd77f;
  box-shadow: 0 0 0 2px rgba(255, 215, 127, 0.45), 0 10px 20px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.line-controller-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.line-title {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.line-meta {
  font-size: 0.74rem;
  color: var(--muted);
}

.sphere-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(104px, 1fr));
  gap: 0.5rem;
}

.sphere-card {
  display: grid;
  gap: 0.35rem;
}

.sphere-label {
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding-left: 0.2rem;
}

.sphere-host {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(165, 197, 255, 0.22);
  background: radial-gradient(circle at 36% 28%, #243b5a, #11233e 65%, #0d1a31);
  touch-action: none;
}

.sphere-host canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.controller-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.color-row {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

input[type="color"] {
  width: 2.1rem;
  height: 1.5rem;
  border: none;
  background: transparent;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
}

.delete-btn {
  border: 1px solid rgba(255, 109, 92, 0.7);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  background: linear-gradient(140deg, rgba(72, 29, 31, 0.88), rgba(129, 36, 45, 0.86));
  color: #ffd8d3;
  font-size: 0.77rem;
  font-weight: 650;
  cursor: pointer;
}

.delete-btn:hover {
  filter: brightness(1.08);
}

@media (max-width: 920px) {
  :root {
    --controller-width: clamp(240px, 34vw, 280px);
  }

  .line-controller {
    border-radius: 14px;
  }

  #add-line-btn {
    padding: 0.56rem 0.82rem;
  }
}

@media (max-width: 700px) {
  :root {
    --controller-width: min(270px, calc(100vw - 4.4rem));
  }

  #controllers-bar {
    gap: 0.5rem;
    padding: 0.55rem;
    padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }

  #sidebar {
    top: 0.55rem;
    left: 0.55rem;
    width: min(220px, calc(100vw - 1.1rem));
  }

  #full-code-panel {
    right: 0.55rem;
    width: min(330px, calc(100vw - 1.1rem));
    padding: 0.46rem;
    border-radius: 12px;
  }

  .full-code-grid {
    gap: 0.4rem;
  }

  .sidebar-group {
    padding: 0.5rem 0.55rem 0.55rem;
  }

  .sidebar-option {
    font-size: 0.8rem;
  }

  .line-controller {
    padding: 0.5rem;
    border-radius: 13px;
  }

  .sphere-grid {
    gap: 0.45rem;
  }

  .controller-actions {
    gap: 0.5rem;
  }
}
