body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 1rem;
    box-sizing: border-box;
}

#setup-screen, #game-screen {
    background-color: #2d2d2d;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    max-width: 960px;
    width: 95%;
}

h1, h2, h3 { color: #f39c12; }

input, select {
    background-color: #3d3d3d;
    border: 1px solid #555;
    color: white;
    padding: 8px;
    margin: 5px 0;
    border-radius: 4px;
    width: calc(100% - 20px);
}

button {
    background-color: #d35400;
    color: white;
    border: none;
    padding: 10px 15px;
    margin: 5px 0;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
    width: 100%;
}
button:hover    { background-color: #e67e22; }
button:disabled { background-color: #7f8c8d; cursor: not-allowed; }

.btn-lore {
    background-color: #2c3e50;
    color: #f39c12;
    border: 1px solid #444;
    width: auto;
    padding: 6px 14px;
    font-size: 0.85rem;
}
.btn-lore:hover { background-color: #34495e; }

.lobby-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
@media (max-width: 600px) { .lobby-grid { grid-template-columns: 1fr; } }

.lobby-section {
    background-color: #333;
    padding: 15px;
    border-radius: 6px;
}

.open-game {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #444;
    padding: 10px;
    margin-top: 10px;
    border-radius: 4px;
}
.open-game button { width: auto; margin: 0; padding: 5px 10px; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #444; }
th { color: #f39c12; }

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #444;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.invite-panel {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: #333;
    padding: 10px;
    border-radius: 6px;
}
.invite-panel input  { margin: 0; }
.invite-panel button { width: auto; margin: 0; }

/* ── Faction selector ──────────────────────────────────────────────── */
.faction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    margin: 10px 0;
}
.faction-option {
    background: #3a3a3a;
    border: 2px solid #555;
    border-radius: 6px;
    padding: 10px 8px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    font-size: 0.82rem;
}
.faction-option:hover           { border-color: #f39c12; background: #444; }
.faction-option.selected        { border-color: #f39c12; background: #3d2b00; }
.faction-option .fo-icon        { font-size: 1.4rem; display: block; margin-bottom: 3px; }
.faction-option .fo-name        { color: #f39c12; font-weight: bold; display: block; }
.faction-option .fo-style       { color: #999; font-size: 0.75rem; }

/* ── Stats grid ────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}
.stat-card {
    background-color: #3d3d3d;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #f39c12;
}
.stat-card h3 {
    margin-top: 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    color: #bdc3c7;
}
.stat-card p { font-size: 1.5rem; font-weight: bold; margin: 5px 0; }

.village-state {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-left: 8px;
    vertical-align: middle;
}
.vs-thriving  { background: #1a3a1a; color: #2ecc71; }
.vs-struggling{ background: #3a3a1a; color: #f39c12; }
.vs-broken    { background: #3a1a1a; color: #e74c3c; }

/* ── Actions / panels ──────────────────────────────────────────────── */
.actions-panel, .market-panel, .logs-panel, .blot-panel {
    background-color: #333;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
}
.action-group { margin-bottom: 10px; }
.action-group button { width: auto; margin: 5px; }
.action-group input  { width: auto; display: inline-block; }

#logs-content {
    height: 150px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.9rem;
    background-color: #222;
    padding: 10px;
    border-radius: 4px;
}
.log-entry { margin-bottom: 5px; border-bottom: 1px solid #333; }

.market-offer {
    display: flex;
    justify-content: space-between;
    background-color: #444;
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 4px;
}
.market-offer button { width: auto; margin: 0; padding: 5px 10px; }
.market-post { display: flex; gap: 10px; margin-top: 10px; }
.market-post input  { margin: 0; }
.market-post button { width: auto; margin: 0; }

/* ── Blót panel ────────────────────────────────────────────────────── */
.blot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 10px;
}
.blot-btn {
    background: #2c2c2c;
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 8px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    text-align: center;
    transition: border-color 0.2s;
    width: 100%;
    margin: 0;
}
.blot-btn:hover    { border-color: #f39c12; background: #3a3a2a; }
.blot-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.blot-btn .bg-icon { font-size: 1.2rem; display: block; }
.blot-btn .bg-cost { color: #e67e22; font-size: 0.7rem; margin-top: 2px; }

/* ── Event modal ───────────────────────────────────────────────────── */
#event-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.78);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
#event-modal-overlay.visible { display: flex; }
#event-modal {
    background: #2d2d2d;
    border: 2px solid #f39c12;
    border-radius: 8px;
    padding: 2rem;
    max-width: 480px;
    width: 90%;
    text-align: center;
}
#event-modal-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 4px;
    margin-bottom: 1rem;
    display: none;
}
#event-modal-title {
    color: #f39c12;
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
}
#event-modal-flavor {
    font-style: italic;
    color: #aaa;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}
#event-modal-effect {
    color: #e67e22;
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
}
#event-modal-btn {
    background: #d35400;
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    width: auto;
}
#event-modal-btn:hover { background: #e67e22; }

/* ── AI add panel ──────────────────────────────────────────────────── */
.ai-panel {
    background: #252535;
    border: 1px solid #3a3a5a;
    border-radius: 6px;
    padding: 12px;
    margin-top: 12px;
}
.ai-panel h4 { color: #9b59b6; margin: 0 0 8px; font-size: 0.9rem; }
.ai-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.ai-row select { flex: 1; min-width: 90px; width: auto; margin: 0; }
.ai-row button { width: auto; margin: 0; padding: 8px 14px; }

/* ── Opponents strip ───────────────────────────────────────────────── */
.opponents-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.opp-card {
    background: #3a3a3a;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 0.82rem;
}
.opp-card .opp-name  { font-weight: bold; }
.opp-card .opp-state { font-size: 0.72rem; color: #999; margin-top: 2px; }
