* {
  box-sizing: border-box;
}

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

html {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #101820;
  color: #f8fafc;
  font-family: Calibri, "Helvetica Neue", Arial, sans-serif;
}

.app {
  --camera-opacity: 0.78;
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 420px;
  background:
    radial-gradient(circle at 20% 0%, rgba(22, 163, 74, 0.2), transparent 30%),
    linear-gradient(160deg, #0f172a 0%, #111827 45%, #172554 100%);
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

.camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0f172a;
  z-index: 1;
  opacity: var(--camera-opacity);
}

.camera-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.96));
  color: rgba(248, 250, 252, 0.88);
  padding: 18px;
  font-size: clamp(1rem, 2.6vw, 1.35rem);
  letter-spacing: 0;
}

.camera-fallback[hidden] {
  display: none;
}

.camera-card {
  display: grid;
  gap: 14px;
  justify-items: center;
  max-width: min(420px, 100%);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.7);
  text-align: center;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
}

.camera-card p {
  margin: 0;
}

.camera-start {
  min-height: 40px;
  min-width: 128px;
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 6px;
  background: #bae6fd;
  color: #075985;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.camera-start:hover {
  background: #e0f2fe;
}

.dial {
  --dial-size: min(46vmin, 430px);
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: var(--dial-size);
  height: var(--dial-size);
  transform: translate(-50%, -50%);
  touch-action: none;
  cursor: move;
  user-select: none;
}

.app:not(.is-camera-on) .dial {
  display: none;
}

.dial-canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: none;
}

.dial-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(14, 165, 233, 0.95);
  box-shadow:
    0 0 0 4px rgba(14, 165, 233, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.resize-handle {
  position: absolute;
  top: 50%;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  cursor: ew-resize;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.36);
}

.dial[data-side="right"] .resize-handle {
  right: -10px;
  left: auto;
  transform: translate(50%, -50%);
}

.dial[data-side="left"] .resize-handle {
  left: -10px;
  right: auto;
  transform: translate(-50%, -50%);
}

.resize-handle::before,
.resize-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border-top: 2px solid rgba(255, 255, 255, 0.92);
  border-left: 2px solid rgba(255, 255, 255, 0.92);
}

.resize-handle::before {
  left: 6px;
  transform: translateY(-50%) rotate(-45deg);
}

.resize-handle::after {
  right: 6px;
  transform: translateY(-50%) rotate(135deg);
}

.resize-handle {
  background:
    linear-gradient(
      rgba(255, 255, 255, 0.92),
      rgba(255, 255, 255, 0.92)
    ) center / 12px 2px no-repeat,
    rgba(15, 23, 42, 0.72);
}

.controls {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  width: max-content;
  max-width: calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right));
  margin: 0 auto;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.46);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
}

.app:not(.is-camera-on) .controls {
  display: none;
}

.control {
  min-width: 66px;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.78);
  color: #0f172a;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
}

.control:hover {
  background: #fff;
}

.control.is-active {
  border-color: rgba(56, 189, 248, 0.72);
  background: rgba(186, 230, 253, 0.86);
  color: #075985;
}

.control.is-danger {
  background: rgba(254, 226, 226, 0.88);
  color: #991b1b;
}

.control.is-recording {
  background: rgba(187, 247, 208, 0.9);
  color: #166534;
}

.control[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.opacity-control {
  display: inline-grid;
  grid-template-columns: auto minmax(74px, 9vw);
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(248, 250, 252, 0.92);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.opacity-control input {
  width: 100%;
  accent-color: #bae6fd;
}

@media (max-width: 560px) {
  .app {
    min-height: 100svh;
    min-height: 100dvh;
  }

  .dial {
    --dial-size: clamp(210px, 68vw, 300px);
  }

  .resize-handle {
    width: 34px;
    height: 34px;
  }

  .dial[data-side="right"] .resize-handle {
    right: -14px;
  }

  .dial[data-side="left"] .resize-handle {
    left: -14px;
  }

  .resize-handle::before,
  .resize-handle::after {
    width: 8px;
    height: 8px;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: auto;
    max-width: none;
    padding: 5px;
    gap: 5px;
  }

  .control {
    min-width: 0;
    min-height: 38px;
    padding-inline: 6px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .opacity-control {
    grid-column: span 6;
    order: 4;
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 34px;
    padding-inline: 9px;
  }

  #left-btn,
  #right-btn,
  #camera-off-btn {
    grid-column: span 2;
  }

  #left-btn {
    order: 1;
  }

  #right-btn {
    order: 2;
  }

  #camera-off-btn {
    order: 3;
  }

  #record-btn,
  #screenshot-btn {
    grid-column: span 3;
  }

  #record-btn {
    order: 5;
  }

  #screenshot-btn {
    order: 6;
  }
}

@media (max-width: 360px) {
  .control {
    font-size: 0.68rem;
    padding-inline: 4px;
  }

  .opacity-control {
    font-size: 0.68rem;
  }
}
