:root {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.96);
  --text: #1f2328;
  --muted: #5f6b76;
  --border: #d8dee4;
  --accent: #d9771b;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --card: #f6f8fa;
  --input: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: rgba(22, 26, 31, 0.96);
    --text: #e6e9ec;
    --muted: #9aa5b1;
    --border: #343b43;
    --card: #1c2127;
    --input: #12161a;
    --danger: #e0614f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
}
#cesiumContainer { position: absolute; inset: 0; }
.cesium-viewer-bottom { left: auto; right: 6px; }

.panel {
  position: absolute; top: 10px; left: 10px; bottom: 10px;
  width: 340px; overflow-y: auto; overflow-x: hidden;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  padding: 0 12px 12px; z-index: 10;
}
.panel.collapsed { display: none; }
.panel-header { position: sticky; top: 0; background: var(--panel); padding: 12px 0 8px 36px; z-index: 1; }
.panel-header h1 { margin: 0; font-size: 17px; }
.kz-bar { padding: 10px 0 0 36px; }
.panel-toggle {
  position: absolute; top: 18px; left: 18px; z-index: 11;
  width: 30px; height: 30px; padding: 0; font-size: 16px;
}
.panel-footer { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 8px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 10px; }
.card h2 { margin: 0 0 8px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.count { color: var(--muted); font-weight: normal; }

label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 4px 0; }
input, select, button {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--input); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; min-width: 0;
}
input[type="color"] { padding: 1px 2px; height: 30px; width: 100%; }
input[type="range"] { padding: 0; border: none; background: transparent; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
button { cursor: pointer; background: var(--card); }
button:hover { border-color: var(--accent); }
button.primary, button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.wide { width: 100%; margin-top: 8px; }

.row { display: flex; gap: 6px; align-items: flex-end; margin-top: 6px; }
.row.wrap { flex-wrap: wrap; }
.row > input[type="search"] { flex: 1; }
.grow { flex: 1; }

.presets { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.presets button { padding: 3px 8px; font-size: 12px; }
.time-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.time-row input { flex: 1; }
.time-label { font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 58px; }

.sun-info { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: 12px; }
.sun-info dt { color: var(--muted); }
.sun-info dd { margin: 0; font-variant-numeric: tabular-nums; }

.add-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.draw-help { margin-top: 8px; font-size: 12px; }

.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.edit-grid .span2 { grid-column: span 2; }
.edit-grid input, .edit-grid select { width: 100%; }
.edit-grid > label { min-width: 0; }

.search-results { list-style: none; margin: 4px 0 0; padding: 0; max-height: 160px; overflow-y: auto; }
.search-results li { padding: 5px 6px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.search-results li:hover { background: var(--border); }

.shape-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; }
.shape-list li { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.shape-list li:hover { background: var(--border); }
.shape-list li.selected { outline: 2px solid var(--accent); }
.shape-list .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.2); }
.shape-list .dims { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.shape-list .empty { color: var(--muted); cursor: default; }

.file-btn { display: inline-flex; flex-direction: row; align-items: center; color: var(--text); font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; cursor: pointer; background: var(--card); }
.file-btn:hover { border-color: var(--accent); }

.probe { margin-top: 8px; font-size: 13px; }
.probe canvas { width: 100%; height: auto; display: block; margin-top: 6px; }
.probe-legend { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.sw.sun { background: #f5b83d; } .sw.shade { background: #5a6b7d; } .sw.night { background: #232a33; }

.toast {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 20;
  background: rgba(20, 24, 28, 0.92); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px;
}

body.picking #cesiumContainer { cursor: crosshair; }

@media (max-width: 640px) {
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 12px 12px 0 0; padding: 0 16px 16px; }
  .panel-toggle { top: 10px; left: 10px; }
  .panel-header { padding-left: 0; }
  .kz-bar { padding-left: 0; }
}

/* ---- 追加 UI ---- */
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.header-tools { display: flex; gap: 4px; }
.header-tools button { width: 30px; height: 30px; padding: 0; font-size: 15px; }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { border-color: var(--border); }
button.small { padding: 2px 8px; font-size: 12px; margin-top: 6px; }

details.card > summary { cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 6px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: 8px; }

.sw.shade2 { background: #3b5b8a; }

.iso-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; margin-top: 8px; color: var(--text); }
.iso-legend span { display: inline-flex; align-items: center; gap: 4px; }
.iso-legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; }

.measure { font-size: 13px; margin-top: 6px; line-height: 1.6; }
.measure:empty { display: none; }

.feature-info {
  position: absolute; top: 10px; right: 10px; z-index: 12; width: 260px; max-height: 60vh; overflow-y: auto;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,.18); padding: 10px 12px; font-size: 13px;
}
.feature-info h3 { margin: 0 24px 6px 0; font-size: 14px; }
.feature-info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; margin: 0; }
.feature-info dt { color: var(--muted); }
.feature-info dd { margin: 0; word-break: break-all; }
.feature-info .close { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; padding: 0; border: none; background: transparent; font-size: 16px; }
.feature-info .row button { font-size: 12px; }

dialog.help {
  max-width: 560px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text); padding: 18px 20px;
}
dialog.help::backdrop { background: rgba(0,0,0,.45); }
dialog.help h2 { margin: 0 0 8px; font-size: 18px; }
dialog.help ol { padding-left: 20px; line-height: 1.6; font-size: 14px; }
dialog.help li { margin-bottom: 4px; }

@media (max-width: 640px) {
  .feature-info { top: auto; bottom: calc(55vh + 8px); left: 10px; right: 10px; width: auto; max-height: 30vh; }
}

/* ---- 多言語・世界対応 ---- */
.lang-row { margin-top: 0; }
.lang-row label { flex-direction: row; align-items: center; gap: 8px; }
.lang-row select { flex: 1; }
.search-results li.attrib { cursor: default; color: var(--muted); font-size: 11px; }
.search-results li.attrib:hover { background: transparent; }
#mapHint { color: #b26a00; }
.row > label { min-width: 0; }
.row > label > select, .row > label > input:not([type="checkbox"]):not([type="range"]) { width: 100%; }
.row > .half { flex: 1 1 0; }

/* ---- 日付の比較 ---- */
.cmp-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; flex: none; }
.cmp-row { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 13px; }
.cmp-row input[type="date"] { flex: 1; }
.cmp-row button.small { margin-top: 0; }
#cmpSolstices { margin-top: 8px; }

/* ---- 免責事項 ---- */
.legal-short { margin: 0 0 6px; color: var(--text); }
.legal-short a, .legal-note a { color: var(--accent); }
.legal-note { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--card); border: 1px solid var(--border); }
dialog.legal { max-width: 720px; }
.legal-body { max-height: 60vh; overflow-y: auto; font-size: 13px; line-height: 1.65; padding-right: 6px; }
.legal-body h4 { margin: 14px 0 4px; font-size: 14px; }
.legal-body h4:first-child { margin-top: 4px; }
.legal-body p { margin: 0; }

/* ---- 地名の表示 ---- */
label.check.disabled { color: var(--muted); }
#labelsHint { margin-top: 0; }
