:root {
    /* Cyber Commander Theme Palette */
    --bg-main: #121212;
    --bg-panel: #1e1e1e;
    --bg-card: #252525;
    --bg-input: #2d2d2d;

    --text-primary: #f0f0f0;
    --text-secondary: #aaaaaa;
    --text-muted: #666666;

    --accent-color: #ff4757;
    /* Neon Red */
    --accent-hover: #ff6b81;
    --accent-glow: rgba(255, 71, 87, 0.3);

    --border-color: #333333;
    --border-focus: #555555;

    --success-color: #2ed573;
    --danger-color: #ff4757;
    --warning-color: #ffa502;
    --info-color: #1e90ff;

    --sidebar-width: 280px;
    --header-height: 60px;

    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.2);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    font-size: 16px;
    /* Base size */
    line-height: 1.5;
    overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#app {
    display: flex;
    width: 100%;
    height: 100%;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--bg-panel);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-right: 1px solid var(--border-color);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}



/* Desktop Title */
.sidebar h2 {
    margin-bottom: 30px;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 1px;
    background: linear-gradient(45deg, var(--accent-color), #ff6b81);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    cursor: pointer;
    /* [NEW] Clickable */
}

.logo {
    font-size: 1.5rem;
    margin-bottom: 2.5rem;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo::before {
    content: '';
    display: block;
    width: 4px;
    height: 24px;
    background-color: var(--accent-color);
    border-radius: 2px;
}

/* [FIX] Make nav scrollable so footer is always visible */
.sidebar nav {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Flexbox scroll fix */
    margin-bottom: 15px;
    padding-right: 4px;
    /* Avoid scrollbar overlap */
}

.sidebar nav button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.sidebar nav button:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.sidebar nav button.active {
    background-color: rgba(255, 71, 87, 0.1);
    /* Low opacity accent */
    color: var(--accent-color);
}

.sidebar nav button.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 50%;
    background-color: var(--accent-color);
    border-radius: 0 2px 2px 0;
}

/* Badge update */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--success-color);
    color: #000;
    font-weight: 700;
    border-radius: 12px;
    /* Capsule */
    padding: 0 6px;
    height: 18px;
    font-size: 0.75rem;
    margin-left: auto;
    margin-left: auto;
    /* Push to right */
    min-width: 18px;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    /* Push to bottom */
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.sidebar-footer #mod-version {
    margin-bottom: 5px;
    color: var(--text-secondary);
}

.sidebar-footer .copyright {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* --- Main Content --- */
.content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
    background-color: var(--bg-main);
}

.tab-content {
    display: none;
    height: 100%;
    /* [FIX] Revert to fixed height for App-like layout */
    flex-direction: column;
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    /* [FIX] Enable scrolling for individual tabs */
}

/* [FIX] Console layout must be fixed height with no outer scroll */
#tab-console {
    overflow-y: hidden;
}

.tab-content.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

/* --- Cards / Containers --- */
#map-container {
    flex: 1;
    background-color: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    min-height: 400px;
    touch-action: none;
    position: relative;
    /* [FIX] Disable browser zoom/pan to let Leaflet handle it */
}

/* ホード（ブラッドムーン）進行中の赤背景。地図全体（地形・マーカー）に薄い赤を重ねる。
   Leafletの操作UI(z-index:1000)より下・pointer-events:none のため操作には影響しない */
#map-container.bloodmoon-active {
    border-color: #c0392b;
}
#map-container.bloodmoon-active::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 300;
    background: rgba(160, 0, 0, 0.22);
    box-shadow: inset 0 0 90px rgba(255, 30, 30, 0.55);
    animation: bloodmoon-pulse 3s ease-in-out infinite;
}
@keyframes bloodmoon-pulse {
    0%, 100% { background: rgba(160, 0, 0, 0.22); }
    50%      { background: rgba(160, 0, 0, 0.34); }
}

/* --- Forms & Inputs --- */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* [MOD] Modern Toggle Switch for Checkboxes */
/* [MOD] Modern Toggle Switch for Checkboxes */
.form-group input[type="checkbox"],
.config-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 50px !important;
    /* [FIX] Override inline style="width:auto" */
    height: 26px !important;
    background: var(--bg-input);
    border-radius: 13px;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--border-color);
    outline: none;
    transition: all 0.3s;
    vertical-align: middle;
    margin-right: 10px;
    display: inline-block;
    /* [FIX] Ensure block layout */
    flex-shrink: 0;
    /* [FIX] Prevent shrinking in flex containers */
}

.form-group input[type="checkbox"]::after,
.config-item input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-group input[type="checkbox"]:checked,
.config-item input[type="checkbox"]:checked {
    background: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
}

.form-group input[type="checkbox"]:checked::after,
.config-item input[type="checkbox"]:checked::after {
    transform: translateX(24px);
    background: #fff;
}

/* Hover Effect */
.form-group input[type="checkbox"]:hover,
.config-item input[type="checkbox"]:hover {
    border-color: #777;
    /* [FIX] Lighter border on hover */
}

input[type="password"],
input[type="number"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 10px 16px;
    /* [FIX] Reduce padding to match buttons/toggles */
    border-radius: 6px;
    border: 1px solid #555;
    /* [FIX] Higher contrast border */
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

/* [FIX] Text Input Visibility */
input[type="text"] {
    width: 100%;
    padding: 10px 16px;
    border-radius: 6px;
    border: 1px solid #555;
    /* [FIX] Higher contrast */
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* --- Buttons --- */
button {
    font-family: inherit;
    cursor: pointer;
}

/* Common Button Style */
.btn-primary,
#btn-save-scheduler,
#btn-save-conf,
#btn-send-chat,
#btn-send-command {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
}

.btn-primary:hover,
#btn-save-scheduler:hover,
#btn-save-conf:hover,
#btn-send-chat:hover,
#btn-send-command:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: #3a3a3a;
    border-color: #666;
}

/* Small Buttons (Map) */
.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 4px;
}

.btn-small:hover {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 10px;
    background-color: var(--bg-panel);
    /* Card like */
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

th {
    background-color: #252525;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    padding: 16px;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: var(--text-primary);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Action Buttons in Table */
.action-btn {
    padding: 6px 12px;
    margin-right: 6px;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-kick {
    background-color: var(--warning-color);
    color: #000;
}

.btn-ban {
    background-color: var(--danger-color);
    color: #fff;
}

/* --- Console & Chat --- */
.console-container {
    display: flex;
    flex-direction: row;
    /* Horizontal Split */
    height: 100%;
    width: 100%;
    gap: 0;
    /* Gutter handles spacing */
    background: transparent;
}

.console-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-radius: 8px;
    /* padding: 10px; handled by flex children spacing */
    padding: 1rem;
    flex: 1;
    min-width: 250px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
}

#console-gutter {
    width: 12px;
    background: transparent;
    cursor: col-resize;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    margin: 0 4px;
    transition: background 0.2s;
    border-radius: 4px;
}

#console-gutter:hover {
    background: rgba(255, 255, 255, 0.1);
}

#console-gutter::after {
    content: "⋮";
    color: var(--text-muted);
    font-size: 14px;
}

.log-window {
    /* Shared for #chat-output and #console-output */
    flex: 1;
    background-color: #111;
    /* Pitch black for logs */
    color: #e0e0e0;
    font-family: 'Consolas', 'Monaco', monospace;
    /* Code font */
    font-size: 14px;
    line-height: 1.3;
    padding: 12px;
    overflow-y: auto;
    margin-bottom: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: 100%;

    /* [NEW] Whitespace handling */
    white-space: pre-wrap;
    word-break: break-all;
}

/* Hanging Indent for Log Lines */
.log-line {
    padding-left: 2em;
    /* Indent wrapped lines */
    text-indent: -2em;
    /* Pull first line back */
    margin-bottom: 2px;
    /* Slight separation */
    font-family: 'Consolas', 'Monaco', monospace;
}

#chat-output {
    background-color: #15151b;
}

/* Slightly lighter for chat */
#console-output {
    color: #81ecec;
}

/* System text color */

/* Chat items */
.chat-msg {
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: baseline;
    animation: fadeIn 0.2s;
}

.chat-time {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-right: 8px;
    font-family: system-ui;
    min-width: 45px;
}

.chat-sender {
    font-weight: 700;
    color: var(--info-color);
    margin-right: 8px;
}

.chat-text {
    color: var(--text-primary);
    word-break: break-all;
}

.input-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.input-row input {
    flex: 1;
    /* Adjust input style specifically for chat bar if needed */
}

/* --- Map Toolbar --- */
.map-toolbar {
    background-color: var(--bg-panel);
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    /* Floating toolbar look */
    margin-bottom: 16px;
    align-items: center;
    flex-shrink: 0;
    /* [FIX] Prevent crushing */
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 16px;
    border-right: 1px solid var(--border-color);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Toggle Button Modern */
.toggle-btn {
    position: relative;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
}

.toggle-btn input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-btn span {
    background-color: var(--bg-input);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    font-weight: 500;
}

.toggle-btn:hover span {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.toggle-btn input:checked~span {
    background-color: rgba(255, 71, 87, 0.15);
    /* Accent tint */
    color: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.2);
}

/* Config Editor Colors */
.config-group {
    border: 1px solid var(--border-color);
    background: var(--bg-panel);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-card);
}

.config-item {
    margin-bottom: 20px;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 20px;
}

.config-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* Game Time Display Transition */
#game-time-display {
    display: inline-block;
    /* 高さ指定のためにブロック化 */
    min-height: 1.5em;
    /* 最低高さを確保して潰れ防止 */
    line-height: 1.5;
    /* 行高さを固定 */
    font-variant-numeric: tabular-nums;
    /* 数字の幅ズレ防止 */
}

/* Mobile Layout Optimization (Stats & Time in one row) */
@media (max-width: 768px) {
    .stats-group {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        width: 100%;
        overflow-x: auto;
        gap: 8px;
        white-space: nowrap;
        padding-top: 5px;
        /* 少し隙間あける */
    }

    .stats-row {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 0 !important;
        /* 強制的にマージン削除 */
    }

    /* ラベル短縮 */
    .stat-badge {
        font-size: 0.85rem;
        padding: 2px 5px;
    }

    /* モバイルヘッダー調整（もし必要なら） */
    .map-toolbar {
        padding: 8px;
        gap: 8px;
    }
}

#game-time-display.fade-out {
    opacity: 0;
}

.config-item label {
    color: var(--text-primary);
    font-size: 1rem;
}

.config-item .desc {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Status Messages */
.status-msg {
    margin-top: 8px;
    font-weight: 500;
}

.status-success {
    color: var(--success-color);
}

.status-error {
    color: var(--danger-color);
}

.hidden {
    display: none !important;
}

/* Chat Log Enhancements */
.chat-msg {
    padding: 2px 4px;
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95em;
    line-height: 1.4;
}

.chat-time {
    color: #888;
    font-size: 0.8em;
    margin-right: 6px;
    opacity: 0.7;
}

.chat-sender {
    font-weight: bold;
    color: #4db8ff;
    margin-right: 4px;
    white-space: nowrap;
}

.chat-text {
    color: #e0e0e0;
}

.chat-msg.public .chat-text {
    color: #ffffff;
}

.chat-msg.private .chat-text {
    color: #ff00ff;
}

/* System Events in Chat */
.chat-msg.login {
    border-left: 3px solid #00ff00;
    background: rgba(0, 255, 0, 0.05);
}

.chat-msg.login .chat-sender {
    color: #00ff00;
}

.chat-msg.login .chat-text {
    color: #ccffcc;
    font-style: italic;
}

.chat-msg.logout {
    border-left: 3px solid #888;
    background: rgba(128, 128, 128, 0.05);
}

.chat-msg.logout .chat-sender {
    color: #aaaaaa;
}

.chat-msg.logout .chat-text {
    color: #cccccc;
    font-style: italic;
}

.chat-msg.death {
    border-left: 3px solid #ff4444;
    background: rgba(255, 0, 0, 0.1);
}

.chat-msg.death .chat-sender {
    color: #ff4444;
}

.chat-msg.death .chat-text {
    color: #ffcccc;
    font-weight: bold;
}

/* Player Table Column Alignment */

/* Global Alignment: All Center */
#players-table th,
#players-table td {
    text-align: center;
    padding: 12px;
}

/* Status Indicator */
.status-online {
    width: 8px;
    height: 8px;
    background-color: #00ff00;
    border-radius: 50%;
    margin: 0 auto;
    box-shadow: 0 0 4px #00ff00;
}

/* Player List Header & Controls */
.header-with-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    padding-bottom: 10px;
}

.header-with-controls h3 {
    margin: 0;
    border: none;
    padding: 0;
}

.toggle-group {
    display: flex;
    background-color: var(--bg-input);
    border-radius: 6px;
    padding: 2px;
}

.toggle-option {
    padding: 6px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: all 0.2s;
    user-select: none;
    margin-bottom: 0;
    font-weight: 500;
}

.toggle-option input {
    display: none;
}

.toggle-option.active {
    background-color: var(--bg-panel);
    color: var(--accent-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    font-weight: 700;
}

.toggle-option:hover:not(.active) {
    color: var(--text-primary);
}

.status-offline {
    width: 6px;
    height: 6px;
    background-color: #666;
    border-radius: 50%;
    margin: 0 auto;
}

/* [NEW] Map Tooltip Fading */
.hide-tooltips .player-label {
    opacity: 0 !important;
    transition: opacity 0.5s ease;
}

.player-label {
    opacity: 1;
    transition: opacity 0.5s ease;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #444;
    /* Added border */
    font-weight: bold;
    font-size: 12px;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    /* Enhanced shadow */
    text-align: center;
    /* Center name */
    padding: 2px 4px;
    /* Padding */
}

.tooltip-name {
    margin-bottom: 2px;
}

/* HP Bar Styles (Tooltip Version) */
.hp-bar-container-tooltip {
    width: 80px;
    /* Slight wider than before */
    height: 6px;
    background-color: #333;
    border: 1px solid #000;
    border-radius: 2px;
    overflow: hidden;
    margin: 2px auto 0 auto;
    /* Center in tooltip */
}

.hp-bar {
    height: 100%;
    background-color: #2ed573;
    /* Green */
    width: 100%;
    /* Default 100% */
    transition: width 0.3s ease;
}

/* Critical HP (< 30%) */
.hp-critical {
    background-color: #ff4757;
    /* Red */
    animation: blink-critical 0.5s infinite alternate;
}

@keyframes blink-critical {
    0% {
        opacity: 1;
        box-shadow: 0 0 5px #ff4757;
    }

    100% {
        opacity: 0.4;
        box-shadow: 0 0 1px #ff4757;
    }
}



/* [NEW] Map Header Stats Group */
.stats-group {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding-right: 0 !important;
    /* Override default toolbar-group padding if needed */
}

.stats-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#game-time-display {
    font-family: 'Consolas', monospace;
    font-weight: bold;
    color: var(--text-primary);
    /* [MOD] Default white */
    min-width: 140px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 1rem;
    /* [MOD] Adjusted to 1rem as requested */
    letter-spacing: 0.5px;
}

/* [NEW] Region Grid Styles */
.custom-region-line {
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 1;
    stroke-dasharray: 5, 5;
    /* Dashed line */
    pointer-events: none;
    /* Let clicks pass through */
}

.region-label-icon {
    background: transparent;
    border: none;
}

.region-label-text {
    color: rgba(255, 255, 255, 0.5);
    font-size: 10px;
    font-family: monospace;
    text-align: center;
    white-space: nowrap;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
}

/* [NEW] Blink Animation for Hostiles */
@keyframes blink {
    0% {
        opacity: 0.9;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }

    100% {
        opacity: 0.9;
        transform: scale(1);
    }
}

/* [NEW] Map Toolbar Stats */
.stat-badge {
    color: var(--text-secondary);
    font-size: 1rem;
    /* [MOD] Updated to 1rem */
    margin-right: 12px;
}

.stat-badge b {
    color: var(--text-primary);
    font-family: monospace;
    font-size: 1rem;
    margin-left: 4px;
}

/* [NEW] Shake Animation Class for Leaflet Image Icons */
.vehicle-shake {
    animation: shake 0.8s infinite;
    display: block;
    /* Ensure it behaves correctly inside div */
}

/* [NEW] Vertical Bounce Animation for Vehicles */
@keyframes shake {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

/* [NEW] Player Icon Rotation Smoothing */
.player-rotation-anim {
    transition: transform 0.5s linear;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* [NEW] Auto-Message Slots */
.automsg-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #2a2a2a;
    margin-bottom: 5px;
    border-radius: 4px;
    border: 1px solid #444;
}

.automsg-slot label {
    font-size: 0.9em;
    color: #ccc;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Checkbox container width matching header '有効' */
.automsg-slot>label:first-child {
    width: 60px;
    justify-content: center;
}

.automsg-slot input[type="color"].am-color,
.scheduler-color {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.am-color-reset,
.scheduler-color-reset {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid #555;
    background: #222;
    color: #ccc;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 5px;
}

.am-color-reset:hover,
.scheduler-color-reset:hover {
    background: #444;
}

.automsg-slot input[type="text"].am-msg {
    flex: 2;
    padding: 6px;
    min-width: 150px;
    background: #111;
    border: 1px solid #555;
    color: #eee;
}

.automsg-slot select.am-mode {
    width: 100px;
    padding: 6px;
    background: #111;
    border: 1px solid #555;
    color: #eee;
}

.automsg-slot input[type="text"].am-value {
    width: 70px;
    padding: 6px;
    text-align: center;
    background: #111;
    border: 1px solid #555;
    color: #eee;
}

/* Count Label wrapper - Hide text "回数:" to align with header? 
   Or just style it. The HTML has <label>回数: <input></label>.
   I should probably remove the "回数:" text in HTML for perfect column alignment, 
   but CSS masking is easier.
*/
.automsg-slot>label:last-child {
    width: 60px;
    font-size: 0;
    /* Hide "回数:" text */
}

.automsg-slot input[type="number"].am-count {
    width: 100%;
    font-size: 14px;
    /* Restore font size for input */
    padding: 6px;
    background: #111;
    border: 1px solid #555;
    color: #eee;
    text-align: center;
}

/* [NEW] Detailed Popup Styles */
/* [NEW] Premium Expandable Tooltip Styles (Light Theme) */
.player-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    transition: none !important;
}

/* Hide the little triangle tip */
.player-label:before,
.player-label:after {
    display: none !important;
}

/* Glassmorphism Container (White) */
/* Marker Overrides for Custom Upward Label */
.player-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    overflow: visible !important;
    width: 0;
    height: 0;
}

.player-label:before {
    display: none !important;
}

.tooltip-content {
    position: absolute;
    bottom: 20px;
    /* Fixed distance from arrow icon */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.85);
    /* White, semi-transparent */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 50px;
    /* Stadium/Pill Shape */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    /* Softer shadow */

    padding: 6px 16px;
    /* Adjust padding for rounded ends */
    text-align: center;
    width: auto;
    /* Allow flexibility */
    min-width: 100px;
    max-width: 120px;
    /* Cap width in minimized state */

    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    /* overflow: hidden を削除（border-radius と組み合わさるとヒット領域が pill 形状にクリップされ、角がクリック不可になる） */
    /* details 側のスライドアニメ用 overflow:hidden は .tooltip-details に既にあるので問題なし */
    transform-origin: bottom center;
    color: #333;
    /* Dark text */
}

.tooltip-content.expanded {
    background: rgba(255, 255, 255, 0.98);
    /* More opaque when expanded */
    border-color: rgba(255, 255, 255, 0.9);
    width: 180px;
    /* Wider when expanded */
    max-width: none;
    border-radius: 24px;
    /* Slightly less rounded for content area, but still very round */
    padding: 12px 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

/* Header */
.tooltip-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 2;
}

.tooltip-name {
    font-size: 12px;
    font-weight: 700;
    color: #222;
    /* Dark Grey/Black */
    text-shadow: none;
    margin-bottom: 0;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.tooltip-content.expanded .tooltip-name {
    font-size: 14px;
    margin-bottom: 8px;
}

/* HP Bar Container */
.hp-bar-container-tooltip {
    width: 100%;
    max-width: 120px;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    /* Light grey track */
    border-radius: 3px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.hp-bar {
    height: 100%;
    border-radius: 3px;
    box-shadow: none;
    /* Flat look fits light theme better, or subtle */
}

/* Details Section */
.tooltip-details {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    transform: translateY(-10px);
    overflow: hidden;
    /* [FIX] Prevent content spill */
    visibility: hidden;
    /* [FIX] Ensure non-interactive */
    pointer-events: none;
    /* [FIX] No ghost clicks */
}

.tooltip-content.expanded .tooltip-details {
    max-height: 150px;
    opacity: 1;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    /* Light divider */
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
}

/* Detail Rows */
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    /* Increased from 12px */
    color: #555;
    margin-bottom: 6px;
    line-height: 1.5;
}

/* Item Button */
.btn-item-check {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.btn-item-check:hover {
    background: #f5f5f5;
    transform: scale(1.05);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.hp-text {
    font-family: 'Consolas', 'Monaco', monospace;
    font-weight: bold;
    color: #222;
    font-size: 14px;
    /* Increased from 12px */
}

.stat-text {
    color: #444;
    /* Darker grey */
    font-size: 13px;
    /* Increased from 11px */
    font-weight: 500;
}

.stat-text .val {
    font-weight: bold;
    color: #222;
}

/* [NEW] Inventory Modal Styles */
.inventory-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    display: none;
    /* Hidden by default */
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.inventory-overlay.active {
    opacity: 1;
}

.inventory-modal {
    background: rgba(20, 20, 25, 0.95);
    backdrop-filter: blur(12px);
    width: 800px;
    max-width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid #444;
    color: #eee;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.inventory-overlay.active .inventory-modal {
    transform: scale(1);
}

.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.inventory-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

.inv-close {
    cursor: pointer;
    font-size: 24px;
    color: #888;
    transition: color 0.2s;
    line-height: 1;
}

.inv-close:hover {
    color: #fff;
}

.inv-section h4 {
    margin: 16px 0 8px;
    color: #bbb;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-left: 3px solid #e74c3c;
    padding-left: 8px;
}

.inv-grid {
    display: grid;
    /* [FIX] Mobile Responsive Grid */
    /* Use repeat(auto-fill) with a % minmax to likely hit 4 or 5 columns on mobile */
    /* minmax(20%, 1fr) ensures roughly 4-5 items per row */
    /* grid-template-columns: repeat(auto-fill, minmax(18%, 1fr)); */
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    /* [MOD] Reduced size (approx -10px on mobile) */
    gap: 6px;
    padding: 4px;
}

.inv-slot {
    /* [FIX] Remove fixed size, let Grid handle it */
    width: 100%;
    /* Ensure aspect ratio 1:1 */
    aspect-ratio: 1 / 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #333;
    position: relative;
    border-radius: 6px;
    transition: background 0.2s;
    /* Ensure content centers */
    display: flex;
    justify-content: center;
    align-items: center;
}

.inv-slot:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #555;
}

.inv-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.inv-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0px 0px 2px #000, 1px 1px 0 #000;
    pointer-events: none;
}

/* Quality Colors */
.inv-quality-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    width: 100%;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.q-1 {
    background: #888;
}

/* Broken/Grey */
.q-2 {
    background: #d35400;
}

/* Orange */
.q-3 {
    background: #f39c12;
}

/* Yellow */
.q-4 {
    background: #27ae60;
}

/* Green */
.q-5 {
    background: #2980b9;
}

/* Blue */
.q-6 {
    background: #8e44ad;
}

/* Purple */

/* [NEW] Custom Inventory Tooltip */
.inv-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid #555;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    z-index: 10000;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.15s ease;
    transform: translate(-50%, -100%);
    /* Center above cursor/target */
    margin-top: -10px;
}

.inv-tooltip.visible {
    opacity: 1;
}

/* [NEW] Player Status Board Container */
.status-board {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
    min-height: 0;
    /* [FIX] Prevent overlap */
    flex-shrink: 0;
    width: 100%;
}

/* [MOD] Updated Player Card */
.player-card {
    background: linear-gradient(135deg, #1e1e24 0%, #2a2a30 100%);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px 14px;
    width: 220px;
    /* Slight Increase */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.3s;
}

.player-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

/* [NEW] Card Status Effects (Low/Critical) */
.player-card.status-low {
    border-color: #f39c12;
    animation: pulse-warning 2s infinite;
}

.player-card.status-critical {
    border-color: #e74c3c;
    animation: pulse-critical 1.5s infinite;
}

/* Clean Header */
.p-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 6px;
}

.p-card-name {
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
}

/* Stats Layout */
.p-card-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* HP Row */
.p-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.p-bar-container {
    flex: 1;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
}

.p-hp-bar {
    height: 100%;
    background: #2ed573;
    width: 100%;
    transition: width 0.3s ease-out, background-color 0.3s;
}

.p-hp-bar.mid {
    background: #f1c40f;
}

.p-hp-bar.low {
    background: #e74c3c;
}

/* Sub Stats (Food/Water) */
.p-sub-stats {
    display: flex;
    justify-content: space-between;
    margin-top: 2px;
}

.p-sub-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    /* Reduced gap */
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    /* Slightly tighter padding */
    border-radius: 12px;
    font-size: 12px;
    /* Reduced font size to fit */
    white-space: nowrap;
    /* Prevent wrapping inside badge */
}

.p-icon {
    font-size: 14px;
    line-height: 1;
}

.p-val {
    font-weight: 600;
    font-family: 'Consolas', monospace;
    color: #ddd;
}

/* Red Cross Icon */
.p-icon-cross {
    width: 20px;
    height: 20px;
    background-color: #ff4444;
    /* Red Square */
    color: white;
    /* White Cross */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-weight: bold;
    font-size: 14px;
    margin-right: 8px;
    line-height: 1;
}

/* Animations */
@keyframes pulse-warning {
    0% {
        box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4);
        border-color: #f39c12;
    }

    50% {
        box-shadow: 0 0 10px 4px rgba(243, 156, 18, 0.2);
        border-color: #f1c40f;
    }

    100% {
        box-shadow: 0 0 0 0 rgba(243, 156, 18, 0);
        border-color: #f39c12;
    }
}

@keyframes pulse-critical {
    0% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6);
        background-color: rgba(231, 76, 60, 0.1);
        border-color: #e74c3c;
    }

    50% {
        box-shadow: 0 0 15px 5px rgba(231, 76, 60, 0.3);
        background-color: rgba(231, 76, 60, 0.25);
        border-color: #ff0000;
        transform: scale(1.02);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
        background-color: rgba(231, 76, 60, 0);
        border-color: #e74c3c;
        transform: scale(1);
    }
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px) rotate(-2deg);
    }

    50% {
        transform: translateX(5px) rotate(2deg);
    }

    75% {
        transform: translateX(-5px) rotate(-2deg);
    }

    100% {
        transform: translateX(0);
    }
}

@keyframes shake-vertical {

    0%,
    100% {
        transform: translateY(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateY(-2px);
        border-color: #e74c3c;
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateY(2px);
        border-color: #e74c3c;
    }
}

.player-card.shake {
    animation: shake-vertical 0.5s ease-in-out;
}

/* Custom Large Tooltip */
#custom-tooltip {
    position: absolute;
    display: none;
    background-color: rgba(30, 30, 30, 0.95);
    color: #ffffff;
    padding: 12px 16px;
    border-radius: 6px;
    border: 1px solid #555;
    font-size: 1.1rem;
    /* Larger font */
    line-height: 1.5;
    z-index: 10000;
    pointer-events: none;
    /* Let mouse pass through */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    white-space: pre-wrap;
    /* Handle newlines */
    max-width: 400px;
}

/* SVG Icon Styles */
.icon-biohazard-img {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-left: 8px;
    margin-right: 4px;
    filter: drop-shadow(0 0 2px rgba(255, 215, 0, 0.7));
}

.p-icon-health-img {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-right: 8px;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
}

/* --- Mobile Responsive --- */
/* Hide Mobile Header by Default on Desktop */
.mobile-header {
    display: none;
    height: 50px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    padding: 0 1rem;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2000;
    /* [FIX] Higher than Leaflet (defaults to 400-1000) */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    margin-right: 1rem;
    /* [FIX] Ensure button is above title and has good touch target */
    z-index: 2002;
    position: relative;
    padding: 10px;
    /* Increase touch area */
    margin: -10px 1rem -10px -10px;
    /* Compensate padding */
}

.mobile-title {
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    /* [NEW] Clickable */
    flex: 1;
    /* Allow title to take space but not cover button */
}

.sidebar-overlay {
    background: rgba(0, 0, 0, 0.5);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1999;
    /* Just below header */
    display: none;
    /* Hidden by default */
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        /* [FIX] Prevent horizontal scroll/sway */
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }

    /* [FIX] コンソール画面: 高さを画面いっぱいに固定せず成り行きにし、縦スクロールを許可 */
    #tab-console {
        overflow-y: auto;
    }

    /* [FIX] システムコンソール/チャットの表示欄が均等割りで潰れないよう最低高さを確保 */
    .log-window {
        min-height: 150px;
    }

    /* Header Visible */
    .mobile-header {
        display: flex;
    }

    /* Sidebar Collapsed */
    /* Sidebar Collapsed */
    .sidebar {
        position: fixed;
        top: 50px;
        /* Below header */
        left: 0;
        height: calc(100% - 50px);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 2001;
        /* [FIX] Higher than Overlay (1999) and Header (2000) */
        width: 260px;
        /* Slightly narrower */
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Main Content Adjustments */
    .content {
        margin-left: 0;
        /* Remove Desktop margin */
        width: 100%;
        /* [FIX] Top 60px for header, others 0.5rem */
        padding: 60px 0.5rem 0.5rem 0.5rem;
        height: 100%;
        overflow-y: auto;
        /* Ensure scrolling */
    }

    /* [NEW] Helper for hiding on Mobile */
    .mobile-hidden {
        display: none !important;
    }

    /* Map Toolbar: Allow wrapping and stacking */
    .map-toolbar {
        height: auto;
        min-height: 40px;
        /* Reduced min-height */
        flex-wrap: wrap;
        padding: 4px;
        /* Reduced padding */
        align-items: center;
        gap: 5px;
        /* Add gap */
    }

    /* [MOD] Details/Summary for Display Settings */
    details.toolbar-group {
        width: 100%;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
        padding: 4px 8px;
        margin-bottom: 5px;
    }

    details.toolbar-group summary {
        font-size: 0.9rem;
        font-weight: bold;
        color: var(--text-primary);
        outline: none;
    }

    /* Override open handling if needed */
    details.toolbar-group[open] {
        background: rgba(0, 0, 0, 0.4);
    }

    .toolbar-group {
        flex-wrap: wrap;
        width: auto;
        margin-bottom: 0;
        /* Handled by gap */
        margin-right: 0;
        /* Handled by gap */
        align-items: center;
    }

    /* [FIX] Compact Stats Layout for Mobile */
    .stats-group {
        display: flex;
        flex-direction: row;
        align-items: center;
        width: 100%;
        justify-content: flex-end;
        /* Push to right or distribute */
        background: transparent;
        /* Remove bg to save visual weight */
        padding: 0;
        gap: 10px;
    }

    .stats-row {
        display: flex;
        align-items: center;
        margin-bottom: 0;
        margin-right: 0;
    }

    /* Compact Time Display */
    #game-time-display {
        font-size: 0.85rem;
        padding: 2px 4px;
        background: rgba(0, 0, 0, 0.3);
        border: 1px solid var(--border-color);
        border-radius: 3px;
    }

    .stat-badge {
        font-size: 0.85rem;
        padding: 2px 5px;
    }

    /* ... rest ... */

    /* Ensure toolbar doesn't shrink */
    .map-toolbar {
        flex-shrink: 0;
    }

    /* Player status board also shouldn't shrink */
    #player-status-board {
        flex-shrink: 0;
    }

    /* [FIX] Scheduler Overflow on Mobile */
    #tab-scheduler input {
        min-width: 0;
        max-width: 90%;
    }

    #tab-scheduler div[style*="display:flex"] {
        max-width: 100%;
    }
}

/* Responsive Table as Cards (Mobile & Tablet) */
@media screen and (max-width: 1100px) {
    #players-table thead {
        display: none;
    }

    #players-table tbody {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 12px;
        padding: 4px;
    }

    /* Wrap single card if only one */
    #players-table tr {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr;
        /* 4 columns grid */
        gap: 6px 12px;
        background-color: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: var(--shadow-soft);
        padding: 10px;
        font-size: 0.9rem;
    }

    #players-table td {
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 0;
        border: none;
        text-align: left;
    }

    /* -- Header Area (Name, ID, Status) -- */
    /* Status Dot */
    #players-table td[data-label="Status"] {
        grid-column: 1 / 2;
        grid-row: 1;
        justify-content: center;
        align-items: flex-start;
        padding-top: 4px;
    }

    /* Name */
    #players-table td[data-label="Name"] {
        grid-column: 2 / 5;
        grid-row: 1;
        font-weight: 700;
        font-size: 1.1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding-bottom: 4px;
        margin-bottom: 4px;
        color: var(--text-highlight);
    }

    /* ID (Place under name or beside?) - Let's put ID small below name or beside status? */
    #players-table td[data-label="ID"] {
        grid-column: 1 / 5;
        grid-row: 2;
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-bottom: 8px;
    }

    #players-table td[data-label="ID"]::before {
        content: "ID: ";
        display: inline;
    }


    /* -- Stats Area (2-4 columns) -- */
    /* Level, GS, Score, Health - Row 3 */
    #players-table td[data-label="Level"],
    #players-table td[data-label="GS"],
    #players-table td[data-label="Health"],
    #players-table td[data-label="Score"] {
        background: rgba(255, 255, 255, 0.03);
        padding: 4px;
        border-radius: 4px;
        align-items: center;
    }

    /* Small Headers for Stats */
    #players-table td::before {
        font-size: 0.65rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        margin-bottom: 2px;
        display: block;
        content: attr(data-label);
    }

    /* Simplify Labels */
    #players-table td[data-label="Level"]::before {
        content: "LVL";
    }

    #players-table td[data-label="Zombie Kills"]::before {
        content: "Z-KILL";
    }

    #players-table td[data-label="Player Kills"]::before {
        content: "P-KILL";
    }

    /* -- Combat/Info Area -- */
    #players-table td[data-label="Deaths"],
    #players-table td[data-label="Zombie Kills"],
    #players-table td[data-label="Player Kills"],
    #players-table td[data-label="Ping"] {
        align-items: center;
    }

    /* Position - Full width bottom */
    #players-table td[data-label="Position"] {
        grid-column: 1 / 4;
        font-size: 0.8rem;
        color: var(--text-muted);
        align-items: flex-start;
        margin-top: 4px;
    }

    #players-table td[data-label="Position"]::before {
        display: inline;
        margin-right: 4px;
    }

    /* -- Actions -- */
    #players-table td[data-label="Action"] {
        grid-column: 4 / 5;
        grid-row: -1;
        /* Bottom right */
        align-items: flex-end;
        justify-content: flex-end;
    }

    #players-table .btn-small {
        padding: 4px 8px;
        font-size: 0.75rem;
        margin: 2px 0;
        width: 100%;
        text-align: center;
    }

    /* HIDING PREVIOUS STYLES or Overriding */
    /* Remove flex layouts from previous iteration if conflict */
}

/* [NEW] Compact Player Status Board for Mobile (Name | Bar | Icon) */
@media screen and (max-width: 768px) {
    #player-status-board {
        flex-direction: column;
        /* Stack multiple players vertically */
        gap: 4px;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
    }

    #player-status-board .player-card {
        display: flex;
        /* Name | HP Bar(Flex) | Food | Water | Infection | Icon */
        align-items: center;
        gap: 6px;
        padding: 6px 8px;
        height: auto;
        min-height: 0;
        width: 100%;
        box-sizing: border-box;
    }

    /* Flatten DOM structure */
    #player-status-board .p-card-header,
    #player-status-board .p-card-stats,
    #player-status-board .p-stat-row,
    #player-status-board .p-sub-stats {
        display: contents;
    }

    /* 1. Name */
    #player-status-board .p-card-name {
        order: 1;
        font-size: 0.85rem;
        margin: 0;
        padding: 0;
        border: none;
        width: 80px;
        /* Fixed Width */
        min-width: 80px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: var(--text-highlight);
    }

    /* 2. HP Bar (Container) */
    #player-status-board .p-bar-container {
        order: 2;
        flex: 1;
        /* Take remaining space */
        min-width: 40px;
        /* Prevent collapse */
        height: 6px;
        margin: 0 2px;
        background: rgba(0, 0, 0, 0.5);
        border: 1px solid #444;
        border-radius: 2px;
    }

    #player-status-board .p-hp-bar {
        height: 100%;
        border-radius: 1px;
    }

    /* 3, 4, 5. Sub Stats (Food, Water, Infection) */
    #player-status-board .p-sub-stat,
    #player-status-board .infection-block {
        display: flex;
        align-items: center;
        font-size: 0.75rem;
        padding: 0;
        background: none !important;
        /* Remove block bg */
        border: none !important;
        margin: 0;
        min-width: 46px;
        /* [FIX] Fixed width for alignment */
        justify-content: flex-end;
        /* Align to right number */
    }

    /* Order: Food(3), Water(4), Infection(5) */
    #player-status-board .p-sub-stat[title="満腹度"] {
        order: 3;
    }

    #player-status-board .p-sub-stat[title="水分"] {
        order: 4;
    }

    #player-status-board .infection-block {
        order: 5;
        /* Ensure Infection stays last on mobile too */
        max-width: 80px;
        /* Limit width on mobile to prevent blowout */
    }

    /* Compact icons and values */
    #player-status-board .p-icon {
        font-size: 0.8rem;
        margin-right: 1px;
    }

    #player-status-board .p-val {
        color: #ccc;
        font-weight: 600;
    }

    /* Adjust SVG icon size for infection/health if used (hidden usually but just in case) */
    #player-status-board .icon-biohazard-img {
        width: 14px;
        height: 14px;
        margin: 0 1px 0 0;
    }

    /* 6. Device Icon & Action Wrapper */
    #player-status-board .p-header-right {
        order: 6;
        display: flex;
        align-items: center;
        margin-left: 2px;
    }

    #player-status-board .p-card-platform {
        order: 0;
        font-size: 1.0rem;
        margin: 0;
    }

    /* Hide Unnecessary Elements */
    #player-status-board .p-icon-health-img,
    /* Health Cross */
    #player-status-board .hp-val

    /* Numerical HP */
        {
        display: none !important;
    }
}

/* [MOD] Mobile Short Text for Toggles */
@media (max-width: 768px) {
    .toggle-btn span[data-mobile] {
        font-size: 0 !important;
        padding: 6px 10px;
    }


    .toggle-btn span[data-mobile]::before {
        content: attr(data-mobile);
        visibility: visible;
        font-size: 0.9rem;
        line-height: 1.5;
    }
}

/* --- Rule Page Styles --- */
.rule-view-container {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.rule-header-row {
    border-bottom: 2px solid var(--accent-color);
    margin-bottom: 20px;
}

#rule-content-view {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
    min-height: 300px;
    line-height: 1.6;
    color: #e0e0e0;
}

/* Minimal Markdown Styles */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    border-bottom: 1px solid #444;
    padding-bottom: 0.3em;
    margin-top: 1.5em;
    color: #fff;
}

.markdown-body h1 {
    font-size: 2em;
}

.markdown-body h2 {
    font-size: 1.5em;
}

.markdown-body p {
    margin-bottom: 1em;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-bottom: 1em;
}

.markdown-body code {
    background: #333;
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
}

.markdown-body pre {
    background: #1e1e1e;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 15px;
    color: #aaa;
    margin: 1em 0;
}

/* Agreement Section */
.agreement-section {
    text-align: center;
    padding: 40px;
    background: var(--bg-panel);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
}

.password-display-box {
    display: inline-flex;
    align-items: center;
    background: #000;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 15px 30px;
    font-size: 1.5rem;
    font-weight: bold;
    font-family: monospace;
    letter-spacing: 2px;
    color: #fff;
    margin-top: 10px;
}

/* --- Recipes Tab Styles --- */
.recipes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    padding: 10px 0;
}

.recipe-card {
    background-color: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s, background-color 0.2s;
}

.recipe-card:hover {
    background-color: #2a2a2a;
    transform: translateY(-2px);
}

.recipe-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    border-bottom: 1px solid #444;
    padding-bottom: 8px;
}

.recipe-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    padding: 2px;
}

.recipe-title-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.recipe-name {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--accent-color);
}

.recipe-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.badge-station {
    font-size: 0.75rem;
    background: #444;
    color: #ddd;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

.badge-mod {
    font-size: 0.75rem;
    background: transparent;
    color: #888;
    border: 1px solid #444;
    padding: 1px 6px;
    border-radius: 4px;
    display: inline-block;
}

.recipe-body {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 8px;
}

.recipe-subtitle {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.ingredients-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ingredients-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ingredients-list li:last-child {
    border-bottom: none;
}

.ing-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.ing-name {
    flex: 1;
    font-size: 0.9rem;
    color: #ddd;
}



/* --- Item Gift Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-overlay.hidden {
    display: none;
}

.gift-modal {
    background: var(--bg-panel);
    width: 600px;
    max-width: 90%;
    max-height: 80vh;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #fff;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.gift-search-section input {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    font-size: 16px;
    margin-bottom: 10px;
}

.gift-results-list {
    height: 250px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #333;
    border-radius: 4px;
}

.gift-item-row {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    transition: background 0.1s;
}

.gift-item-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.gift-item-row.selected {
    background: rgba(46, 213, 115, 0.2);
    border-left: 4px solid var(--success-color);
}

.item-icon-small {
    width: 32px;
    height: 32px;
    background-color: #000;
    border: 1px solid #444;
    margin-right: 10px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.item-info {
    flex: 1;
    overflow: hidden;
}

.item-label {
    font-weight: bold;
    color: #eee;
}

.item-id {
    font-size: 11px;
    color: #aaa;
}

.gift-options-section {
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.selected-item-preview {
    flex: 1;
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #aaa;
}

.input-group {
    display: flex;
    align-items: center;
}

.input-group label {
    margin-right: 5px;
    color: #ccc;
}

.input-group input {
    width: 70px;
    padding: 5px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    border-radius: 3px;
}

.btn-item-gift {
    background-color: #9b59b6;
    color: white;
    padding: 4px 10px;
    border: none;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 5px;
    font-weight: bold;
    height: 24px;
    display: inline-flex;
    align-items: center;
}

.btn-item-gift:hover {
    background-color: #8e44ad;
}
/* Mod Cards */
.mod-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    padding: 10px;
}

.mod-card {
    background: #2b2f33;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.mod-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    border-color: #666;
}

.mod-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #3d444b;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.mod-title {
    margin: 0;
    font-size: 1.1em;
    color: #e6e6e6;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mod-version {
    font-size: 0.85em;
    color: #4caf50;
    background: #1a1d20;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.mod-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mod-desc {
    font-size: 0.9em;
    color: #aaa;
    margin: 0 0 10px 0;
    line-height: 1.4;
    flex: 1;
    max-height: 80px;
    overflow-y: auto;
}

.mod-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: #888;
    margin-top: auto;
}

.mod-author {
    font-style: italic;
}

.mod-link {
    color: #7289da;
    text-decoration: none;
    font-size: 1.2em;
}
.mod-link:hover {
    color: #fff;
}


/* Mod Guide Tab */
.guide-intro {
    color: #aaa;
    font-size: 0.95em;
    margin: 5px 10px 15px 10px;
}

.guide-section {
    color: var(--accent-color);
    border-bottom: 1px solid #444;
    padding: 6px 10px;
    margin: 20px 0 5px 0;
    font-size: 1.15em;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 15px;
    padding: 10px;
}

.guide-card {
    background: #2b2f33;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.guide-card p {
    font-size: 0.9em;
    color: #bbb;
    line-height: 1.55;
    margin: 0 0 8px 0;
}

.guide-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    border-bottom: 1px solid #3d444b;
    padding-bottom: 8px;
    margin-bottom: 10px;
}

.guide-title {
    font-size: 1.05em;
    font-weight: bold;
    color: #e6e6e6;
}

.guide-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    color: #fff;
}

.badge-craft { background: #2e7d32; }
.badge-admin { background: #a33; }
.badge-auto { background: #1565c0; }
.badge-event { background: #8e44ad; }

.guide-how {
    color: #d8c477 !important;
    font-size: 0.85em !important;
    margin-top: auto !important;
    border-top: 1px dashed #444;
    padding-top: 8px;
}
