:root {
  --bg: #12100c;
  --panel: #241d14;
  --panel2: #2f261a;
  --border: #6a5230;
  --parchment: #e8d5a8;
  --ink: #2a2115;
  --amber: #e0a84e;
  --amber-dark: #8a5a20;
  --moss: #7a9a4e;
  --blood: #b8543e;
  --bone: #e6dcc2;
  --muted: #a89070;
  --text: #f0e4c8;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "Segoe UI", system-ui, sans-serif; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; }
#game { display: block; width: 100%; height: 100%; background: var(--bg); cursor: default; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; background: rgba(10,8,6,0.55); backdrop-filter: blur(2px); }
.screen.hidden { display: none; }

.loading-box { text-align: center; color: var(--parchment); }
.loading-box h1 { font-family: Georgia, serif; letter-spacing: .12em; color: var(--amber); text-shadow: 0 3px 0 #3a2008; }
.bar { width: 260px; height: 6px; background: #2a1a0a; border: 1px solid var(--border); border-radius: 3px; margin: 12px auto; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: var(--amber); transition: width .2s; }

.menu-panel, .missions-panel, .briefing-panel, .help-panel, .overlay-panel {
  background: linear-gradient(180deg, #2a2014 0%, #1a140a 100%);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 92vw;
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,220,150,0.15);
  color: var(--parchment);
}
.menu-panel { text-align: center; min-width: 360px; }
.menu-panel h1 { font-family: Georgia, serif; font-size: 46px; margin: 0 0 8px; color: var(--amber); text-shadow: 0 4px 0 #3a2008; letter-spacing: .08em; line-height: 1.05; }
.subtitle { color: var(--muted); margin-bottom: 22px; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.footer { margin-top: 18px; font-size: 12px; color: var(--muted); }

.btn { background: linear-gradient(180deg, #6a5230, #3a2a14); color: var(--parchment); border: 1px solid var(--border); border-radius: 8px; padding: 10px 22px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 #1a1008; transition: transform .05s, filter .1s; font-size: 14px; letter-spacing: .06em; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a1008; }
.btn.primary { background: linear-gradient(180deg, #b88030, #7a4a18); color: #fff4d8; }
.btn.small { padding: 6px 12px; font-size: 12px; }

.icon-btn { background: linear-gradient(180deg, #5a4228, #2a1a0a); color: var(--parchment); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 14px; }
.icon-btn:hover { filter: brightness(1.2); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud.hidden { display: none; }
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 52px; background: linear-gradient(180deg, rgba(20,16,10,0.92), rgba(20,16,10,0.7)); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 14px; pointer-events: auto; gap: 12px; }
.res-group { display: flex; gap: 14px; }
.res-chip { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.res-chip i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,0.4); }
.icon-food { background: #d97a5a; }
.icon-wood { background: #b9854e; }
.icon-stone { background: #aeb6c2; }
.icon-bone { background: #e6dcc2; }
.top-mid { display: flex; gap: 16px; align-items: center; color: var(--amber); font-weight: 700; font-size: 13px; }
#clock { color: var(--muted); }
.top-right { display: flex; gap: 6px; align-items: center; }
#pop-text { color: var(--parchment); font-size: 12px; margin-right: 6px; }

#mission-panel { position: absolute; top: 60px; left: 12px; width: 270px; background: rgba(20,16,10,0.85); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; pointer-events: auto; }
#mission-panel.hidden { display: none; }
.panel-title { font-size: 11px; letter-spacing: .12em; color: var(--amber); margin-bottom: 6px; font-weight: 700; }
#objective-list .obj { font-size: 12px; margin: 4px 0; display: flex; align-items: center; gap: 6px; }
#objective-list .obj .bar { width: 60px; height: 4px; margin: 0; }
#objective-list .obj.done { color: #9fd090; text-decoration: line-through; }

#notices { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 12; }
.notice { background: rgba(20,16,10,0.85); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 13px; color: var(--parchment); box-shadow: 0 4px 12px rgba(0,0,0,0.4); animation: fadeIn .2s; }
.notice.alert { border-color: var(--blood); color: #f0b0a0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

#bottombar { position: absolute; bottom: 0; left: 0; right: 0; height: 178px; background: linear-gradient(180deg, rgba(20,16,10,0.7), rgba(20,16,10,0.92)); border-top: 1px solid var(--border); display: flex; gap: 8px; padding: 8px 10px; pointer-events: auto; }
.panel { background: rgba(20,16,10,0.55); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
#selection-panel { flex: 0 0 320px; overflow: auto; }
#build-panel { flex: 1 1 auto; overflow: hidden; display: flex; flex-direction: column; }
#minimap-panel { flex: 0 0 196px; display: flex; flex-direction: column; align-items: center; }
#minimap { border: 1px solid var(--border); border-radius: 4px; cursor: pointer; image-rendering: pixelated; width: 180px; height: 180px; }

.panel-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
#build-quick, #build-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.build-card { background: linear-gradient(180deg, #3a2e1a, #241a0e); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; cursor: pointer; min-width: 92px; font-size: 11px; transition: transform .05s, border-color .1s; position: relative; }
.build-card:hover { border-color: var(--amber); transform: translateY(-1px); }
.build-card.disabled { opacity: 0.45; cursor: not-allowed; }
.build-card .name { font-weight: 700; color: var(--parchment); }
.build-card .cost { color: var(--muted); font-size: 10px; }
.build-card .key { position: absolute; top: 4px; right: 6px; color: var(--amber); font-size: 10px; font-weight: 700; }

#selection-content { font-size: 12px; }
.sel-title { font-weight: 700; color: var(--amber); margin-bottom: 4px; }
.sel-row { margin: 2px 0; color: var(--parchment); }
.sel-bar { height: 6px; background: #2a1a0a; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; margin: 4px 0; }
.sel-bar i { display: block; height: 100%; background: var(--moss); }
.train-btn { background: linear-gradient(180deg, #7a5a30, #3a2a14); color: var(--parchment); border: 1px solid var(--border); border-radius: 5px; padding: 5px 10px; cursor: pointer; font-size: 11px; margin: 3px 4px 3px 0; }
.train-btn:hover { filter: brightness(1.2); }
.train-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#tooltip { position: fixed; z-index: 30; background: rgba(20,16,10,0.95); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 12px; color: var(--parchment); max-width: 260px; pointer-events: none; }
#tooltip.hidden { display: none; }

.missions-panel, .briefing-panel { min-width: 420px; }
.mission-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 16px 0; max-height: 55vh; overflow: auto; }
.mission-card { background: rgba(30,22,14,0.8); border: 1px solid var(--border); border-radius: 8px; padding: 12px; cursor: pointer; transition: border-color .1s, transform .05s; }
.mission-card:hover { border-color: var(--amber); transform: translateY(-2px); }
.mission-card.completed { border-color: var(--moss); }
.mission-card .mc-title { font-weight: 700; color: var(--amber); margin-bottom: 4px; }
.mission-card .mc-sub { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.mission-card .mc-obj { font-size: 11px; color: var(--parchment); }
.mission-card .mc-diff { font-size: 11px; color: var(--muted); margin-top: 6px; }

.briefing-panel h2 { color: var(--amber); font-family: Georgia, serif; }
.briefing-panel h3 { color: var(--amber); font-size: 14px; margin: 10px 0 4px; }
.briefing-panel p { line-height: 1.5; }
.briefing-panel ul { margin: 4px 0 10px 18px; }
.briefing-buttons { display: flex; gap: 10px; margin-top: 14px; }

.help-panel { min-width: 520px; max-width: 860px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 12px 0; }
.help-grid h3 { color: var(--amber); margin: 0 0 4px; font-size: 13px; }
.help-grid p { margin: 2px 0; font-size: 12px; color: var(--parchment); }

.overlay-panel { text-align: center; min-width: 320px; }
.overlay-panel h2 { color: var(--amber); font-family: Georgia, serif; font-size: 34px; margin: 0 0 8px; }
.overlay-buttons { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: 14px; }
#gameover-stats { margin-top: 10px; font-size: 13px; color: var(--parchment); }

@media (max-width: 900px) {
  #bottombar { height: 220px; flex-wrap: wrap; }
  #selection-panel { flex: 1 1 100%; max-height: 70px; }
  #build-panel { flex: 1 1 100%; }
  #minimap-panel { display: none; }
  #mission-panel { width: 220px; }
}
