:root {
    --bg-main: #1a0f0c;
    --bg-card: #2a1812;
    --bg-card-hover: #3a2218;
    --border-gold: #d4af37;
    --border-subtle: #5a3a28;
    --text-primary: #f8edd4;
    --text-secondary: #c4a882;
    --accent-green: #6dbf8a;
    --accent-gold: #f0c75e;
    --accent-red: #c44536;
    --accent-qi: #e07a3d;
    --accent-blue: #4aa3ff;
    --player: #d4b056;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: "Noto Serif SC", serif; user-select: none; }

body {
    background:
        radial-gradient(900px 400px at 0% 0%, rgba(196, 69, 54, 0.18), transparent 50%),
        radial-gradient(800px 400px at 100% 0%, rgba(212, 175, 55, 0.12), transparent 45%),
        var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
}
h1, h2, h3, .brand h1 { font-family: "Ma Shan Zheng", "Cinzel", serif; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

#top-bar {
    background: linear-gradient(180deg, #161d28 0%, #0b1017 100%);
    border-bottom: 2px solid var(--border-gold);
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.crest {
    width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center;
    background: radial-gradient(circle, #f0d27a, #7a5416);
    color: #2a1a04; font-weight: 900; font-family: "Cinzel", serif;
    box-shadow: 0 0 16px rgba(230, 193, 90, 0.4);
}
.brand h1 {
    font-family: "Cinzel", serif;
    font-size: 1.25rem;
    color: var(--accent-gold);
    letter-spacing: 2px;
}
.brand .subtitle { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; }

.resources-container { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; justify-content: center; }
.res-item {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.03);
    padding: 5px 10px; border-radius: 8px;
    border: 1px solid var(--border-subtle);
}
.res-icon { font-size: 1.1rem; }
.res-info { display: flex; flex-direction: column; }
.res-label { font-size: 0.6rem; color: var(--text-secondary); text-transform: uppercase; }
.res-value { font-weight: 700; font-size: 0.9rem; }
.res-rate { font-size: 0.62rem; color: var(--accent-green); }

.header-actions { display: flex; gap: 6px; }
.icon-btn {
    background: var(--bg-card); border: 1px solid var(--border-subtle);
    color: #fff; width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-gold); }

#event-banner {
    background: linear-gradient(90deg, #5a1d12, #2b120c);
    color: white; padding: 8px 18px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--accent-red);
}
#event-banner.hidden { display: none; }
#event-action-btn {
    background: var(--accent-gold); border: none; padding: 6px 14px;
    font-weight: 700; cursor: pointer; border-radius: 4px;
}

#main-content { display: flex; flex: 1; padding: 16px; gap: 16px; }
#left-panel { width: 280px; display: flex; flex-direction: column; gap: 14px; }
#right-panel { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
    background: linear-gradient(180deg, #161d28, #10151d);
    border: 1px solid var(--border-subtle);
    border-radius: 10px; padding: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.28);
}
.card h2, .card h3 {
    font-family: "Cinzel", serif; color: var(--accent-gold);
    margin-bottom: 10px; font-size: 1rem;
    border-bottom: 1px solid var(--border-subtle); padding-bottom: 6px;
}

.clicker-card { text-align: center; }
.sphere-container { margin: 16px 0; display: flex; justify-content: center; position: relative; }
.cultivation-sphere {
    width: 132px; height: 132px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #e2b8ff, #7b2fd4 42%, #22063a 80%);
    border: 3px solid var(--border-gold);
    box-shadow: 0 0 28px rgba(176, 124, 255, 0.45);
    cursor: pointer; position: relative; outline: none;
    transition: transform 0.12s;
}
.cultivation-sphere:active { transform: scale(0.93); }
.sphere-rings {
    position: absolute; inset: -10px; border-radius: 50%;
    border: 2px dashed rgba(230,193,90,0.35);
    animation: spin 12s linear infinite;
}
.sphere-text {
    color: #fff; font-family: "Cinzel", serif; font-weight: 700;
    letter-spacing: 1px; text-shadow: 0 2px 6px #000;
    position: relative; z-index: 1;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stat-group { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 0.84rem; }
.stat-group.column { flex-direction: column; gap: 4px; }
.threat-bar-bg, .relation-bar-bg {
    width: 100%; height: 9px; background: #222; border-radius: 6px; overflow: hidden;
}
#threat-bar-fill { height: 100%; background: linear-gradient(90deg, #e6c15a, #e05a5a); }
#relation-bar-fill { height: 100%; width: 50%; background: linear-gradient(90deg, #e05a5a, #e6c15a, #3dcf8a); }

.mini-legend ul { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 0.75rem; color: var(--text-secondary); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.hostile { background: #e05a5a; }
.dot.peace { background: #4aa3ff; }
.dot.trade { background: #e6c15a; }
.dot.ally { background: #3dcf8a; }
.dot.vassal { background: #b07cff; }
.dot.player { background: #d4b056; }

.tab-navigation { display: flex; flex-wrap: wrap; gap: 6px; }
.tab-btn {
    background: var(--bg-card); border: 1px solid var(--border-subtle);
    color: var(--text-secondary); padding: 8px 12px; border-radius: 8px;
    cursor: pointer; font-size: 0.82rem; font-weight: 600;
}
.tab-btn:hover { color: #fff; }
.tab-btn.active { background: var(--border-gold); color: #1a1204; border-color: var(--border-gold); }
.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; gap: 12px; }
.section-header h2 { font-family: "Cinzel", serif; color: var(--accent-gold); font-size: 1.15rem; }
.section-header p { color: var(--text-secondary); font-size: 0.85rem; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.8fr); gap: 12px; }
.map-stage { padding: 10px; }
#world-map { width: 100%; height: auto; border-radius: 10px; background: #0b1a28; }
.land { stroke: #f3ead2; stroke-width: 1.8; cursor: pointer; transition: filter 0.2s, stroke 0.2s; stroke-linejoin: round; }
.land:hover, .land.selected { filter: brightness(1.2); stroke: #fff; stroke-width: 2.6; }
.player-land { fill: url(#playerFill); cursor: default; stroke: #fff3c4; stroke-width: 2.2; }
.island-land { filter: url(#soft); }
.land-label { fill: #f7f1de; font-size: 13px; font-family: "Cinzel", serif; pointer-events: none; text-shadow: 0 1px 2px #000; }
.player-capital { fill: #fff3c4; stroke: #7a5416; }
.map-hint { text-align: center; color: var(--text-secondary); font-size: 0.75rem; margin-top: 6px; }

.land[data-status="hostile"] { fill: #7a2d2d; }
.land[data-status="peace"] { fill: #2a4d73; }
.land[data-status="trade"] { fill: #7a6320; }
.land[data-status="ally"] { fill: #1f6a48; }
.land[data-status="vassal"] { fill: #5a3878; }

#diplo-empty { text-align: center; color: var(--text-secondary); padding: 24px 8px; }
.empty-crest { font-size: 2rem; margin-bottom: 8px; }
.diplo-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.diplo-flag { font-size: 1.8rem; }
.diplo-desc { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 10px; }
.diplo-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.diplo-stats div { background: rgba(255,255,255,0.03); padding: 6px; border-radius: 6px; text-align: center; }
.diplo-stats span { display: block; font-size: 0.65rem; color: var(--text-secondary); }
.treaty-tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; min-height: 22px; }
.tag { font-size: 0.68rem; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--border-subtle); }
.diplo-actions { display: flex; flex-direction: column; gap: 6px; }
.btn-diplo, .btn-buy, .btn-action, .btn-attack {
    border-radius: 6px; cursor: pointer; font-weight: 700; padding: 8px 10px; font-size: 0.8rem;
}
.btn-diplo {
    background: #1c2734; border: 1px solid var(--border-subtle); color: #fff; text-align: left;
}
.btn-diplo:hover { border-color: var(--border-gold); }
.btn-diplo:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-diplo.good { border-color: #2e6d4f; }
.btn-diplo.warn { border-color: #8a4a1d; }
.btn-diplo.danger { border-color: #8a2d2d; }

.f-status { padding: 2px 8px; border-radius: 4px; font-size: 0.72rem; }
.status-hostile { background: rgba(224,90,90,0.2); color: #ff8a8a; }
.status-peace { background: rgba(74,163,255,0.2); color: #8ec7ff; }
.status-trade { background: rgba(230,193,90,0.2); color: #f0d27a; }
.status-ally { background: rgba(61,207,138,0.2); color: #7eecc0; }
.status-vassal { background: rgba(176,124,255,0.2); color: #d2b4ff; }

.policy-controls { display: flex; gap: 24px; }
.policy-item { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.policy-desc { font-size: 0.75rem; color: var(--text-secondary); }
input[type="range"] { width: 100%; accent-color: var(--border-gold); }

.buildings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.building-card { display: flex; align-items: center; gap: 10px; }
.b-icon { font-size: 1.8rem; background: rgba(255,255,255,0.05); padding: 8px; border-radius: 8px; }
.b-info { flex: 1; }
.b-info h4 { color: var(--accent-gold); font-size: 0.92rem; }
.b-desc, .b-cost { font-size: 0.74rem; color: var(--text-secondary); }
.b-effect { font-size: 0.74rem; color: var(--accent-green); font-weight: 700; }
.btn-buy {
    background: linear-gradient(180deg, #c9a24a, #7a5a20);
    border: 1px solid var(--border-gold); color: #fff;
}
.military-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.forge-action { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btn-action { background: #1c2734; border: 1px solid var(--border-gold); color: var(--accent-gold); }
.unit-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); }
.unit-details h4 { font-size: 0.9rem; }
.unit-details p { font-size: 0.74rem; color: var(--text-secondary); }

.talents-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.talent-card { cursor: pointer; text-align: left; color: inherit; }
.talent-card:hover { border-color: var(--border-gold); transform: translateY(-2px); }
.t-cost { color: var(--accent-qi); font-size: 0.8rem; font-weight: 700; }
.t-level { font-size: 0.74rem; color: var(--text-secondary); }

.chronicle { list-style: none; max-height: 420px; overflow: auto; }
.chronicle li { padding: 8px 0; border-bottom: 1px solid var(--border-subtle); font-size: 0.84rem; color: var(--text-secondary); }
.chronicle li strong { color: var(--accent-gold); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast {
    background: #1a2230; border: 1px solid var(--border-gold); color: #fff;
    padding: 10px 14px; border-radius: 8px; min-width: 240px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.35); animation: pop 0.2s ease;
}
.toast.bad { border-color: var(--accent-red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.hidden { display: none !important; }

.map-header-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.season-chip {
    background: rgba(230,193,90,0.12); border: 1px solid var(--border-gold);
    color: var(--accent-gold); padding: 6px 12px; border-radius: 99px; font-size: 0.8rem;
}
.map-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.map-tool {
    background: #1c2734; border: 1px solid var(--border-subtle); color: #dbe4ee;
    padding: 6px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.78rem;
}
.map-tool.active, .map-tool:hover { border-color: var(--border-gold); color: var(--accent-gold); }
.tool-sep { width: 1px; height: 18px; background: var(--border-subtle); margin: 0 4px; }
#map-viewport { overflow: hidden; border-radius: 10px; cursor: grab; position: relative; background: #0b1a28; }
#map-viewport.dragging { cursor: grabbing; }
#world-map { width: 100%; height: auto; transform-origin: 0 0; }
.river { fill: none; stroke: #7ec8e8; stroke-width: 2.2; opacity: 0.55; stroke-linecap: round; }
.mountain { fill: #cfd6de; opacity: 0.55; }
.tree { fill: #2f7a4a; opacity: 0.7; }
.dune { fill: #c4a36a; opacity: 0.35; }
.cap-pulse { fill: rgba(255, 236, 170, 0.18); animation: pulseCap 2.4s ease-out infinite; }
.cap-core { fill: #fff3c4; stroke: #7a5416; stroke-width: 1.5; }
@keyframes pulseCap { 0% { opacity: 0.55; } 100% { opacity: 0; } }
.trade-route { fill: none; stroke: #e6c15a; stroke-width: 2; stroke-dasharray: 8 8; opacity: 0.85; animation: dash 1.2s linear infinite; }
.ally-route { stroke: #3dcf8a; }
.peace-route { stroke: #4aa3ff; }
.vassal-route { stroke: #b07cff; }
@keyframes dash { to { stroke-dashoffset: -32; } }
.cloud.c1 { animation: drift 22s linear infinite; }
.cloud.c2 { animation: drift 28s linear infinite reverse; }
.cloud.c3 { animation: drift 26s linear infinite; }
@keyframes drift { 0% { transform: translateX(0); } 50% { transform: translateX(24px); } 100% { transform: translateX(0); } }
.campaign-flash { fill: none; stroke: #ffd36a; stroke-width: 3; stroke-dasharray: 6 6; animation: dash 0.35s linear infinite; }
#map-tooltip {
    position: absolute; pointer-events: none;
    background: rgba(12,16,24,0.92); border: 1px solid var(--border-gold);
    color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 0.75rem;
    min-width: 140px; z-index: 5;
}
#map-tooltip strong { color: var(--accent-gold); display: block; margin-bottom: 2px; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: grid; place-items: center; z-index: 30; }
#modal.hidden { display: none !important; }
.modal-card { width: min(420px, 92vw); background: #161d28; border: 1px solid var(--border-gold); border-radius: 12px; padding: 18px; }
.modal-card h3 { font-family: "Cinzel", serif; color: var(--accent-gold); margin-bottom: 8px; }
.modal-card p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 12px; }
#modal-actions { display: flex; flex-direction: column; gap: 6px; }
.map-stage.season-winter .land { filter: saturate(0.7) brightness(1.08); }
.map-stage.season-autumn .land { filter: sepia(0.22) saturate(1.08); }
.map-stage.season-summer .land { filter: saturate(1.18) brightness(1.06); }

.fx-burst { animation: burstUp 0.7s ease-out forwards; fill: #fff3c4; }
@keyframes burstUp {
    from { opacity: 1; transform: translateY(0) scale(0.8); }
    to { opacity: 0; transform: translateY(-18px) scale(1.3); }
}
.land.under-fire { filter: brightness(1.35) saturate(1.3); stroke: #ffd36a; stroke-width: 3.2; }
.quest-card ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.quest-card li { font-size: 0.78rem; color: var(--text-secondary); }
.quest-card li.done { color: var(--accent-green); }
.combo-row { font-size: 0.8rem; margin-bottom: 6px; }
.glory-bg { height: 8px; background: #222; border-radius: 6px; overflow: hidden; margin-bottom: 4px; }
#glory-fill { height: 100%; width: 10%; background: linear-gradient(90deg, #c9a24a, #fff3c4); transition: width 0.3s; }
.glory-label { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 8px; }

#court-menu {
    position: absolute; z-index: 8; width: 270px; max-height: 70%;
    overflow: auto; padding: 12px;
    background: linear-gradient(180deg, #3b1f14, #24140f);
    border: 2px solid #d4af37; border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.45);
}
.court-close {
    position: absolute; right: 6px; top: 4px; background: none; border: 0;
    color: #f0c75e; font-size: 1.2rem; cursor: pointer;
}
.big-legend { list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 0.9rem; }
.legend-tip { margin-top: 10px; color: var(--text-secondary); font-size: 0.75rem; }
.ink-note p { font-size: 0.8rem; color: var(--text-secondary); }
.life.sway { animation: sway 3.6s ease-in-out infinite; transform-origin: center; }
.life.walk { animation: stroll 5s ease-in-out infinite; }
.life.lantern { animation: glow 2s ease-in-out infinite; }
.life.delay { animation-delay: 1.2s; }
@keyframes sway { 50% { transform: rotate(6deg); } }
@keyframes stroll { 50% { transform: translateX(6px); } }
@keyframes glow { 50% { opacity: 0.55; } }
#settings-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: grid; place-items: center; z-index: 40; }
#settings-modal.hidden { display: none !important; }
.settings-card { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 980px) {
    #main-content { flex-direction: column; }
    #left-panel { width: 100%; }
    .map-layout, .buildings-grid, .military-grid, .talents-grid { grid-template-columns: 1fr; }
}

#compass {
    position: absolute; left: 10px; bottom: 10px; z-index: 7;
    width: 84px; height: 84px; display: grid;
    grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr;
    gap: 2px; background: rgba(40,20,12,.82); border: 1px solid #d4af37; border-radius: 50%;
    padding: 10px; place-items: center;
}
#compass button {
    width: 20px; height: 20px; border: 0; border-radius: 50%;
    background: #5a3a18; color: #f0d27a; font-size: 10px; font-weight: 700; cursor: pointer;
}
#compass button[data-dir="n"] { grid-column: 2; grid-row: 1; }
#compass button[data-dir="w"] { grid-column: 1; grid-row: 2; }
#compass button[data-dir="c"] { grid-column: 2; grid-row: 2; background: #d4af37; color: #2a1408; }
#compass button[data-dir="e"] { grid-column: 3; grid-row: 2; }
#compass button[data-dir="s"] { grid-column: 2; grid-row: 3; }
