/* iOS自動ズーム回避 */
#screen-setup input,
#screen-setup select,
#screen-setup textarea {
  font-size: 17px !important;
}

/* ダブルタップ拡大防止 */
#screen-setup {
  touch-action: manipulation;
}

/* レイアウト調整 */
#screen-setup .card {
  max-width: 720px;
  margin: 0 auto;
}

html, body {
  overflow-x: hidden;
}

/* CSS変数定義 */
:root {
  --bg: #0b0f1a;
  --panel: #0e1526;
  --ink: #e6edf7;
  --muted: #9fb3c8;
  --brand: #3b82f6;
  --line: #1f2a44;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
}

/* リセット */
* {
  box-sizing: border-box;
}

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

body {
  margin-top: 20px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  -webkit-text-size-adjust: 100%;
}

/* レイアウト */
.wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
   margin-top: 25px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(11, 15, 26, .85);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}

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

/* ヘッダーロゴ */
.ttl .header-logo {
  height: 30px !important;
  width: auto !important;
  max-width: 150px !important;
  vertical-align: middle;
  display: inline-block;
  object-fit: contain;
}

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

.user-info {
  color: var(--muted);
  font-size: 14px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

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

.end-btn {
  border: 1px solid var(--danger);
  color: #fecaca;
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  display: none;
}

.install-btn {
  border: 1px solid var(--line);
  color: #dbeafe;
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  display: none;
}

main {
  flex: 1;
  display: grid;
}

.panel {
  padding: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

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

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

label {
  font-size: 13px;
  color: var(--muted);
  display: block;
}

input, select, button {
  font-size: 16px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--ink);
  width: 100%;
}

/* ボタン */
.btn {
  width: 100%;
  cursor: pointer;
}

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

.btn.success {
  background: var(--ok);
  color: #022;
}

.btn.warn {
  background: var(--warn);
  color: #220;
}

.btn.ghost {
  background: transparent;
}

/* 撮影画面 */
body.fullscreen header {
  display: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  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) + 10px);
  left: 10px;
  z-index: 3;
}

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

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

.bottom-center .btn {
  padding: 14px 24px;
  font-size: 18px;
  border-radius: 999px;
  width: auto;
}

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

.count {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-size: 64px;
  font-weight: 800;
  background: rgba(0, 0, 0, .35);
}

.time {
  position: absolute;
  top: 8px;
  right: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, .35);
  padding: 6px 10px;
  border-radius: 12px;
  display: none;
}

#mixCanvas {
  display: none;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--ink);
}

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

.lens-btn {
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .3);
  cursor: pointer;
}

/* フォーカスインジケーター */
.focus-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid #fff;
  border-radius: 8px;
  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 {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  place-items: center;
  z-index: 999;
}

.loading-content {
  text-align: center;
  color: #fff;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

.loading-text {
  font-size: 16px;
  margin-top: 12px;
}

/* iOS Safari専用の修正 */
@supports (-webkit-touch-callout: none) {
  .ttl .header-logo {
    height: 28px !important;
    max-height: 28px !important;
    width: auto !important;
    max-width: 140px !important;
  }
  
  .bar .ttl {
    padding: 8px 0;
  }
  
  .panel {
    -webkit-overflow-scrolling: touch;
  }
  
  .card {
    min-height: 0;
    -webkit-transform: translateZ(0);
  }
  
  input, select, textarea {
    -webkit-appearance: none;
    appearance: none;
  }
  
  #screen-setup .card {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 14px;
  }
}

/* スマートフォン対応 */
@media (max-width: 480px) {
  .ttl .header-logo {
    height: 24px !important;
    max-width: 120px !important;
  }
  
  .header-actions {
    font-size: 12px;
  }
  
  .user-info {
    font-size: 12px;
    padding: 4px 10px;
  }
  
  .btn-link {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* タッチデバイス最適化 */
@media (hover: none) {
  .btn-link:hover {
    background: transparent;
    color: var(--brand);
  }
  
  .btn-link:active {
    background: var(--brand);
    color: white;
  }
}
/* QRモーダル */
.qr-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  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: 24px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  position: relative;
  display: grid;
  gap: 20px;
  place-items: center;
}

.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: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition: all 0.2s ease;
}

.qr-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

.qr-modal-qr {
  border-radius: 12px;
  background: white;
  padding: 16px;
}

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

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

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

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

/* スマートフォン対応 */
@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: 12px;
  }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
  .qr-modal {
    background: rgba(0, 0, 0, 0.9);
  }
}

/* アクセシビリティ: 動きを減らす設定 */
@media (prefers-reduced-motion: reduce) {
  .qr-modal-close {
    transition: none;
  }
}