:root {
  --bg: #000000;
  --surface: #0d0d0d;
  --line: #2b2b2b;
  --tick: #4a4a4a;
  --text: #ffffff;
  --text-dim: #8c8c8c;
  --red: #e20612;
  --red-text: #ff5a63;
  --font: "Helvetica Neue", Helvetica, Arial, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
}

body {
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button {
  font-family: var(--font);
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    12px
    calc(18px + var(--safe-left));
  flex-shrink: 0;
}

.sensor-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 4px 0;
}
.sensor-btn span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sensor-btn .brand-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
}
.sensor-btn svg { color: var(--text-dim); margin-top: 2px; }

.mode-switch {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

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

.mode-btn {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 6px;
  color: var(--text-dim);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.mode-btn.active {
  background: var(--line);
  color: var(--text);
}

.settings-trigger {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
  transition: color 0.15s, opacity 0.15s;
}

.settings-trigger:hover {
  color: var(--text);
}

.icon-btn {
  color: var(--text);
  padding: 4px;
  display: flex;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.icon-btn:hover { opacity: 0.7; }

/* ---------- Stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  padding:
    0
    calc(16px + var(--safe-right))
    6px
    calc(16px + var(--safe-left));
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view[hidden] {
  display: none;
}

/* 扇の頂点(赤い点)とスライダーの中間あたりに合計深度を置く */
.metrics-row {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 0 10px;
}

/* 撮影プレビュー(16:9)。被写界深度で人物の各部位を塗り分ける */
.preview-frame {
  width: 100px;
  aspect-ratio: 16 / 9;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 34%, #1a1a1a 0%, #0b0b0b 62%, #050505 100%);
  box-shadow: inset 0 0 12px rgba(255,255,255,0.025);
}

.preview-frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

.metric {
  display: flex;
  width: 140px;
  flex: 0 0 140px;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.metric-value {
  display: flex;
  align-items: baseline;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-unit {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dim);
  margin-left: 4px;
}

.metric-caption {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---------- 統合グラフィック ---------- */

.dof-svg {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  aspect-ratio: 360 / 281;
  height: auto;
  display: block;
  overflow: visible;
}

.dof-svg text {
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

.svg-cap {
  fill: var(--text-dim);
  font-size: 9px;
  letter-spacing: 0.18em;
}

.svg-red {
  fill: var(--red-text);
  font-size: 20px;
  font-weight: 800;
}

.svg-strong {
  fill: var(--text);
  font-size: 20px;
  font-weight: 800;
}

.svg-aov {
  fill: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.svg-width {
  fill: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
}

/* ---------- Rulers ---------- */

.dial-group { border-top: 1px solid var(--line); }

/* ---------- f値・焦点距離(画面下部に固定) ---------- */

.fixed-controls {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.fixed-controls .dial-group:first-child {
  border-top: none;
}

.dial-caption {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 0 4px;
}

.ruler {
  position: relative;
  height: 78px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.dial-group:not(:has(.dial-caption)) .ruler { height: 92px; }

.ruler.dragging { cursor: grabbing; }

.ruler-strip {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  will-change: transform;
}

/* スナップ式ルーラーはクリック感を出す */
.ruler.snap .ruler-strip {
  transition: transform 0.1s ease-out;
}

.rt {
  position: absolute;
  top: 8px;
  width: 1px;
  height: 8px;
  background: var(--line);
}

.rt-major {
  height: 14px;
  background: var(--tick);
}

.rt-label {
  position: absolute;
  top: 32px;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hyperfocal-marker {
  position: absolute;
  top: -3px;
  z-index: 2;
  transform: translateX(-50%);
  color: var(--red-text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.hyperfocal-marker::after {
  content: "";
  position: absolute;
  top: 17px;
  left: 50%;
  width: 1px;
  height: 7px;
  transform: translateX(-50%);
  background: var(--red);
}

.ruler-box {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -54%);
  min-width: 80px;
  height: 42px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1.5px solid var(--text);
  border-radius: 8px;
  pointer-events: none;
}

.ruler-box span {
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.dial-dot {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
  pointer-events: none;
}

/* ---------- テーブルモード ---------- */

.table-wrap {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#dofTable {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

#dofTable th,
#dofTable td {
  padding: 11px 16px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

#dofTable thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.04em;
  z-index: 2;
}

#dofTable thead th:first-child {
  left: 0;
  z-index: 3;
}

#dofTable tbody th {
  position: sticky;
  left: 0;
  background: var(--bg);
  text-align: left;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 700;
  z-index: 1;
}

#dofTable tbody td {
  padding: 9px 14px;
}

.cell-total {
  display: block;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
}

.cell-fb {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
}

/* ---------- Settings ---------- */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(20px + var(--safe-top))
    calc(20px + var(--safe-right))
    calc(20px + var(--safe-bottom))
    calc(20px + var(--safe-left));
  z-index: 100;
}

.settings-overlay[hidden] { display: none; }

.settings-panel {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 40px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}

.settings-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.settings-page[hidden] { display: none; }

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.settings-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.settings-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-head.centered {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
}

.settings-head.centered h2 {
  text-align: center;
}

.settings-head.centered .icon-btn {
  justify-self: center;
}

.settings-link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  transition: border-color 0.15s;
}
.settings-link:hover { border-color: var(--text-dim); }
.settings-link svg { color: var(--text-dim); }
.settings-link + .settings-link { margin-top: 10px; }

.settings-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.settings-section:not(:last-child) {
  margin-bottom: 22px;
}

.settings-caption {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.sensor-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sensor-option {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 14px 16px;
  text-align: left;
  transition: border-color 0.15s;
}

.sensor-option[hidden] { display: none; }

.sensor-option:hover { border-color: var(--text-dim); }
.sensor-option.selected { border-color: var(--text); }

.sensor-option.selected .sensor-option-name::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
  margin-left: 9px;
}

.sensor-option-name { font-size: 15px; font-weight: 700; }

.sensor-option-detail {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.choice-row {
  display: flex;
  gap: 8px;
}

.choice-btn {
  flex: 1;
  padding: 10px 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s;
}

.choice-btn.active {
  border-color: var(--text);
  color: var(--text);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip.active {
  border-color: var(--red);
  color: var(--text);
  background: rgba(226, 6, 18, 0.12);
}

/* ---------- Lens picker ---------- */

.favorite-lens-list,
.lens-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lens-search-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  height: 42px;
  margin-bottom: 14px;
  padding: 0 12px;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.lens-search {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font: 500 14px var(--font);
}

.lens-search::placeholder { color: #6f6f6f; }
.lens-search::-webkit-search-cancel-button { filter: invert(1); opacity: 0.6; }

.lens-picker-body { padding-right: 4px; }

.lens-group:not(:last-child) { margin-bottom: 20px; }

.lens-group-title {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 5px 0 8px;
  color: var(--text-dim);
  background: var(--surface);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lens-group-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lens-row {
  display: flex;
  align-items: stretch;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.lens-row:hover { border-color: var(--text-dim); }
.lens-row.selected { border-color: var(--red); }

.lens-select {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 12px 10px 12px 14px;
  text-align: left;
}

.lens-name {
  width: 100%;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.lens-detail {
  color: var(--text-dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.lens-favorite {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  flex-shrink: 0;
  color: var(--text-dim);
  border-left: 1px solid var(--line);
}

.lens-favorite.active { color: var(--red-text); }
.lens-favorite.active svg { fill: currentColor; }
.lens-favorite svg { width: 18px; height: 18px; }

.lens-catalog-status {
  padding: 28px 12px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.favorite-lens-list .lens-detail { display: none; }

/* ---------- Installed PWA ---------- */

@media (display-mode: standalone) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
  }

  .app-header {
    padding-top: var(--safe-top);
  }

  .fixed-controls {
    padding-bottom: 0;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 370px) {
  .metric-value { font-size: 34px; }
  .sensor-btn { font-size: 14px; }
  .mode-btn { font-size: 11px; padding: 6px 8px; }
  .settings-panel { padding: 20px; }
}
