/* ===== Spinap360 Shooting Station — Refined Light Design ===== */

/* iOS auto-zoom prevention */
#screen-setup input,
#screen-setup select,
#screen-setup textarea {
  font-size: 17px !important;
}

/* Double-tap zoom prevention */
#screen-setup {
  touch-action: manipulation;
}

/* Layout constraint */
#screen-setup .card {
  max-width: 560px;
  margin: 0 auto;
}

html,
body {
  overflow-x: hidden;
}

/* ===== Design Tokens ===== */
:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1a1d26;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-light: #dbeafe;
  --line: #e2e5eb;
  --ok: #059669;
  --ok-light: #d1fae5;
  --warn: #d97706;
  --warn-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */
.wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.ttl {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  min-height: 40px;
}

/* Header Logo */
.ttl .header-logo {
  height: 28px !important;
  width: auto !important;
  max-width: 140px !important;
  vertical-align: middle;
  display: inline-block;
  object-fit: contain;
  /* Invert for light background */
  filter: invert(1) brightness(0.15);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-info {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
}

.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius-full);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-link:hover {
  background: var(--brand);
  color: #fff;
}

.end-btn {
  border: 1px solid var(--danger);
  color: var(--danger);
  background: transparent;
  border-radius: var(--radius-full);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: none;
  transition: all var(--transition);
}

.end-btn:hover {
  background: var(--danger-light);
}

.install-btn {
  border: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  border-radius: var(--radius-full);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: none;
  transition: all var(--transition);
}

.install-btn:hover {
  background: var(--bg);
}

main {
  flex: 1;
  display: grid;
}

/* ===== Panel / Card ===== */
.panel {
  padding: 20px 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.grid {
  display: grid;
  gap: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ===== Form Elements ===== */
label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

/* ===== Checkbox Field ===== */
#screen-setup .checkbox-field {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  min-height: 48px;
}

#screen-setup .checkbox-field input[type="checkbox"] {
  -webkit-appearance: checkbox !important;
  appearance: checkbox !important;
  width: 22px !important;
  height: 22px !important;
  min-width: 22px;
  min-height: 22px;
  margin: 0 !important;
  padding: 0 !important;
  cursor: pointer;
  accent-color: var(--brand);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.checkbox-field span {
  pointer-events: none;
}

input:not([type="checkbox"]):not([type="file"]):not([type="range"]),
select {
  font-size: 16px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input[type="file"] {
  font-size: 14px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
}

input:not([type="checkbox"]):focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

button {
  font-size: 16px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  width: 100%;
  cursor: pointer;
  transition: all var(--transition);
}

/* ===== Buttons ===== */
.btn {
  width: 100%;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius-md);
  padding: 13px 20px;
  transition: all var(--transition);
  border: none;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn.primary:hover {
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.btn.primary:disabled {
  background: #93c5fd;
  box-shadow: none;
  cursor: not-allowed;
}

.btn.success {
  background: var(--ok);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}

.btn.success:hover {
  box-shadow: 0 4px 16px rgba(5, 150, 105, 0.35);
}

.btn.warn {
  background: var(--warn);
  color: #fff;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.25);
}

.btn.warn:hover {
  box-shadow: 0 4px 16px rgba(217, 119, 6, 0.35);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.btn.danger:hover {
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.35);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.ghost:hover {
  background: var(--bg);
  border-color: var(--muted);
}


/* ===== Capture Screen ===== */
body.fullscreen header {
  display: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #0a0a0a;
  overflow: hidden;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

#preview.mirror {
  transform: scaleX(-1);
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
  pointer-events: none;
}

.top-left {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  z-index: 3;
}

.top-left .btn {
  padding: 10px 16px;
  font-size: 13px;
  border-radius: var(--radius-full);
  width: auto;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.top-right {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 12px;
  z-index: 3;
}

.bottom-center {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
}

.bottom-center .btn {
  padding: 16px 36px;
  font-size: 17px;
  border-radius: var(--radius-full);
  width: auto;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.overlay-hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.count {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-size: 72px;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.time {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: rgba(220, 38, 38, 0.85);
  padding: 6px 16px;
  border-radius: var(--radius-full);
  display: none;
  letter-spacing: 0.5px;
  animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

#mixCanvas {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ===== Setup Screen Groups ===== */
.setup-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 0;
  display: grid;
  gap: 12px;
}

.setup-group legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 6px;
}

.setup-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.setup-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 0;
}

.setup-item .setup-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.setup-item select,
.setup-item input[type="number"] {
  padding: 8px 10px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  width: 100%;
}

.setup-row-2 {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.bgm-vol-label {
  min-width: 90px;
}

.flex-grow {
  flex: 1;
  min-width: 0;
}

.setup-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.setup-footer-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  font-size: 13px !important;
  padding: 8px 16px !important;
  text-decoration: none;
  color: var(--muted) !important;
}

.lens-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 44px;
  text-align: center;
}

.lens-btn.lens-active {
  background: rgba(255, 255, 255, 0.95);
  color: var(--brand);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.lens-btn:active {
  transform: scale(0.92);
}

#lensSelector {
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 4px;
  border-radius: var(--radius-full);
}

/* ===== Focus Ring ===== */
.focus-ring {
  position: absolute;
  width: 72px;
  height: 72px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 4;
  display: none;
  animation: focusAnim 0.3s ease-out;
}

@keyframes focusAnim {
  0% {
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0;
  }

  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  place-items: center;
  z-index: 999;
}

.loading-content {
  text-align: center;
  color: var(--ink);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
}

/* ===== iOS Safari Fixes ===== */
@supports (-webkit-touch-callout: none) {
  .ttl .header-logo {
    height: 26px !important;
    max-height: 26px !important;
    width: auto !important;
    max-width: 130px !important;
  }

  .bar .ttl {
    padding: 6px 0;
  }

  .panel {
    -webkit-overflow-scrolling: touch;
  }

  .card {
    min-height: 0;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    -webkit-appearance: none;
    appearance: none;
  }

  #screen-setup .card {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 20px;
  }
}

/* ===== Mobile ===== */
@media (max-width: 480px) {
  .ttl .header-logo {
    height: 22px !important;
    max-width: 110px !important;
  }

  .header-actions {
    font-size: 12px;
    gap: 6px;
  }

  .user-info {
    font-size: 11px;
    padding: 4px 10px;
  }

  .btn-link {
    font-size: 11px;
    padding: 6px 12px;
  }

  .card {
    padding: 18px;
  }
}

/* ===== Touch Optimization ===== */
@media (hover: none) {
  .btn-link:hover {
    background: transparent;
    color: var(--brand);
  }

  .btn-link:active {
    background: var(--brand);
    color: #fff;
  }

  .btn.primary:hover {
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
  }
}

/* ===== QR Modal ===== */
.qr-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  place-items: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
}

.qr-modal-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 380px;
  width: 100%;
  position: relative;
  display: grid;
  gap: 20px;
  place-items: center;
  box-shadow: var(--shadow-lg);
}

.qr-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.qr-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.qr-modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition: all var(--transition);
}

.qr-modal-close:hover {
  background: var(--line);
  color: var(--ink);
}

.qr-modal-close:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.qr-modal-qr {
  border-radius: var(--radius-md);
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}

.qr-modal-url {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
  max-width: 100%;
}

.qr-modal-url a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}

.qr-modal-url a:hover {
  text-decoration: underline;
}

.qr-modal-actions {
  display: grid;
  gap: 12px;
  width: 100%;
}

/* Mobile QR */
@media (max-width: 480px) {
  .qr-modal {
    padding: 16px;
  }

  .qr-modal-content {
    padding: 24px 20px;
    gap: 16px;
  }

  .qr-modal-title {
    font-size: 16px;
  }

  .qr-modal-close {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }

  .qr-modal-qr {
    padding: 14px;
  }
}

/* ===== Accessibility: Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {

  .qr-modal-close,
  .btn,
  .btn-link,
  input,
  select {
    transition: none;
  }

  .time {
    animation: none;
  }
}

/* ===== Volume Slider ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  outline: none;
  border: none;
  padding: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ===== File Input ===== */
input[type="file"] {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  margin-right: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: all var(--transition);
}

input[type="file"]::file-selector-button:hover {
  background: var(--bg);
  border-color: var(--brand);
  color: var(--brand);
}