/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(45deg, #071C1E 60%, #0F2833);
  min-height: 100vh;
  color: #e0e0e4;
  line-height: 1.5;
}

      
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
h1 { font-size: 26px; line-height: 35px; font-weight: 500; margin-bottom: 2px; 
  img{
    vertical-align: text-bottom;
    margin-right: 5px;
  }
}
.subtitle { font-size: 13px; color: #888; margin-bottom: 1.5rem; }
.description{
  margin-bottom: 15px;
  font-size: small;
  color:#999;
}
.hidden { display: none !important; }

/* ── Drop zone ── */
#dz {
  border: 1.5px dashed #548c9c;
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: background .15s;
  background: rgba(7, 28, 30, 0.4);
}
#dz.ov { background: rgba(35, 77, 94, 0.4); }
#dz input[type=file] { display: none; }
.dz-icon { font-size: 22px; margin-bottom: 8px; color: #666; }
.dz-main { font-weight: 500; margin: 0; }
.dz-sub { font-size: 12px; color: #666; margin: 4px 0 0; }

/* ── Controls ── */
#ctrl { margin-top: 1rem; }
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.tab-bar {
  display: flex;
  border: .5px solid #548c9c55;
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}
.tab {
  padding: 6px 18px;
  font-size: 13px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #89b4c0;
  font-family: inherit;
}
.tab.active {
  font-weight: 500;
  background: rgba(35, 77, 94, 0.5);
  color: #e0e0e4;
}
.tab + .tab { border-left: .5px solid #548c9c55; }
.adv-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #888;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.adv-toggle input[type=checkbox] {
  accent-color: #6b8afd;
  cursor: pointer;
}
.adv-toggle input[type=checkbox]:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}
.adv-toggle:has(input:disabled) {
  opacity: 0.45;
  cursor: not-allowed;
}
.adv-toggle:hover { color: #bbb; }
.threshold-panel {
  margin-top: .75rem;
  background: rgba(7, 28, 30, 0.5);
  border-radius: 8px;
  padding: .75rem 1rem;
  border: .5px solid #548c9c33;
}
.threshold-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.threshold-label { font-size: 13px; font-weight: 500; white-space: nowrap; }
.threshold-row input[type=range] { flex: 1; min-width: 120px; }
.threshold-row span { font-size: 13px; min-width: 34px; }
.threshold-row button {
  padding: 4px 14px;
  font-size: 12px;
  background: transparent;
  border: .5px solid #444;
  border-radius: 6px;
  color: #ccc;
  cursor: pointer;
  font-family: inherit;
}
.threshold-row button:hover { background: #222; }
.threshold-hint { margin: 6px 0 0; font-size: 11px; color: #666; }
.local-hint { color: #5a8a5a; }
.server-warn { color: #b8860b; }
.adv-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: .5px solid #548c9c33;
}
.adv-section {
  margin-top: 0px;
  padding-top: 0px;
  border-top: 0;
  visibility: hidden;
}


/* ── Advanced Controls ── */
#adv-controls {
  margin-top: 10px;
}
.adv-btn {
  display: block;
  width: 100%;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  background: rgba(35, 77, 94, 0.4);
  border: .5px solid #548c9c;
  border-radius: 8px;
  color: #e0e0e4;
  cursor: pointer;
  transition: background .15s;
}
.adv-btn:hover:not(:disabled) { background: rgba(84, 140, 156, 0.35); }
.adv-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.analyze-progress {
  margin-top: 8px;
  font-size: 12px;
  color: #89b4c0;
  font-family: 'SF Mono', Consolas, monospace;
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── 角度範囲スライダー ── */
.angle-range-panel {
  margin: 8px 0;
  padding: 8px 10px;
  background: rgba(0,0,0,.2);
  border-radius: 6px;
  border: .5px solid #548c9c22;
}
.angle-range-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.angle-range-label { font-size: 11px; color: #888; }
.angle-range-val   { font-size: 11px; color: #89b4c0; font-weight: 500; }
.angle-range-sliders { display: flex; flex-direction: column; gap: 4px; }
.angle-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.angle-slider-tag { font-size: 10px; color: #666; width: 22px; }
.angle-slider-row input[type=range] {
  flex: 1;
  accent-color: #548c9c;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  outline: none;
  background: #2a4a50; /* JSで上書きされる */
}
.angle-slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #548c9c;
  cursor: pointer;
  border: 2px solid #0a2428;
}
.angle-slider-row input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #548c9c;
  cursor: pointer;
  border: 2px solid #0a2428;
}
.angle-slider-num { font-size: 11px; color: #ccc; width: 32px; text-align: right; }

/* ── コーナー行 ── */
.cand-row.corner-row { opacity: 0.75; }
.cand-row.corner-row:hover { opacity: 1; }
.cand-row.corner-row.selected { background: rgba(180,40,40,0.2); opacity: 1; }
.cand-corner-badge {
  font-size: 9px;
  background: rgba(255,200,50,0.2);
  color: #ffcc4d;
  border: .5px solid #ffcc4d55;
  border-radius: 3px;
  padding: 0 3px;
  white-space: nowrap;
}
.cand-bridge-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 3px;
  border: .5px solid #89b4c055;
  border-radius: 3px;
  background: rgba(84, 140, 156, 0.18);
  color: #89b4c0;
  font-size: 9px;
  font-weight: 400;
  vertical-align: middle;
}
.convert-btn {
  margin-top: 8px;
  background: rgba(180, 60, 60, 0.3);
  border-color: #b84040;
}
.convert-btn:hover:not(:disabled) { background: rgba(180, 60, 60, 0.5); }

/* ── Advanced Selection Panel ── */
#adv-selection {
  margin-top: 10px;
}
.candidate-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.candidate-table th {
  text-align: left;
  padding: 4px 6px;
  color: #888;
  border-bottom: .5px solid #548c9c33;
  font-weight: 400;
}
.candidate-table td {
  padding: 3px 6px;
  border-bottom: .5px solid #548c9c15;
}
.conf-high { color: #5fb85f; }
.conf-mid  { color: #b8a040; }
.conf-low  { color: #b85050; }

.selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.selection-help {
  margin: 8px 0 4px;
  padding: 7px 9px;
  border: .5px solid #548c9c44;
  border-radius: 6px;
  background: rgba(35, 77, 94, 0.18);
  color: #9fb6bd;
  font-size: 11px;
  line-height: 1.45;
}
.selection-help-sub {
  margin-top: 4px;
  padding: 5px 9px;
  background: rgba(0, 199, 242, 0.08);
}
.help-key {
  display: inline-block;
  padding: 1px 5px;
  border: .5px solid #548c9c66;
  border-radius: 4px;
  background: rgba(0,0,0,.22);
  color: #e0e0e4;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 10px;
}
.help-sep { color: #548c9c; margin: 0 5px; }
.selection-info {
  flex: 1;
  font-size: 12px;
  color: #888;
}
.sel-btn {
  padding: 3px 10px;
  font-size: 11px;
  background: transparent;
  border: .5px solid #548c9c55;
  border-radius: 6px;
  color: #89b4c0;
  cursor: pointer;
  font-family: inherit;
}
.sel-btn:hover { background: rgba(35, 77, 94, 0.3); }
.sel-btn.secondary {
  color: #6f8f98;
  border-color: #548c9c33;
}
.sel-btn.active {
  background: rgba(0, 199, 242, 0.16);
  border-color: #00c7f2;
  color: #d5f8ff;
}

.vw-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  pointer-events: none;
  user-select: none;
}
.vw-legend {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 12px;
  background: rgba(0,0,0,.6);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #ccc;
}
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ── 候補リスト オーバーレイ ── */
#candidate-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 220px;
  max-height: 100%;
  overflow-y: auto;
  background: rgba(5, 18, 20, 0.82);
  backdrop-filter: blur(4px);
  border-right: .5px solid #548c9c33;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: #548c9c44 transparent;
}
#candidate-overlay::-webkit-scrollbar { width: 4px; }
#candidate-overlay::-webkit-scrollbar-thumb { background: #548c9c44; border-radius: 2px; }

.cand-row {
  display: grid;
  grid-template-columns: 36px 1fr 52px 36px;
  align-items: center;
  gap: 0;
  padding: 5px 8px;
  font-size: 11px;
  cursor: pointer;
  border-bottom: .5px solid #548c9c11;
  transition: background .1s;
  user-select: none;
}
.cand-row:hover { background: rgba(84,140,156,0.15); }
.cand-row.active { background: rgba(84,140,156,0.25); }
.cand-row.selected { background: rgba(180,40,40,0.2); }
.cand-row.selected.active { background: rgba(180,40,40,0.35); }

.cand-id   { color: #89b4c0; font-size: 10px; }
.cand-angle { color: #ccc; }
.cand-conf  { text-align: right; padding-right: 6px; }
.cand-check { text-align: center; font-size: 13px; }

.cand-header {
  display: grid;
  grid-template-columns: 36px 1fr 52px 36px;
  padding: 5px 8px;
  font-size: 10px;
  color: #556;
  border-bottom: .5px solid #548c9c33;
  position: sticky;
  top: 0;
  background: rgba(5, 18, 20, 0.95);
}

/* ── Advanced Selection Bar ── */
#adv-selection {
  margin-top: 0;
  border: .5px solid #548c9c33;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: .5rem .75rem;
  background: rgba(7, 28, 30, 0.4);
}

/* ── 3D Viewer ── */
#vw {
  position: relative;
  margin-top: 1rem;
  border-radius: 12px;
  overflow: hidden;
  border: .5px solid #333;
}
#cv {
  display: block;
  width: 100%;
  height: 50vh;
  cursor: default;
  touch-action: none;
}
#cv:active { cursor: inherit; }
.vw-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}
.vw-controls button {
  font-size: 11px;
  padding: 3px 10px;
  background: rgba(0,0,0,.6);
  border: .5px solid #555;
  border-radius: 6px;
  color: #ccc;
  cursor: pointer;
  font-family: inherit;
}
.vw-controls button:hover { background: rgba(40,40,40,.8); }

/* ── Stats ── */
#sarea { margin-top: 1rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat {
  background: rgba(7, 28, 30, 0.5);
  border-radius: 8px;
  padding: .6rem 1rem;
  border: .5px solid #548c9c22;
}
.stat-label { font-size: 11px; color: #888; margin: 0 0 2px; }
.stat-value { font-size: 17px; font-weight: 500; margin: 0; }

/* ── Log & Download ── */
#lg {
  font-size: 12px;
  font-family: 'SF Mono', Consolas, monospace;
  color: #888;
  margin-top: 8px;
  min-height: 16px;
}
.dl-btn {
  display: block;
  margin-top: 1rem;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  border: .5px solid #548c9c;
  text-decoration: none;
  color: #e0e0e4;
  transition: background .15s;
  background: rgba(35, 77, 94, 0.3);
}
.dl-btn:hover { background: rgba(84, 140, 156, 0.25); }

/* ── Affiliate Footer ── */
#affiliate-footer {
  margin-top: 3rem;
  padding: 1.5rem;
  border-top: .5px solid #548c9c33;
  text-align: center;
}
.affiliate-label {
  font-size: 12px;
  color: #ccc;
  margin: 0 0 1rem;
}
#affiliate-items {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.affiliate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: #666;
  width: 140px;
  transition: opacity .15s;
  padding: 10px;
  border-radius:10px;
  background:#fff;
  box-shadow: #000 2px 3px 2px;
}
.affiliate-card:hover { opacity: .8; }
.affiliate-card img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}
.affiliate-name {
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}
.affiliate-note {
  font-size: 11px;
}
.affiliate-disc {
  font-size: 10px;
  color: #ccc;
  margin: 1rem 0 0;
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 1rem; }
}
.copyright{
  text-align: center;
  color: #ccc;
  font-size: 12px;
  a{
    color:#ccc;
  }
}
