:root{
  --bg: #f8f9fa;
  --panel: #ffffff;
  --muted: #6c757d;
  --text: #212529;
  --border: rgba(0,0,0,0.08);
  --primary: #007bff;
}

*{ box-sizing:border-box; }
html{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #e9ecef, #f8f9fa);
  color: var(--text);
  min-height: 100%;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  background: rgba(248,249,250,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.brand{ display:flex; gap:12px; align-items:center; }
.logo{ font-size:28px; }
.title{ font-weight:800; letter-spacing:0.2px; }
.subtitle{ color:var(--muted); font-size:12px; margin-top:2px; }

.container{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:16px;
  padding:16px;
  max-width: 1200px;
  margin: 0 auto;
  height: calc(100vh - 130px);
  overflow: hidden;
}

.panel{
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

.panel::-webkit-scrollbar{
  width: 8px;
}

.panel::-webkit-scrollbar-track{
  background: transparent;
}

.panel::-webkit-scrollbar-thumb{
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

.panel::-webkit-scrollbar-thumb:hover{
  background: rgba(0,0,0,0.35);
}

h2{ margin: 8px 0 16px; font-size: 16px; font-weight: 700; color: var(--text); }

.videoContainer{
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.videoWrap{
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 3px solid var(--border);
  background: linear-gradient(135deg, #1a1a1a 0%, #0d0d0d 100%);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
  width: 420px;
  height: 450px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.videoWrap::before{
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 13px;
  padding: 3px;
  background: linear-gradient(135deg, rgba(0,123,255,0.1), rgba(0,123,255,0.05));
  pointer-events: none;
  z-index: 1;
}

video{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  position: relative;
  z-index: 2;
}

.countdown{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  font-weight: 900;
  background: rgba(0,0,0,0.6);
  color: #fff;
  text-shadow: 0 4px 12px rgba(0,0,0,0.9), 0 0 20px rgba(0,123,255,0.3);
  z-index: 10;
  animation: countdownPulse 0.6s ease-in-out;
  font-family: 'Courier New', monospace;
}

@keyframes countdownPulse {
  0% { transform: scale(0.5); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.hidden{ display:none; }

.row{
  display:flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 18px;
  align-items: flex-end;
}

.field{
  display:flex;
  flex-direction:column;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  min-width: 200px;
  flex: 1;
}

select{
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.04);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

select:hover{
  border-color: rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.06);
}

select:focus{
  outline: none;
  border-color: var(--primary);
  background: rgba(0,123,255,0.02);
}

input[type="range"]{
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(0,0,0,0.08);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,123,255,0.3);
  transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0,123,255,0.5);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(0,123,255,0.3);
  transition: all 0.2s ease;
}

.toggle{
  display:flex;
  gap:10px;
  align-items:center;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.04);
  color: var(--text);
  user-select:none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  font-size: 14px;
}

.toggle:hover{
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.12);
}

.btn{
  padding: 11px 18px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: rgba(0,0,0,0.04);
  color: var(--text);
  cursor:pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.25s ease;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:hover{
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.btn:active{ transform: translateY(0px); }

.btn-primary{
  background: linear-gradient(135deg, rgba(0,123,255,0.15), rgba(0,123,255,0.1));
  border-color: rgba(0,123,255,0.5);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,123,255,0.15);
}

.btn-primary:hover{
  background: linear-gradient(135deg, rgba(0,123,255,0.22), rgba(0,123,255,0.18));
  border-color: rgba(0,123,255,0.6);
  box-shadow: 0 4px 12px rgba(0,123,255,0.25);
}

.btn-secondary{
  background: rgba(108,117,125,0.12);
  border-color: rgba(108,117,125,0.3);
  color: var(--text);
}

.btn-secondary:hover{
  background: rgba(108,117,125,0.2);
  border-color: rgba(108,117,125,0.4);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-ghost{
  background: transparent;
  border-color: rgba(0,0,0,0.1);
}

.btn-ghost:hover{
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.15);
}

.hint{
  color: var(--muted);
  font-size: 12px;
  margin-top: 10px;
  line-height: 1.4;
}

.frameList{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.frameItem{
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(0,0,0,0.03);
  padding: 4px;
  transition: all 0.2s ease;
  aspect-ratio: 1;
}

.frameItem:hover{
  border-color: rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.06);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.frameItem img{
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  object-fit: cover;
}

.frameItem.active{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,123,255,0.15), 0 2px 8px rgba(0,123,255,0.2);
}

hr{
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
  flex-shrink: 0;
}

.canvasWrap{
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #f8f9fa;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
  flex-shrink: 0;
  margin-bottom: 16px;
  max-width: 100%;
}

canvas{
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  background: transparent;
  display: block;
}


.note{
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.footer{
  padding: 18px;
  color: var(--muted);
  text-align:center;
  font-size: 12px;
}

@media (max-width: 900px){
  .container{
    grid-template-columns: 1fr;
    min-height: auto;
    max-height: none;
    height: auto;
    overflow: visible;
  }
  .panel{
    min-height: auto;
    max-height: none;
    height: auto;
  }
  .videoWrap{
    width: 100%;
    max-width: 420px;
    height: auto;
    aspect-ratio: 420 / 450;
  }
  .videoContainer{
    margin-bottom: 16px;
  }
}
html, body { height: 100%; }
body { touch-action: manipulation; }
.topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
.footer { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
.btn { min-height: 44px; } /* touch friendly */
