:root {
  --bg: #04060c;
  --glass: rgba(10, 16, 30, 0.74);
  --glass-border: rgba(140, 170, 220, 0.16);
  --text: #dfe6f2;
  --text-dim: #8d9ab2;
  --gold: #ffd27d;
  --blue: #7fb8ff;
  --danger: #ff8a70;
  --font: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}

#scene-container { position: fixed; inset: 0; }
#scene-container canvas { display: block; }

/* ---------- 共通パネル ---------- */
.panel {
  position: fixed;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.panel h2 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ---------- タイトル ---------- */
#title-bar {
  top: 14px; left: 50%;
  transform: translateX(-50%);
  padding: 8px 22px;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
#title-bar h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--gold);
}
#title-bar p {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 3px;
  letter-spacing: 0.06em;
}

/* ---------- 左: 入力パネル ---------- */
#input-panel {
  top: 14px; left: 14px;
  width: 268px;
  max-height: calc(100vh - 148px); /* 左下の視点パネルと重ならない高さ */
  overflow-y: auto;
  padding: 16px;
  transition: transform 0.3s ease;
}
#input-panel.collapsed { transform: translateX(-262px); }

#panel-toggle {
  position: fixed;
  top: 22px; left: 296px;
  z-index: 11;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  transition: left 0.3s ease;
}
#panel-toggle.collapsed { left: 20px; }

.field-group { margin-bottom: 14px; }
.field-row { display: flex; gap: 6px; margin-bottom: 6px; }
.field-row > * { flex: 1; min-width: 0; }

label.small {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

input[type="date"], input[type="time"], input[type="number"], input[type="text"], select {
  width: 100%;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(140, 170, 220, 0.22);
  border-radius: 7px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: var(--font);
  color-scheme: dark;
}
input:focus, select:focus { outline: 1px solid var(--blue); }
select option { background: #0d1422; }

/* iOS WebKitの日付・時刻入力を通常のフォーム見た目に揃える */
input[type="date"], input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}
input::-webkit-date-and-time-value { text-align: left; }

.check-row {
  display: flex; align-items: center; gap: 7px;
  padding: 3.5px 0;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.check-row input[type="checkbox"] {
  accent-color: var(--gold);
  width: 14px; height: 14px;
  cursor: pointer;
}

.radio-group { display: flex; gap: 4px; }
.radio-group label {
  flex: 1;
  text-align: center;
  font-size: 11px;
  padding: 5px 2px;
  border: 1px solid rgba(140, 170, 220, 0.22);
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-dim);
}
.radio-group input { display: none; }
.radio-group input:checked + span { color: var(--gold); }
.radio-group label:has(input:checked) {
  border-color: var(--gold);
  background: rgba(255, 210, 125, 0.08);
  color: var(--gold);
}

button.action {
  width: 100%;
  padding: 8px;
  border: 1px solid rgba(255, 210, 125, 0.45);
  border-radius: 8px;
  background: rgba(255, 210, 125, 0.12);
  color: var(--gold);
  font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: 0.08em;
}
button.action:hover { background: rgba(255, 210, 125, 0.22); }
button.ghost {
  border: 1px solid rgba(140, 170, 220, 0.25);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-family: var(--font);
  cursor: pointer;
}
button.ghost:hover { background: rgba(255, 255, 255, 0.1); }
button.ghost.active { border-color: var(--gold); color: var(--gold); }

.divider { height: 1px; background: var(--glass-border); margin: 12px 0; }

/* ---------- 右: 天体パネル ---------- */
#data-panel {
  top: 14px; right: 14px;
  width: 252px;
  max-height: calc(100vh - 190px);
  overflow-y: auto;
  padding: 14px;
}

.angles-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.angle-chip {
  background: rgba(255, 210, 125, 0.07);
  border: 1px solid rgba(255, 210, 125, 0.25);
  border-radius: 8px;
  padding: 5px 8px;
  text-align: center;
}
.angle-chip .k { font-size: 9.5px; color: var(--gold); letter-spacing: 0.12em; }
.angle-chip .v { font-size: 12px; margin-top: 1px; }

table.planet-table { width: 100%; border-collapse: collapse; }
.planet-table td {
  padding: 3.5px 2px;
  font-size: 12px;
  border-bottom: 1px solid rgba(140, 170, 220, 0.08);
  white-space: nowrap;
}
.planet-table td.glyph { font-size: 15px; width: 22px; text-align: center; }
.planet-table td.name { color: var(--text); width: 58px; font-size: 11.5px; }
.planet-table td.pos { color: var(--text); }
.planet-table td.pos .sg { font-size: 13px; margin-right: 2px; }
.planet-table td.house {
  text-align: right; width: 34px;
  font-size: 11px; color: var(--text-dim);
}
.planet-table td .retro { color: var(--danger); font-size: 10px; margin-left: 3px; }
.planet-table tr.below td { opacity: 0.55; }

.aspect-list { margin-top: 8px; }
#data-panel .aspect-list { max-height: 120px; overflow-y: auto; }

/* ---------- 2Dチャートシート（モバイル専用、デスクトップは非表示） ---------- */
#chart2d-panel { display: none; padding: 14px; }
#wheel-canvas-large {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
}
.aspect-item { font-size: 11px; padding: 2px 0; color: var(--text-dim); }
.aspect-item b { color: var(--text); font-weight: 500; }

.note { font-size: 10px; color: var(--text-dim); line-height: 1.5; margin-top: 6px; }
.note.error { color: var(--danger); }

/* 関連サービスへのリンクボタン */
.service-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  margin-bottom: 6px;
  border: 1px solid rgba(140, 170, 220, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
}
.service-link:hover {
  background: rgba(255, 210, 125, 0.1);
  border-color: var(--gold);
  color: var(--gold);
}
.service-link .ext { color: var(--text-dim); font-size: 11px; margin-left: 8px; }

/* コピーライト・法的表記 */
.app-footer {
  margin-top: 12px;
  text-align: center;
  font-size: 9.5px;
  color: var(--text-dim);
  line-height: 1.9;
}
.app-footer a { color: var(--text-dim); text-decoration: underline; }
.app-footer a:hover { color: var(--text); }

#view-presets { display: flex; gap: 4px; margin-bottom: 8px; }
#view-presets button { flex: 1; font-size: 10.5px; padding: 5px 2px; white-space: nowrap; }

/* ---------- 下: 時間コントロール ---------- */
#time-bar {
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
#time-bar .time-display {
  font-size: 13px;
  color: var(--gold);
  min-width: 168px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#time-bar .offset-display {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 110px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#time-bar button { min-width: 34px; }
#play-btn { font-size: 14px; min-width: 42px; }

/* ---------- 2Dホイール ---------- */
#wheel-card {
  bottom: 16px; right: 14px;
  padding: 10px;
}
#wheel-card canvas { display: block; border-radius: 8px; }
#wheel-card .caption {
  text-align: center;
  font-size: 9.5px;
  color: var(--text-dim);
  margin-top: 5px;
  letter-spacing: 0.1em;
}

/* ---------- カメラモード（左下） ---------- */
#camera-bar {
  bottom: 16px; left: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#camera-bar .row { display: flex; gap: 5px; }

/* ---------- 情報モーダル ---------- */
#info-modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(2, 4, 10, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#info-modal.open { display: flex; }
#info-modal .box {
  width: min(560px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 26px 30px;
  line-height: 1.85;
  font-size: 12.5px;
}
#info-modal h3 { color: var(--gold); margin: 14px 0 4px; font-size: 13.5px; }
#info-modal h3:first-child { margin-top: 0; }
#info-modal p { color: var(--text); margin-bottom: 6px; }
#info-modal .close {
  float: right;
  background: none; border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
}

#loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  z-index: 200;
  transition: opacity 0.6s ease;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
#loading-overlay .star-spin {
  width: 40px; height: 40px;
  border: 2px solid transparent;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p { color: var(--text-dim); letter-spacing: 0.2em; font-size: 12px; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(140, 170, 220, 0.25); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

button, select, input, label { touch-action: manipulation; }

/* タブレット幅ではタイトルの説明文を省略（左パネルとの重なり防止） */
@media (min-width: 761px) and (max-width: 1200px) {
  #title-bar h1 { font-size: 13px; }
  #title-bar p { display: none; }
}

/* ---------- モバイル（ボトムタブ＋シート方式） ---------- */
#mobile-tabs { display: none; }

@media (max-width: 760px) {
  :root { --tabbar-h: 52px; }

  #title-bar { top: 8px; padding: 6px 14px; max-width: 60vw; white-space: normal; }
  #title-bar h1 { font-size: 12.5px; letter-spacing: 0.14em; }
  #title-bar p { font-size: 8.5px; }

  #panel-toggle { display: none; }

  /* 各パネルをボトムシート化（タブで開閉） */
  #input-panel, #data-panel, #time-bar, #camera-bar, #chart2d-panel {
    left: 0; right: 0; top: auto;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-height: 56vh;
    max-height: 56dvh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    transform: translateY(130%);
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 20;
  }
  #input-panel.collapsed { transform: translateY(130%); }
  .panel.sheet-open { transform: translateY(0) !important; }

  /* 2Dチャートはメインビューとして使えるよう大きめに */
  #chart2d-panel {
    display: block;
    max-height: 78vh;
    max-height: 78dvh;
  }

  #time-bar {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
    padding: 14px 10px;
  }
  #time-bar .time-display { width: 100%; min-width: 0; order: -1; font-size: 15px; }
  #time-bar .offset-display { min-width: 0; }

  #camera-bar .row { flex-wrap: wrap; }
  #camera-bar .row button { min-width: 64px; padding: 9px 8px; }

  /* モバイルでは浮遊カードを廃止（2Dタブに統合） */
  #wheel-card { display: none !important; }

  /* 下部タブバー */
  #mobile-tabs {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
    background: rgba(8, 12, 24, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--glass-border);
    z-index: 30;
  }
  #mobile-tabs button {
    flex: 1;
    border: 1px solid rgba(140, 170, 220, 0.22);
    background: rgba(255, 255, 255, 0.045);
    color: var(--text-dim);
    border-radius: 9px;
    font-size: 11px;
    padding: 0 2px;
    white-space: nowrap;
    font-family: var(--font);
    cursor: pointer;
  }
  #mobile-tabs button.active {
    color: var(--gold);
    border-color: var(--gold);
    background: rgba(255, 210, 125, 0.1);
  }
}
