:root {
    --primary: #8b0000;
    /* Dark Red - Wani Clan Theme */
    --secondary: #2f4f4f;
    /* Dark Slate Gray */
    --accent: #d4af37;
    /* Gold - Premium feel */
    --bg-dark: #121212;
    --bg-panel: #1e1e1e;
    --text: #e0e0e0;
    --text-muted: #a0a0a0;
    --border: #333;
    --danger: #b22222;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
}

header {
    background: linear-gradient(90deg, var(--primary), #4a0000);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--accent);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

nav a {
    color: var(--text);
    text-decoration: none;
    margin-left: 1.5rem;
    font-weight: 500;
    transition: color 0.3s;
}

nav a:hover,
nav a.active {
    color: var(--accent);
}

#editor-layout {
    display: flex;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    width: 360px;
    min-width: 320px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.section-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

#unit-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}

.unit-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.unit-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.unit-item.selected {
    background: rgba(139, 0, 0, 0.2);
    border-left: 4px solid var(--accent);
}

.io-controls {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--border);
}

/* Preview Area */
#preview-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    align-items: center;
    background: radial-gradient(circle, #222 0%, #121212 100%);
}

.preview-box {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
    background: #000;
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#unit-preview-container {
    position: relative;
    width: 256px;
    height: 256px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#preview-img {
    max-width: 100%;
    max-height: 100%;
    z-index: 2;
    image-rendering: pixelated;
}

#range-circle {
    position: absolute;
    border: 2px dashed rgba(212, 175, 55, 0.4);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    transition: width 0.3s, height 0.3s;
}

.simulation-info {
    margin-top: 2rem;
    background: rgba(0, 0, 0, 0.4);
    padding: 1rem 2rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 500px;
}

.simulation-info h3 {
    margin-bottom: 0.5rem;
    color: var(--accent);
}

/* Params Panel - 2列コンパクト */
#params-panel {
    width: 380px;
    min-width: 320px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.scroll-area {
    padding: 1rem;
    overflow-y: auto;
    flex-grow: 1;
}

.field-group {
    margin-bottom: 1.25rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
    align-items: start;
}

.field-group h3 {
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
    margin-bottom: 0.6rem;
    color: var(--accent);
    grid-column: 1 / -1;
}

.field-group .param-item {
    min-width: 0;
}

.field-group .param-full {
    grid-column: 1 / -1;
}

.field-group .param-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    grid-column: 1 / -1;
}

/* 現在値・最大値を同じ行に並べる（折り返さない） */
.field-group .param-row.param-row-2 {
    flex-wrap: nowrap;
}

.field-group .param-row-2 .param-item {
    flex: 1;
    min-width: 0;
    max-width: 50%;
}

.field-group .input-with-btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

.field-group .input-with-btn input {
    flex: 1;
    min-width: 0;
}

.field-group .btn-small-inline {
    padding: 4px 10px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.field-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.field-group input,
.field-group select {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    box-sizing: border-box;
}

#attack-motion-preview-wrap {
    grid-column: 1 / -1;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
}

#attack-motion-preview {
    display: block;
    width: 100%;
    max-width: 200px;
    height: 56px;
    margin: 0 auto;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
}

label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

input,
select {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.bottom-actions {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    background: #1a1a1a;
    border-top: 1px solid var(--border);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: filter 0.2s;
}

.btn-secondary {
    background: var(--secondary);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}


/* ツールチップや特定のUIがクリックを妨げないように強制設定 */
#ui-overlay {
    pointer-events: none;
}

#ui-overlay>* {
    pointer-events: auto;
    /* 子要素（ボタンなど）はクリック可能にする */
}

/* ユニットカードのホバー等で透明な要素が重なる場合の対策 */
.unit-card {
    pointer-events: auto;
}