/* リセットと基本フォント設定 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #0b0f14;
    font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
    color: #e0d8c3;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#pixi-mount {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ========================================================
   中世ファンタジー風 UI デザイン（共通スタイル）
   ======================================================== */
.fantasy-panel, #top-hud, #mandate-bar, #event-log-container, #citizen-card, #building-card, #bottom-toolbar, .modal-box {
    background: linear-gradient(135deg, rgba(32, 24, 18, 0.94) 0%, rgba(18, 14, 10, 0.96) 100%);
    border: 2px solid #8d6f46;
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.7), inset 0 0 10px rgba(141, 111, 70, 0.2);
    backdrop-filter: blur(4px);
    z-index: 10;
}

/* ========================================================
   最上部 HUD (日時・資源・速度・スタンピード警戒度)
   ======================================================== */
#top-hud {
    position: absolute;
    top: 8px;
    left: 10px;
    right: 10px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    font-size: 12px;
    flex-wrap: nowrap; /* 改行・折り返しを完全に禁止 */
    white-space: nowrap;
    overflow-x: auto; /* 狭い画面でも縦崩れせず横スクロール可能 */
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 8px;
}
#top-hud::-webkit-scrollbar {
    display: none;
}

.hud-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
    flex-shrink: 0;
}

.town-badge {
    background: #5d4037;
    color: #ffe082;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 11px;
    border: 1px solid #ffb300;
}

.season-badge {
    background: #3b5323;
    color: #e8f5e9;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 11px;
    border: 1px solid #66bb6a;
}

.date-text, .time-text {
    font-weight: bold;
    color: #f7e7ce;
}

.weather-badge {
    color: #ffd54f;
    font-weight: bold;
}

#resources-display {
    gap: 8px;
}

.res-item {
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: bold;
    color: #f0f0f0;
    font-size: 12px;
}

.res-item .icon {
    font-size: 13px;
}

/* スタンピード警戒度バー */
.miasma-container {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(40, 10, 40, 0.6);
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid #8e44ad;
}

.miasma-bar-bg {
    width: 48px;
    height: 7px;
    background: #2c0b38;
    border-radius: 4px;
    overflow: hidden;
}

#miasma-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #9b59b6, #e74c3c);
    transition: width 0.3s ease;
}

#speed-controls {
    gap: 4px;
}

.speed-btn {
    background: #2a2018;
    border: 1px solid #705333;
    color: #dfcfb9;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.15s ease;
}

.speed-btn:hover {
    background: #473627;
    color: #fff;
    border-color: #d4af37;
}

.speed-btn.active {
    background: #8d6f46;
    color: #fff;
    border-color: #ffd700;
}

.alarm-btn {
    background: #c0392b;
    border: 1px solid #e74c3c;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: background 0.2s, box-shadow 0.2s;
}

.alarm-btn.active {
    background: #e74c3c;
    box-shadow: 0 0 10px #ff0000;
    animation: pulseAlarm 1.5s infinite;
}

.quest-btn {
    background: #2c3e50;
    border: 1px solid #3498db;
    color: #ecf0f1;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
}

@keyframes pulseAlarm {
    0% { transform: scale(1); }
    50% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* ========================================================
   大号令バー (画面中央上部)
   ======================================================== */
#mandate-bar {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 14px;
    font-size: 12px;
    flex-wrap: nowrap; /* 改行を禁止 */
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#mandate-bar::-webkit-scrollbar {
    display: none;
}

.mandate-title {
    font-weight: bold;
    color: #ffd700;
    white-space: nowrap;
    font-size: 12px;
}

.mandate-buttons {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.mandate-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #2b2219;
    border: 1px solid #6b5033;
    color: #d6c5ad;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 11px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mandate-btn:hover {
    background: #473627;
    color: #fff;
    border-color: #d4af37;
}

.mandate-btn.active {
    background: linear-gradient(180deg, #8d6f46 0%, #684f2e 100%);
    border-color: #ffd700;
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.mandate-divider {
    width: 1px;
    height: 20px;
    background: #8d6f46;
    margin: 0 4px;
    flex-shrink: 0;
}

.mandate-reward-section {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.reward-label {
    font-weight: bold;
    color: #e0d8c3;
    font-size: 11px;
    white-space: nowrap;
}

.reward-buttons {
    display: flex;
    gap: 4px;
}

.reward-btn {
    background: #201a14;
    border: 1px solid #5a4228;
    color: #c4b5a0;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.reward-btn:hover {
    background: #3b2d1d;
    color: #fff;
    border-color: #d4af37;
}

.reward-btn.active {
    background: linear-gradient(180deg, #3d6a45 0%, #264a2c 100%);
    border-color: #52e378;
    color: #fff;
    box-shadow: 0 0 8px rgba(82, 227, 120, 0.4);
}

.reward-btn[data-reward="cc"].active {
    background: linear-gradient(180deg, #8d6f46 0%, #684f2e 100%);
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.reward-btn[data-reward="none"].active {
    background: linear-gradient(180deg, #445566 0%, #2b3844 100%);
    border-color: #88bbdd;
    box-shadow: 0 0 8px rgba(136, 187, 221, 0.4);
}

/* ========================================================
   左下: イベントクロニクル
   ======================================================== */
#event-log-container {
    position: absolute;
    bottom: 74px;
    left: 14px;
    width: 320px;
    max-height: 180px;
    display: flex;
    flex-direction: column;
    padding: 8px;
}

.log-header {
    font-size: 12px;
    font-weight: bold;
    color: #ffd700;
    border-bottom: 1px solid #5a452d;
    padding-bottom: 4px;
    margin-bottom: 6px;
}

#event-log-list {
    overflow-y: auto;
    font-size: 11px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.log-item {
    line-height: 1.4;
    color: #e3d5be;
}

/* ========================================================
   右下: 住民詳細カード & 建物詳細カード
   ======================================================== */
#citizen-card, #building-card {
    position: absolute;
    bottom: 74px;
    right: 14px;
    width: 320px;
    padding: 12px;
    transition: all 0.3s ease;
}

#citizen-card.hidden, #building-card.hidden {
    display: none;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #5a452d;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

#card-citizen-avatar, #card-building-avatar {
    font-size: 28px;
}

.card-title-group h3 {
    font-size: 15px;
    color: #ffd700;
}

#card-citizen-role, #card-building-category {
    font-size: 12px;
    color: #bfa98e;
}

#card-close-btn, #card-building-close-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: #a8947b;
    font-size: 20px;
    cursor: pointer;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
}

.card-stat-row {
    display: flex;
    justify-content: space-between;
}

.stat-label {
    color: #a8947b;
}

.stat-val.highlight {
    color: #ffd700;
    font-weight: bold;
}

/* 6大ステータスグリッド */
.card-attributes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px;
    border-radius: 4px;
    margin: 4px 0;
}

.attr-box {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
}

/* ========================================================
   最下部: ツールバー
   ======================================================== */
#bottom-toolbar {
    position: absolute;
    bottom: 10px;
    left: 12px;
    right: 12px;
    min-height: 54px;
    display: flex;
    align-items: center;
    padding: 4px 12px;
    gap: 8px;
    overflow-x: auto;
}

.tool-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.tool-divider {
    width: 2px;
    height: 32px;
    background: #5a452d;
    margin: 0 4px;
    flex-shrink: 0;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #2b2219;
    border: 1px solid #705333;
    color: #ded0bc;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.tool-btn:hover {
    background: #473627;
    border-color: #ffd700;
    color: #fff;
}

.tool-btn.active {
    background: #8d6f46;
    border-color: #ffd700;
    color: #fff;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

/* ========================================================
   モーダル共通スタイル
   ======================================================== */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    width: 440px;
    max-width: 90vw;
    padding: 24px;
    text-align: center;
}

.modal-box h2 {
    color: #ffd700;
    margin-bottom: 12px;
}

.input-form-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin: 14px 0;
}

.input-form-group label {
    font-size: 13px;
    color: #ffd700;
}

.input-form-group input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #8d6f46;
    background: #18120d;
    color: #fff;
    font-size: 14px;
}

.input-with-dice {
    display: flex;
    width: 100%;
    gap: 6px;
}

.dice-btn {
    background: #473627;
    border: 1px solid #ffd700;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

.modal-actions {
    margin-top: 20px;
}

.action-btn {
    background: linear-gradient(180deg, #8d6f46 0%, #684f2e 100%);
    border: 1px solid #ffd700;
    color: #fff;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

.action-btn:hover {
    background: #a38255;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
}

.quest-list {
    text-align: left;
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 250px;
    overflow-y: auto;
}

.quest-item {
    background: rgba(0, 0, 0, 0.35);
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 3px solid #ffd700;
    font-size: 12px;
}

#help-hint {
    position: absolute;
    top: 66px;
    right: 14px;
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    color: #bfa98e;
    pointer-events: none;
    z-index: 5;
}

/* セーブ・ロードスロットUI */
.save-load-box {
    width: 600px;
    max-width: 94vw;
}

.save-slots-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 4px;
    margin-bottom: 12px;
}

.save-slot-card {
    background: rgba(26, 19, 13, 0.88);
    border: 1px solid #8d6f46;
    border-radius: 6px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: border-color 0.2s, background 0.2s;
}

.save-slot-card:hover {
    border-color: #ffd700;
}

.save-slot-card.auto-slot {
    background: rgba(18, 28, 42, 0.88);
    border-color: #4a76a8;
}

.save-slot-card.auto-slot:hover {
    border-color: #72a7ea;
}

.save-slot-card.empty-slot {
    border-style: dashed;
    border-color: #554433;
    background: rgba(18, 14, 11, 0.5);
}

.slot-main {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.slot-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slot-name {
    font-size: 14px;
    font-weight: bold;
    color: #ffd700;
}

.save-slot-card.auto-slot .slot-name {
    color: #8ac0ff;
}

.slot-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: bold;
    background: #3d2d1c;
    color: #e5c99e;
    border: 1px solid #785a35;
}

.save-slot-card.auto-slot .slot-tag {
    background: #1b3353;
    color: #a0ccff;
    border-color: #3b6699;
}

.slot-meta {
    font-size: 12px;
    color: #d8c8b4;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.slot-meta span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.slot-timestamp {
    font-size: 11px;
    color: #928475;
}

.slot-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-slot {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid;
    transition: all 0.15s;
}

.btn-slot-load {
    background: linear-gradient(180deg, #2b6c3e 0%, #1a4426 100%);
    border-color: #4bd876;
    color: #fff;
}
.btn-slot-load:hover {
    background: #35854d;
    box-shadow: 0 0 8px rgba(75, 216, 118, 0.4);
}

.btn-slot-save {
    background: linear-gradient(180deg, #8d6f46 0%, #684f2e 100%);
    border-color: #ffd700;
    color: #fff;
}
.btn-slot-save:hover {
    background: #a38255;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.btn-slot-delete {
    background: rgba(120, 30, 30, 0.4);
    border-color: #843232;
    color: #dca0a0;
    padding: 6px 8px;
}
.btn-slot-delete:hover {
    background: #8e2b2b;
    color: #fff;
}

/* ========================================================
   スマホ縦画面レスポンシブ (max-width: 768px)
   ======================================================== */
@media (max-width: 768px) {
    #top-hud {
        top: 4px;
        left: 4px;
        right: 4px;
        font-size: 11px;
        padding: 4px 6px;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }
    .hud-group {
        justify-content: space-between;
        gap: 4px;
        flex-wrap: wrap;
    }
    #mandate-bar {
        position: absolute;
        top: auto;
        bottom: 52px;
        left: 4px;
        right: 4px;
        width: auto;
        transform: none;
        padding: 4px 6px;
        overflow-x: auto;
        display: flex;
        align-items: center;
        gap: 6px;
        z-index: 10;
        white-space: nowrap;
    }
    .mandate-title {
        display: none;
    }
    .mandate-buttons {
        display: flex;
        gap: 4px;
        flex-shrink: 0;
    }
    .mandate-btn {
        padding: 4px 6px;
        font-size: 10px;
        white-space: nowrap;
    }
    .mandate-divider {
        height: 16px;
        margin: 0 2px;
    }
    .mandate-reward-section {
        display: flex;
        align-items: center;
        gap: 4px;
        flex-shrink: 0;
    }
    .reward-label {
        font-size: 10px;
    }
    .reward-btn {
        padding: 3px 5px;
        font-size: 10px;
        white-space: nowrap;
    }
    #event-log-container {
        display: none; /* スマホ時は画面を広く使うため非表示 */
    }
    #citizen-card, #building-card {
        bottom: 96px;
        left: 6px;
        right: 6px;
        width: auto;
        z-index: 20;
    }
    #bottom-toolbar {
        bottom: 4px;
        left: 4px;
        right: 4px;
        padding: 4px;
        overflow-x: auto;
        justify-content: flex-start;
    }
    .tool-btn {
        padding: 4px 8px;
        font-size: 11px;
        white-space: nowrap;
    }
    #help-hint {
        display: none;
    }
}
