/* ===== Spinap360 Station Mode — Premium Dark Design ===== */

/* ===== Design Tokens ===== */
:root {
  --st-bg: #0a0a0f;
  --st-surface: #141419;
  --st-surface-2: #1c1c24;
  --st-surface-3: #24242e;
  --st-ink: #f0f0f5;
  --st-muted: #8888a0;
  --st-brand: #6366f1;
  --st-brand-glow: rgba(99, 102, 241, 0.35);
  --st-accent: #818cf8;
  --st-ok: #34d399;
  --st-line: rgba(255, 255, 255, 0.08);
  --st-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --st-radius: 20px;
  --st-radius-sm: 12px;
  --st-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%; width: 100%; margin: 0; padding: 0;
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  background: var(--st-bg);
  color: var(--st-ink);
}

/* ===== Screen Container ===== */
.screen { position: fixed; inset: 0; display: none; z-index: 1; }
.screen.active { display: flex; }

/* ===== Standby Screen ===== */
#screen-standby {
  align-items: center; justify-content: center; flex-direction: column;
}

.standby-bg { position: absolute; inset: 0; overflow: hidden; z-index: 0; }
.standby-orbs { position: absolute; inset: 0; }

.orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.4;
  animation: orbFloat 12s ease-in-out infinite;
}
.orb-1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--st-brand) 0%, transparent 70%);
  top: -100px; right: -100px;
}
.orb-2 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
  bottom: -80px; left: -80px; animation-delay: -4s;
}
.orb-3 {
  width: 250px; height: 250px;
  background: radial-gradient(circle, #06b6d4 0%, transparent 70%);
  top: 50%; left: 50%; transform: translate(-50%, -50%); animation-delay: -8s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -20px) scale(1.1); }
  50% { transform: translate(-20px, 30px) scale(0.95); }
  75% { transform: translate(20px, 20px) scale(1.05); }
}

.standby-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 32px; text-align: center; padding: 40px;
}

.station-header { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.station-logo { height: 36px; width: auto; opacity: 0.9; }

.station-badge {
  display: inline-flex; align-items: center;
  padding: 6px 16px;
  background: var(--st-brand-glow);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: 2px;
  color: var(--st-accent); text-transform: uppercase;
}

/* ===== Standby Event Name (Editable) ===== */
.standby-event-name-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.standby-event-name {
  font-size: 32px; font-weight: 800; color: var(--st-ink);
  letter-spacing: -0.5px; outline: none;
  border-bottom: 2px solid transparent;
  padding: 4px 8px; border-radius: 6px;
  transition: all 0.2s; cursor: text;
  min-width: 120px; text-align: center;
}
.standby-event-name:focus {
  border-bottom-color: var(--st-brand);
  background: rgba(255, 255, 255, 0.05);
}
.edit-hint { font-size: 12px; color: var(--st-muted); opacity: 0.6; transition: opacity 0.2s; }
.standby-event-name-wrap:hover .edit-hint,
.standby-event-name:focus ~ .edit-hint { opacity: 1; }

/* ===== Standby Message ===== */
.standby-message {
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; position: relative;
}

.pulse-ring {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 160px; height: 160px; border-radius: 50%;
  border: 2px solid var(--st-brand); opacity: 0;
  animation: pulseRing 3s ease-out infinite;
}
@keyframes pulseRing {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0.6; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

.standby-icon {
  width: 96px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  background: var(--st-surface-2);
  border: 1px solid var(--st-line); border-radius: 50%;
  color: var(--st-accent);
  animation: gentleBounce 4s ease-in-out infinite;
}
@keyframes gentleBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.standby-text { font-size: 22px; font-weight: 600; color: var(--st-ink); margin: 0; }
.standby-sub { font-size: 15px; color: var(--st-muted); margin: 0; max-width: 400px; line-height: 1.6; }

.standby-status {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; background: var(--st-surface);
  border: 1px solid var(--st-line); border-radius: 999px;
  font-size: 13px; color: var(--st-muted);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--st-ok);
  animation: statusBlink 2s ease-in-out infinite;
}
@keyframes statusBlink {
  0%, 100% { opacity: 1; } 50% { opacity: 0.4; }
}

.exit-btn {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  left: 50%; transform: translateX(-50%);
  padding: 12px 28px; background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px; color: var(--st-muted);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all var(--st-transition); z-index: 10;
}
.exit-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.25); color: var(--st-ink);
}

/* ========================================
   Preview Screen — 3-Panel Layout
   [Effects | Video | QR + Actions]
======================================== */
#screen-preview { background: var(--st-bg); }

.preview-layout {
  display: flex; width: 100%; height: 100%;
}

/* --- 左パネル: エフェクト選択 --- */
.preview-effects-panel {
  width: 180px; min-width: 160px;
  background: var(--st-surface);
  border-right: 1px solid var(--st-line);
  display: flex; flex-direction: column;
  padding: 16px 10px;
  overflow-y: auto;
}

.effects-header {
  font-size: 13px; font-weight: 700; color: var(--st-muted);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 0 6px 12px; border-bottom: 1px solid var(--st-line);
  margin-bottom: 8px;
}

.effects-list {
  display: flex; flex-direction: column; gap: 6px;
}

.effect-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px; width: 100%;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--st-radius-sm);
  cursor: pointer; transition: all var(--st-transition);
  -webkit-tap-highlight-color: transparent;
  text-align: left;
}
.effect-btn:hover { background: var(--st-surface-2); }
.effect-btn:active { transform: scale(0.97); }

.effect-btn.active {
  border-color: var(--st-brand);
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 0 12px var(--st-brand-glow);
}

.effect-icon { font-size: 20px; line-height: 1; flex-shrink: 0; }
.effect-name {
  font-size: 12px; font-weight: 600; color: var(--st-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.effect-btn.active .effect-name { color: var(--st-accent); }

/* --- 中央: 動画 --- */
.preview-video-area {
  flex: 1; position: relative;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}

#stationVideo {
  width: 100%; height: 100%;
  object-fit: contain; background: #000;
}

.video-loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 5;
  gap: 16px;
}

.video-loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--st-brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.video-loading-text {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.video-overlay-info {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px;
  display: flex; flex-direction: column; gap: 4px; z-index: 2;
}
.video-event-name {
  font-size: 14px; font-weight: 700; color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 5px 12px; border-radius: 999px; display: inline-block;
}
.video-timestamp {
  font-size: 11px; color: rgba(255, 255, 255, 0.7); padding-left: 12px;
}

/* --- 右パネル: QR + アクション --- */
.preview-actions-panel {
  width: 260px; min-width: 220px;
  background: var(--st-surface);
  border-left: 1px solid var(--st-line);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; gap: 24px;
}

.qr-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
}

.qr-section canvas {
  background: #fff; padding: 12px;
  border-radius: var(--st-radius-sm);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.qr-label {
  font-size: 13px; color: var(--st-muted);
  text-align: center; margin: 0;
}

.actions-section {
  display: flex; flex-direction: column;
  gap: 10px; width: 100%;
}

/* ===== Station Buttons ===== */
.btn-station {
  width: 100%; padding: 12px 20px;
  border-radius: var(--st-radius-sm);
  border: none; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all var(--st-transition);
}
.btn-station.primary {
  background: var(--st-brand); color: #fff;
  box-shadow: 0 4px 16px var(--st-brand-glow);
}
.btn-station.primary:hover { box-shadow: 0 6px 24px var(--st-brand-glow); transform: translateY(-1px); }
.btn-station.primary:active { transform: scale(0.98); }
.btn-station.share {
  background: rgba(255, 255, 255, 0.08); color: var(--st-ink);
  border: 1px solid var(--st-line);
}
.btn-station.share:hover { background: rgba(255, 255, 255, 0.14); }
.btn-station.share:active { transform: scale(0.98); }
.btn-station:disabled { opacity: 0.5; pointer-events: none; }

/* 反映ボタン */
.btn-station.apply {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff; font-weight: 700;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.3);
}
.btn-station.apply:hover {
  box-shadow: 0 6px 24px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}
.btn-station.apply:active { transform: scale(0.98); }

/* レンダリング進捗バー */
.render-progress {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 0;
}
.render-progress-bar {
  width: 100%; height: 6px;
  background: var(--st-surface-3);
  border-radius: 999px; overflow: hidden;
}
.render-progress-fill {
  width: 0%; height: 100%;
  background: linear-gradient(90deg, var(--st-brand), var(--st-accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.render-progress-text {
  font-size: 12px; color: var(--st-muted); text-align: center;
}

/* 反映済みバッジ */
.btn-station.share.rendered {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

/* ===== Toast ===== */
.toast-notification {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 20px);
  left: 50%; transform: translateX(-50%) translateY(-120px);
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  background: var(--st-surface-2);
  border: 1px solid var(--st-brand);
  border-radius: var(--st-radius-sm);
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast-notification.show { transform: translateX(-50%) translateY(0); }
.toast-icon { color: var(--st-accent); display: flex; flex-shrink: 0; }
.toast-text { font-size: 15px; font-weight: 600; color: var(--st-ink); white-space: nowrap; }

/* ===== Portrait Mode ===== */
@media (orientation: portrait) {
  .preview-layout { flex-direction: column; }

  .preview-effects-panel {
    width: 100%; min-width: unset; height: auto;
    flex-direction: row; align-items: center;
    border-right: none; border-bottom: 1px solid var(--st-line);
    padding: 8px 12px; overflow-x: auto; overflow-y: hidden;
    order: 2;
  }

  .effects-header { display: none; }

  .effects-list {
    flex-direction: row; gap: 6px;
    flex-wrap: nowrap;
  }

  .effect-btn {
    flex-direction: column; gap: 2px;
    padding: 6px 8px; min-width: 64px;
    align-items: center; text-align: center;
  }

  .effect-icon { font-size: 18px; }
  .effect-name { font-size: 10px; }

  .preview-video-area { flex: 1; min-height: 0; order: 1; }

  .preview-actions-panel {
    width: 100%; min-width: unset; height: auto;
    flex-direction: row; justify-content: center;
    align-items: center;
    border-left: none; border-top: 1px solid var(--st-line);
    padding: 16px; gap: 16px; order: 3;
  }

  .qr-section canvas { width: 100px !important; height: 100px !important; padding: 8px; }

  .actions-section { flex: 1; }

  .standby-event-name { font-size: 24px; }
}

/* ===== Small Screen ===== */
@media (max-width: 600px) {
  .standby-content { gap: 24px; padding: 24px; }
  .standby-event-name { font-size: 20px; }
  .standby-text { font-size: 18px; }
  .standby-sub { font-size: 13px; }
  .station-logo { height: 28px; }
}

/* ===== iOS Safari Fixes ===== */
@supports (-webkit-touch-callout: none) {
  .screen { min-height: -webkit-fill-available; }
}

/* ===== Landscape iPad ===== */
@media (min-width: 1024px) and (orientation: landscape) {
  .preview-effects-panel { width: 200px; }
  .preview-actions-panel { width: 300px; }
  .effect-btn { padding: 12px 10px; }
  .effect-name { font-size: 13px; }
  .qr-section canvas { width: 220px !important; height: 220px !important; }
  .standby-event-name { font-size: 40px; }
  .standby-text { font-size: 26px; }
  .standby-icon { width: 120px; height: 120px; }
  .standby-icon svg { width: 56px; height: 56px; }
}
