body {
    font-family: Arial, sans-serif;
    background-color: #111;
    color: #eee;
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#container {
    display: flex;
    width: 100%;
    height: 100%;
}

#controls {
    width: 450px;
    height: 100%;
    background-color: #222;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    border-right: 2px solid #444;
}

h1, h2 {
    color: #0af;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

h4 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

h4 > span:first-child {
    font-size: 1.1em;
    color: #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

h4 .planet-name {
    background: transparent;
    border: none;
    color: #ddd;
    font-size: 1.1em;
    font-weight: bold;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 3px;
    width: 250px;
    font-family: inherit;
    transition: background-color 0.2s, color 0.2s;
}

h4 .planet-name:hover, h4 .planet-name:focus {
    background-color: #333;
    color: #fff;
    outline: 1px solid #555;
}

.control-section {
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

.form-grid-2-col {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 5px 15px;
    align-items: center;
}

label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
}

input[type="number"], select, textarea {
    width: 100%;
    padding: 8px;
    background-color: #333;
    border: 1px solid #555;
    color: #eee;
    border-radius: 4px;
    box-sizing: border-box;
    font-family: inherit;
}

textarea {
    resize: vertical;
    min-height: 50px;
}

input[type="color"] {
    min-height: 38px;
}

#quick-generate {
    padding: 15px;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 5px;
    margin-bottom: 15px;
}

#quick-generate button {
    background-color: #089;
}

#quick-generate button:hover {
    background-color: #3ad;
}

.multi-select {
    display: flex;
    gap: 5px;
}

button {
    background-color: #0af;
    color: #111;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    margin-top: 10px;
    transition: background-color 0.2s, color 0.2s;
}

button:disabled {
    background-color: #555;
    color: #888;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background-color: #4cf;
}

button.small-button {
    width: auto;
    padding: 5px 10px;
    font-size: 0.8em;
    margin-top: 5px;
    background-color: #078;
}

button.small-button:hover:not(:disabled) {
    background-color: #09a;
}

.planet-controls, .asteroid-belt-controls {
    border: 1px solid #444;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    position: relative;
    background-color: #2a2a2a;
}

.planet-controls .delete-planet, .asteroid-belt-controls .delete-belt {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #c21;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 24px;
    padding: 0;
    text-align: center;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

.planet-controls .delete-planet:hover {
    background: #e42;
}

.asteroid-belt-controls .delete-belt:hover {
    background: #e42;
}

.habitability-status {
    font-size: 0.8em;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: normal;
    color: #fff;
    transition: background-color 0.5s;
}

.planet-temp-display {
    width: 100%;
    padding: 8px;
    background-color: #1a1a1a; /* Darker to indicate read-only */
    border: 1px solid #444;
    color: #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-family: inherit;
    min-height: 35px; /* Match input height */
    line-height: 1.2;
    font-size: 0.9em;
}

.habitable {
    background-color: #2a2;
    border: 1px solid #4f4;
}

.not-habitable {
    background-color: #333;
    border: 1px solid #555;
    color: #aaa;
}

.moon-controls {
    border: 1px dashed #666;
    padding: 10px;
    margin-top: 10px;
    margin-left: 20px;
    border-radius: 4px;
    position: relative;
    background: #333;
}

.moon-controls .delete-moon {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #a11;
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0;
    text-align: center;
    cursor: pointer;
    font-size: 12px;
}

#system-info {
    margin-top: 15px;
    padding: 10px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.85em;
    line-height: 1.6;
}

#system-info > br {
    display: block;
    margin-bottom: 4px;
    content: "";
}

#event-log {
    margin-top: 10px;
    padding: 10px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    height: 150px; /* Fixed height for the log */
    overflow-y: auto;
    display: flex;
    flex-direction: column; /* Newest events at the top */
    font-size: 0.9em;
    line-height: 1.4;
}

.event-log-entry {
    padding-bottom: 4px;
    margin-bottom: 4px;
    border-bottom: 1px solid #333;
}

.event-log-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.event-log-entry .age {
    color: #0af;
    font-weight: bold;
    margin-right: 5px;
}

em {
    font-style: italic;
    color: #fff;
}

.simulation-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.simulation-controls button {
    flex-grow: 1;
}

#simulation {
    flex-grow: 1;
    background-color: #000;
    position: relative;
    overflow: hidden;
    cursor: grab;
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
                      radial-gradient(circle, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px, 80px 80px;
    background-position: 0 0, 40px 40px;
}

#simulation:active {
    cursor: grabbing;
}

#system-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    transform-origin: center;
}

.celestial-body {
    position: absolute;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    will-change: top, left, opacity;
    transition: width 0.5s, height 0.5s, background-color 0.5s, box-shadow 0.5s, opacity 0.5s;
}

@keyframes pulsar-beam {
    0% { transform: rotate(0deg) scaleY(1); opacity: 0.8; }
    50% { transform: rotate(180deg) scaleY(0.7); opacity: 0.4; }
    100% { transform: rotate(360deg) scaleY(1); opacity: 0.8; }
}

.star.pulsar::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -400%; /* Extend way out */
    width: 900%; /* Very wide */
    height: 4px; /* Thin beam */
    margin-top: -2px;
    background: linear-gradient(90deg, transparent, rgba(200,200,255,0.7), transparent);
    animation: pulsar-beam 0.5s linear infinite;
    z-index: 9;
}

@keyframes magnetar-flare {
    0%, 100% { box-shadow: 0 0 15px #f0f, 0 0 25px #f0f, 0 0 40px #fff; opacity: 0.8; }
    50% { box-shadow: 0 0 30px #f8f, 0 0 50px #f8f, 0 0 80px #fff; opacity: 1; }
}

.star.magnetar {
    animation: magnetar-flare 3s ease-in-out infinite;
}

.star {
    z-index: 10;
}

.planet-orbit {
    position: absolute;
    left: 50%;
    top: 50%;
    border: 1px dotted #555;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    transition: opacity 0.5s;
}

.habitable-zone {
    position: absolute;
    left: 50%;
    top: 50%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 255, 0, 0.08);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.2) inset, 0 0 10px rgba(0, 255, 0, 0.2);
    box-sizing: border-box;
}

.asteroid-belt-container {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 3;
    transition: opacity 0.5s;
}

.asteroid {
    position: absolute;
    transform: translate(-50%, -50%);
    background-color: #77695c;
    border-radius: 50%;
}

.planet {
    z-index: 5;
}

.moon {
    z-index: 4;
}

#lifecycle-display {
    padding-top: 10px;
}

#lifecycle-display ul {
    list-style-type: none;
    padding-left: 20px;
    margin: 0;
    border-left: 2px solid #555;
    position: relative;
}

#lifecycle-display li {
    padding: 5px 10px;
    margin-bottom: 8px;
    position: relative;
    transition: background-color 0.3s, border-color 0.3s;
    font-size: 0.9em;
}

#lifecycle-display li::before {
    content: '';
    position: absolute;
    left: -28px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #777;
    border: 2px solid #222;
    transition: background-color 0.3s;
}

#lifecycle-display li.current-stage {
    background-color: rgba(0, 170, 255, 0.2);
    border-radius: 4px;
    border-left: 3px solid #0af;
    padding-left: 7px;
}

#lifecycle-display li.current-stage::before {
    background: #0af;
    transform: translateY(-50%) scale(1.2);
}