:root {
    --bg-color: #010105;
    --panel-bg: #050710;
    --accent-cyan: #00f2ff;
    --accent-orange: #ff6a00;
    --accent-gold: #ffd700;
    --accent-pink: #ff0077;
    --text-main: #f0f4f8;
    --text-muted: #4a5568;
    --border-color: #1a2238;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Courier New', monospace;
    margin: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.game-wrapper {
    display: flex;
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    min-height: 580px;
    max-height: 800px;
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 242, 255, 0.05);
}

.main-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 15px;
    border-right: 2px solid var(--border-color);
    height: 100%;
}

.header-panel h1 {
    color: var(--accent-cyan);
    font-size: 20px;
    margin: 0;
    letter-spacing: 3px;
    text-shadow: 0 0 8px rgba(0, 242, 255, 0.5);
}

.subtitle {
    font-size: 11px;
    color: #5a6578;
    margin: 3px 0 0 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    background: rgba(0, 242, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.stat-box .val {
    font-size: 22px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.stat-box .lbl {
    font-size: 10px;
    color: var(--accent-cyan);
    letter-spacing: 1px;
}

/* 宇宙ビューア */
.view-panel {
    flex: 1;
    background: #000002;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    margin-bottom: 10px;
    z-index: 1; /* ベースの優先順位を設定 */
}

canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2; /* 粒子スクリーン */
}

.visual-overlay {
    position: absolute;
    top: 10px; left: 10px;
    font-size: 10px;
    color: rgba(0, 242, 255, 0.4);
    pointer-events: none;
    letter-spacing: 2px;
    z-index: 3; /* 文字オーバーレイ */
}

/* 修正：マニュアル画面を全要素の中で「絶対的最前面」にする */
.manual-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(1, 1, 5, 0.95); /* 背景の透け具合を調整 */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    z-index: 9999 !important; /* Canvasを完全に突き破る最前面設定 */
}

.manual-content {
    background: #050814;
    border: 1px solid var(--accent-cyan);
    border-radius: 8px;
    width: 100%;
    height: 100%;
    padding: 15px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.2);
}

.manual-scroll {
    flex: 1;
    overflow-y: auto;
    text-align: left;
    font-size: 11px;
    line-height: 1.6;
    padding-right: 5px;
}

.manual-scroll h3 {
    color: var(--accent-gold);
    font-size: 13px;
    margin: 15px 0 5px 0;
    border-left: 3px solid var(--accent-gold);
    padding-left: 6px;
}

.manual-scroll h4 {
    color: var(--accent-cyan);
    font-size: 11px;
    margin: 10px 0 2px 0;
}

.manual-scroll p {
    margin: 0 0 10px 0;
    color: #cbd5e1;
}

.bottom-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.control-btn {
    background: #081125;
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
    padding: 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    flex: 2;
    transition: 0.2s;
}

.control-btn:hover:not(:disabled) {
    background: var(--accent-cyan);
    color: #000;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.5);
}

.special-btn {
    background: linear-gradient(45deg, #ff0055, #ff6a00);
    color: #fff;
    border: none;
    flex: 1;
    animation: glowPulse 1.5s infinite alternate;
}

@keyframes glowPulse {
    0% { box-shadow: 0 0 5px #ff0055; }
    100% { box-shadow: 0 0 20px #ff6a00; }
}

.log-panel {
    background: #020307;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    height: 90px;
    overflow-y: auto;
    font-size: 11px;
    line-height: 1.5;
}

.log-entry { margin-bottom: 5px; padding-left: 6px; border-left: 2px solid var(--accent-cyan); color: #cbd5e1; }
.log-science { border-left-color: var(--accent-pink); color: #fbcfe8; font-style: italic; }

/* 右側パネル */
.sidebar-column {
    width: 320px;
    display: flex;
    flex-direction: column;
    padding: 15px;
    background: rgba(0,0,0,0.3);
    height: 100%;
}

.sidebar-title {
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
    letter-spacing: 1px;
}

.upgrade-grid {
    height: 160px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.item-btn {
    background: #040714;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.item-btn:hover:not(:disabled) { border-color: var(--accent-cyan); background: #0c122c; }
.item-btn:disabled { opacity: 0.15; cursor: not-allowed; }
.item-title { font-weight: bold; font-size: 11px; display: block; color: #fff; }
.item-desc { font-size: 9px; color: #64748b; display: block; margin: 2px 0 4px 0; line-height: 1.3; }
.item-cost { font-size: 10px; color: var(--accent-cyan); font-weight: bold; text-align: right; display: block; }

.catalog-panel {
    flex: 1;
    overflow-y: auto;
    background: #010205;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.catalog-item {
    background: #060919;
    border: 1px solid #13192e;
    border-radius: 6px;
    padding: 8px;
    font-size: 11px;
    opacity: 0.2;
    transition: all 0.4s ease;
}

.catalog-item.unlocked {
    opacity: 1;
    border-color: var(--accent-gold);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.15);
    background: linear-gradient(135deg, #090e26 0%, #040612 100%);
}

.catalog-item .star-name {
    font-weight: bold;
    color: var(--accent-gold);
    display: block;
    font-size: 12px;
}

.catalog-item .star-desc {
    color: #94a3b8;
    display: block;
    margin-top: 4px;
    font-size: 10px;
    line-height: 1.4;
}

.sys-btn {
    background: none; border: none; color: #334155; font-size: 9px;
    cursor: pointer; text-decoration: underline; text-align: right; margin-top: 5px;
}
.sys-btn:hover { color: #94a3b8; }