/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #00060e;
    --surface:    rgba(2, 12, 24, 0.82);
    --border:     rgba(56, 189, 248, 0.12);
    --text:        #c4d8e8;
    --muted:      #3d5a72;
    --accent:      #38bdf8;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Noto Sans JP', sans-serif;
    overflow: hidden;
    height: 100vh; width: 100vw;
}

/* ===== 3Dキャンバス ===== 
   最小サイズ確保時に画面中央からはみ出すように配置 */
canvas {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: -1 !important; 
    pointer-events: auto;
}

/* ===== ヘッダー ===== */
#header {
    position: fixed; top: 0; left: 0; right: 0;
    padding: 0 28px;
    height: 56px;
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    z-index: 100;
    
    /* ★追加：画面幅が極端に狭くなっても、ヘッダー内を横スワイプ・横スクロールで快適に操作可能にする */
    overflow-x: auto;
    scrollbar-width: none; /* Firefox用スクロールバー非表示 */
}
#header::-webkit-scrollbar {
    display: none; /* Chrome, Safari用スクロールバー非表示 */
}

.app-title {
    display: flex;
    align-items: baseline;
    gap: 4px;
    user-select: none;
}
.app-title-main {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: linear-gradient(135deg, #fff 30%, #93c5fd 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.app-title-sub {
    font-size: 10px;
    color: var(--muted);
    font-weight: 400;
}

.divider {
    width: 1px; height: 16px;
    background: var(--border);
    margin: 0 20px;
}

.ctrl-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0; /* ★追加：画面が狭まっても各グループが左右から押し潰されないように固定 */
}
.ctrl-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
    user-select: none;
    white-space: nowrap; /* ★追加：ラベルの文字（ディスプレイサイズ等）が絶対に途中で改行されないようにする */
}

/* ★追加：表示粒子のチェックボックス（0.1μm など）も途中で改行させない */
.switch-label {
    white-space: nowrap;
}

select {
    background: rgba(2, 12, 24, 0.6);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    height: 32px;
    padding: 0 28px 0 10px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
}
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.25);
}

/* ===== クラス変更時の一時バッジ ===== */
#class-badge {
    position: fixed;
    top: 84px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    
    /* ⚠️ 二重楕円の原因になっていた background, border, padding, border-radius をすべて削除しました */
    
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

/* 表示時のアニメーション（このままでOK） */
#class-badge.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 内側のデザイン（一本化したきれいな楕円バッジ） */
.badge-class {
    display: inline-block;                     /* 形状を安定させる */
    font-family: 'DM Mono', monospace;
    font-size: 18px;
    color: rgba(56, 189, 248, 0.90);          /* 鮮やかな水色文字 */
    border: 1px solid rgba(56, 189, 248, 0.3); /* 楕円の枠線 */
    padding: 8px 20px;                         /* 内側の余白 */
    border-radius: 24px;                       /* きれいなカプセル型の1本の楕円にする */
    background: rgba(2, 12, 24, 0.85);         /* 背景の濃い紺色 */
    backdrop-filter: blur(8px);                /* 背景の粒子を程よくボカす */
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 0 20px rgba(0, 6, 14, 0.6);
    white-space: nowrap;                       /* 文字の意図しない改行を防ぐ */
}

/* ===== 凡例パネル ===== */
#legend {
    position: fixed; 
    bottom: 24px; 
    right: 24px;
    width: 190px;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    user-select: none;
    z-index: 90;
}
.legend-hd {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 2px;
}
.legend-row {
    display: flex;
    align-items: center;
    height: 20px;
    transition: opacity 0.2s ease;
}
.legend-dot {
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
}
.legend-name {
    font-size: 12px;
    color: var(--text);
    font-weight: 400;
}
.legend-val {
    margin-left: auto;
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    text-align: right;
}

/* ===== フッター情報 ===== */
#footer {
    position: fixed; bottom: 24px; left: 24px;
    z-index: 90;
    font-size: 10px;
    color: var(--muted);
    line-height: 1.6;
    font-family: 'DM Mono', monospace;
}

/* ===== 画面中央 清浄度クラス表示 ===== */
#center-display {
    position: fixed;
    top: 72px;        /* ヘッダー（高さ56px）の下に程よい余白で配置 */
    left: 28px;       /* ヘッダーの横の余白（28px）と縦ラインを綺麗に揃える */
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* 左揃えに変更 */
    gap: 6px;
    pointer-events: none;
    text-align: left;        /* テキストを左寄せに変更 */
}
#center-iso {
    font-family: 'DM Mono', monospace;
    font-size: 36px;  /* 2D版のスマートなサイズ感に調整 */
    font-weight: 500;
    letter-spacing: 0.06em;
    color: rgba(196, 216, 232, 1.00);
    line-height: 1;
}
#center-fed {
    font-family: 'DM Mono', monospace;
    font-size: 20px;
    letter-spacing: 0em;
    color: rgba(56, 189, 248, 0.90); /* ★0.90（または1.00）に修正して2D版の鮮やかさに統一 */
    font-weight: 400;
    line-height: 1;
}

/* ===== チェックボックスラベル ===== */
.switch-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    font-weight: 400;
}
.switch-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 3px;
    background: rgba(2, 12, 24, 0.6);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.switch-label input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}
.switch-label input[type="checkbox"]:checked::after {
    content: "✓";
    font-size: 10px;
    color: #00060e;
    font-weight: bold;
}
.switch-label:hover input[type="checkbox"] {
    border-color: var(--accent);
    box-shadow: 0 0 4px rgba(56, 189, 248, 0.4);
}

/* ===== スライダー & 数値入力 ===== */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    background: rgba(56, 189, 248, 0.3);
    height: 4px;
    border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    background: var(--accent);
    border-radius: 50%;
    margin-top: -5px;
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
    transition: transform 0.1s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}
input[type="range"]:focus {
    outline: none;
}

input[type="number"] {
    background: rgba(2, 12, 24, 0.6);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    text-align: center;
    height: 28px;
    width: 50px;
    outline: none;
    transition: all 0.2s ease;
}
input[type="number"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.25);
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ===== 画面左下の対象空間情報パネル ===== */
#spatial-info-panel {
    position: fixed;
    bottom: 28px;
    left: 28px;
    background: rgba(2, 12, 24, 0.75);         /* 深い紺色の半透明背景 */
    border: 1px solid rgba(56, 189, 248, 0.3);  /* 水色の細い枠線 */
    border-left: 4px solid var(--accent);       /* 左側だけ太くしてアクセントに */
    padding: 12px 24px;
    border-radius: 4px;                         /* シャープな角丸 */
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.15); /* ほのかなネオン光彩効果 */
    backdrop-filter: blur(10px);                /* 背後の粒子を程よくボカす */
    -webkit-backdrop-filter: blur(10px);
    z-index: 999;                               /* 前面に確実に表示 */
    pointer-events: none;                       /* マウス操作（回転など）を邪魔しない */
}

/* 上部の小さな英語ラベル */
.spatial-label {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--muted);                        /* メーター感のある少しくすんだ青 */
    letter-spacing: 0.15em;
    margin-bottom: 2px;
}

/* メインのサイズ文字 */
.spatial-value {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 22px;                            /* 大きく太くして圧倒的に目立たせる */
    font-weight: 700;
    color: #ffffff;                             /* クッキリ見える白文字 */
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.5); /* 文字自体を少し発光させる */
}

/* (固定) の文字 */
.spatial-sub {
    font-size: 14px;
    color: var(--accent);                       /* テーマカラーの水色 */
    font-weight: 400;
    margin-left: 4px;
}