/* Object Detection AR specific styles. Layered on top of styles.css. */

.obj-body { background: #000; }

#bg-video {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: contain;        /* letterbox to preserve aspect, like Three.js _fitBackground */
  background: #000;
  z-index: 0;
  pointer-events: none;
  transform-origin: center center;
  transition: opacity 0.1s linear;
}

#bg-video.hidden-cam { visibility: hidden; }

.focus-roi-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.focus-roi-box {
  position: absolute;
  border: 2px solid rgba(0, 209, 178, 0.95);
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 18px rgba(0, 209, 178, 0.35);
  background: linear-gradient(
    135deg,
    rgba(0, 209, 178, 0.12),
    rgba(100, 181, 255, 0.04)
  );
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.focus-roi-corner::before,
.focus-roi-corner::after,
.focus-roi-dot,
.focus-roi-resize {
  content: "";
  position: absolute;
  display: block;
}

.focus-roi-corner::before {
  left: 8px;
  top: 8px;
  width: 22px;
  height: 22px;
  border-left: 3px solid #fff;
  border-top: 3px solid #fff;
}

.focus-roi-corner::after {
  right: 8px;
  bottom: 8px;
  width: 22px;
  height: 22px;
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
}

.focus-roi-dot {
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00d1b2;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.65);
}

.focus-roi-resize {
  right: -11px;
  bottom: -11px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.75);
  background:
    linear-gradient(135deg, transparent 0 45%, #001a15 45% 55%, transparent 55%),
    #00d1b2;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
  cursor: nwse-resize;
  pointer-events: auto;
}

/* Overlay container mirrors together with the video so detection boxes
   stay aligned. Labels counter-flip so they stay readable. */
.overlay-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  /* The inner "stage" div (created in JS) is sized to match the video's
     displayed rect (object-fit: contain aware), and boxes are positioned
     inside it in percent coordinates. */
}

.overlay-layer .stage {
  position: absolute;
  overflow: visible;
  transform-origin: center center;
}
/* Mirror は JS で transform を直接設定する。zoom は video の実表示矩形から stage サイズへ反映する。 */

/* Canvas は stage の全面。ビットマップサイズは JS で DPR に合わせて設定する。
   コンポジット層を増やさず、毎フレーム clear+draw しても GPU 負荷が低い。 */
.det-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ラベル層は stage の全面に絶対配置。個々のラベルは % 座標で bbox 左上に置く。 */
.det-label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.det-label {
  position: absolute;
  transform-origin: left top;
  background: #00d1b2;
  color: #001a15;
  font: 600 12px/1.25 ui-monospace, Menlo, Consolas, monospace;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  /* 矩形左上 (percent) に置いたあと、少し上に持ち上げる */
  margin-top: -1.55em;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 150ms linear;
}

.start-camera-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px auto 8px;
}
.start-camera-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.start-camera-picker select {
  max-width: min(62vw, 280px);
  background: #111;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
}
#camera-refresh-btn {
  flex: 0 0 auto;
}
#start-xreal-btn {
  display: block;
  margin: 8px auto 0;
  padding: 8px 14px;
  font-size: 13px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

/* Extra HUD bits. */
.debug-log-title {
  margin-top: 6px;
  color: #aaa;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.debug-log {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 180px;
  overflow: hidden;
}
.debug-log li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
  padding: 1px 0;
}
.debug-log li .name { color: #00d1b2; }
.debug-log li .score { color: #ddd; }

.hud label span {
  display: inline-block;
  min-width: 2.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #ccc;
}

.hud-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  pointer-events: auto;
}

.hud-row {
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms linear;
}

.hud.controls-hidden .hud-row {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
}

.hud.controls-hidden .debug {
  margin-top: 0;
}

.hud-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-ui {
  position: relative;
  width: 38px;
  height: 22px;
  min-width: 38px;
  border-radius: 999px;
  background: #333;
  border: 1px solid #555;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ccc;
  transition: transform 0.15s ease, background 0.15s ease;
}
.hud-switch input:checked + .switch-ui {
  background: #1e755f;
  border-color: #00d1b2;
}
.hud-switch input:checked + .switch-ui::after {
  transform: translateX(16px);
  background: #fff;
}
.hud-switch input:disabled + .switch-ui {
  opacity: 0.45;
}

.hud button#settings-btn {
  padding: 6px 10px;
  font-size: 16px;
  pointer-events: auto;
}

/* フルスクリーンボタンは右端に寄せる */
.hud button#fullscreen-btn {
  margin-left: auto;
  padding: 6px 10px;
  font-size: 16px;
  pointer-events: auto;
}

.xreal-btn {
  background: #1e3a5f;
  border-color: #3b7bbd;
}
.xreal-btn:hover { background: #28507f; }

/* XREAL 関連モーダル (Eye 未接続 / 再接続) */
#xreal-eye-modal .panel,
#xreal-reconnect-modal .panel {
  max-width: 480px;
  text-align: center;
}
#xreal-eye-modal h2,
#xreal-reconnect-modal h2 {
  margin: 0 0 14px;
  font-size: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

/* Settings dialog (gear icon) */
#settings-dialog { z-index: 25; }

.settings-panel {
  max-width: 480px;
  width: min(90vw, 480px);
  /* スマホ横画面 (高さ ~360px) でも全項目にアクセスできるようパネル自体をスクロール。
     余白込みで画面に収まる範囲を上限にする。 */
  max-height: min(90vh, 560px);
  overflow-y: auto;
  text-align: left;
}
.settings-panel h2 {
  margin: 0 0 14px;
  font-size: 20px;
  text-align: center;
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.settings-list label > select,
.settings-list label > input[type="range"] {
  flex: 1;
  min-width: 0;
}
.settings-list select {
  background: #111;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
}
.settings-list input[type="range"] {
  width: auto;
}
.settings-list label span {
  display: inline-block;
  min-width: 3.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #ccc;
}
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.settings-actions button {
  font-size: 13px;
  padding: 8px 12px;
}
#settings-close {
  display: block;
  margin: 18px auto 0;
}

/* About dialog */
#about-dialog { z-index: 30; }

.about-panel {
  max-width: 560px;
  text-align: left;
}
.about-panel h2 {
  margin: 0 0 16px;
  font-size: 22px;
}
.about-panel h3 {
  margin: 18px 0 6px;
  font-size: 12px;
  color: #8ac4ff;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.about-panel p {
  margin: 0 0 8px;
  line-height: 1.6;
  font-size: 14px;
}
.about-panel a { color: #64b5ff; }
.about-list {
  margin: 4px 0 0;
  padding-left: 18px;
  line-height: 1.7;
  font-size: 13px;
}
.about-list li + li { margin-top: 6px; }
#about-close {
  display: block;
  margin: 22px auto 0;
}

/* 認識対象クラス一覧モーダル */
#classes-dialog { z-index: 30; }
#classes-dialog .panel {
  max-width: 640px;
  width: 90vw;
  max-height: 80vh;
  padding: 20px 24px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#classes-dialog h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
#classes-dialog .classes-count {
  font-size: 12px;
  color: #888;
  font-weight: 400;
  margin-left: 6px;
}
#classes-dialog .note {
  margin: 0;
  color: #aaa;
  font-size: 12px;
}
.classes-grid {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 10px;
  overflow-y: auto;
  max-height: 56vh;
}
.classes-grid li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  font-size: 13px;
}
.classes-grid .cls-ja { color: #00d1b2; font-weight: 500; }
.classes-grid .cls-en {
  color: #888;
  font: 11px ui-monospace, Menlo, Consolas, monospace;
  margin-left: 8px;
}
#classes-close { align-self: flex-end; }

/* ═══════════════════════════════════════════════════
   Start Screen — redesign
   ═══════════════════════════════════════════════════ */

#start-overlay {
  background: #0d151d;
  /* justify-content は flex-start のまま（base .overlay の値）。
     カードに margin:auto を使って中央揃えする。
     center にするとカードが縦にはみ出したとき上端がスクロール到達不能になる。 */
  padding: 16px 16px 0;
  font-family: 'Space Grotesk', 'Noto Sans JP', sans-serif;
  /* footer.css カスタムプロパティをダークテーマに上書き */
  --footer-bg: transparent;
  --footer-border: #1e2e3e;
  --footer-text: #60889a;
  --footer-accent: #00d1b2;
}

/* ── Site navigation ── */
.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 540px;
  align-self: center;
  padding-bottom: 14px;
}
.site-nav__home {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #60889a;
  text-decoration: none;
  padding: 4px 6px 4px 2px;
  border-radius: 6px;
  transition: color 0.15s ease;
}
.site-nav__home:hover { color: #00d1b2; }
.site-nav__title {
  color: #60889a;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s ease;
}
.site-nav__title:hover { color: #00d1b2; }

/* ── Footer container (inside #start-overlay) ── */
#footer-container {
  width: 100%;
  max-width: 540px;
  align-self: center;
  padding-top: 8px;
}
#footer-container footer {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
  border-top-color: #1e2e3e;
  font-size: 11px;
  padding: 0.6rem 1rem;
  margin-top: 0;
}

/* ── HUD home link ── */
.hud-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  padding: 6px 8px;
  pointer-events: auto;
  transition: color 0.15s ease;
  flex-shrink: 0;
}
.hud-home-link:hover { color: #00d1b2; }

@media (max-width: 400px) {
  #start-overlay { padding: 12px 12px 0; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #start-overlay { padding: 8px 16px 0; }
  .site-nav { display: none; }
  #footer-container { display: none; }

  .start-header {
    padding: 10px 20px;
    gap: 12px;
  }
  .start-icon {
    width: 48px;
    height: 48px;
    border-radius: 7px;
  }
  .start-subtitle { margin-top: 3px; }
  .start-desc { display: none; }

  .start-body {
    padding: 10px 20px;
    gap: 8px;
  }
  .start-cam-label { margin-bottom: 5px; }
  .start-cam-select { height: 38px; }
  .start-refresh-btn { width: 38px; height: 38px; }
  .start-cam-hint { display: none; }

  #start-overlay .xreal-btn,
  #start-btn.start-go-btn { height: 48px; }

  .start-notes { display: none; }
  .start-footer { display: none; }
}

.start-card {
  width: 100%;
  max-width: 540px;
  margin: auto; /* 縦方向も auto で中央揃え。余白がないときは上詰めになりスクロール可能 */
  border-radius: 20px;
  border: 1px solid #1e2e3e;
  background: #101820;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
  overflow: hidden;
}

/* ── Header banner ── */
.start-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: clamp(16px, 4vw, 28px) clamp(18px, 5vw, 32px);
  background: linear-gradient(135deg, #131f2c 0%, #0f1a26 100%);
  border-bottom: 1px solid #1e2e3e;
}
.start-icon {
  display: block;
  border-radius: 10.8px;
  flex-shrink: 0;
}
.start-header-info { flex: 1; min-width: 0; }
.start-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.start-app-name {
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
}
.start-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #00d1b2;
  background: rgba(0,209,178,0.12);
  border: 1px solid rgba(0,209,178,0.30);
  padding: 2px 8px;
  border-radius: 4px;
}
.start-subtitle {
  color: #00d1b2;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 7px;
}
.start-desc {
  color: #90b4c8;
  font-size: 12px;
  line-height: 1.7;
  margin: 8px 0 0;
  text-wrap: pretty;
  word-break: auto-phrase;
}

/* ── Body ── */
.start-body {
  padding: clamp(16px, 4vw, 24px) clamp(18px, 5vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.start-cam-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #60889a;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Override legacy .start-camera-row positioning */
#start-overlay .start-camera-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin: 0;
}
.start-cam-select {
  height: 44px;
  flex: 1;
  min-width: 0;
  background: #0a1018;
  border: 1px solid #1e2e3e;
  border-radius: 10px;
  padding: 0 14px;
  color: #c8d8e8;
  font-size: 13px;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.start-cam-select:hover {
  background: #182030;
  border-color: rgba(0,209,178,0.30);
}
.start-refresh-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #0a1018;
  border: 1px solid #1e2e3e;
  border-radius: 10px;
  color: #60889a;
  padding: 0;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.start-refresh-btn:hover {
  background: #182030;
  border-color: rgba(0,209,178,0.30);
  color: #00d1b2;
}
.start-cam-hint {
  color: #60889a;
  font-size: 11px;
  margin-top: 8px;
  line-height: 1.6;
  text-wrap: pretty;
  word-break: auto-phrase;
}
.start-divider {
  height: 1px;
  background: #1e2e3e;
}

/* ── Action buttons ── */
.start-actions {
  display: flex;
  gap: 10px;
}
/* 各ボタンは均等に伸縮。XREAL が display:none になると start が自動で全幅になる */
#start-overlay .xreal-btn,
#start-btn.start-go-btn {
  flex: 1;
}
/* Override generic .xreal-btn for start screen */
#start-overlay .xreal-btn {
  height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #0a1018;
  border: 1px solid #1e2e3e;
  border-radius: 12px;
  color: #8098b0;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  padding: 0 8px;
  margin: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}
#start-overlay .xreal-btn:hover {
  background: rgba(0,209,178,0.08);
  border-color: rgba(0,209,178,0.30);
  color: #00d1b2;
}
/* Override generic #start-btn */
#start-btn.start-go-btn {
  height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(135deg, #00d1b2, #00a890);
  border: none;
  border-radius: 12px;
  color: #031510;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0 8px;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,209,178,0.25);
  transition: all 0.15s ease;
}
#start-btn.start-go-btn:hover {
  background: linear-gradient(135deg, #00e6c6, #00b89e);
  box-shadow: 0 4px 28px rgba(0,209,178,0.45);
  transform: translateY(-1px);
}

/* ── Notes block ── */
.start-notes {
  padding: 12px 16px;
  background: #0a1018;
  border-radius: 10px;
  border: 1px solid #1e2e3e;
  color: #60889a;
  font-size: 11px;
  line-height: 1.8;
  text-wrap: pretty;
  word-break: auto-phrase;
}
.start-notes p + p { margin-top: 2px; }
.start-notes-em { color: #7899aa; font-weight: bold; }
.start-notes-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 10px;
}

/* ── Footer link ── */
.start-footer {
  text-align: center;
  margin: 0;
}
.start-footer a {
  color: #60889a;
  font-size: 11px;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

/* ── 映像スライダー チュートリアル tooltip ── */
.bgtut {
  position: fixed;
  z-index: 6;
  background: rgba(8, 18, 26, 0.95);
  border: 1px solid #00d1b2;
  border-radius: 10px;
  padding: 12px 16px;
  max-width: 240px;
  font-size: 13px;
  line-height: 1.6;
  color: #e0e8ec;
  box-shadow: 0 4px 20px rgba(0, 209, 178, 0.2);
  pointer-events: auto;
}
.bgtut::before {
  content: "";
  position: absolute;
  top: -7px;
  left: var(--arrow-left, 20px);
  width: 12px;
  height: 12px;
  background: rgba(8, 18, 26, 0.95);
  border-top: 1px solid #00d1b2;
  border-left: 1px solid #00d1b2;
  transform: rotate(45deg);
}
.bgtut p {
  margin: 0 0 10px;
}
.bgtut strong {
  color: #00d1b2;
}
#bgtut-close {
  display: block;
  margin: 0 auto;
  padding: 4px 16px;
  font-size: 12px;
}
