/* Terra Nova Protocol - HUD. Ein Layout fuer Desktop und Mobile,
   Mobile bekommt groessere Trefferflaechen und kompaktere Panels. */

:root {
  --bg: #241711;
  --panel: rgba(28, 18, 14, 0.92);
  --panel2: rgba(46, 30, 22, 0.95);
  --line: #7a5030;
  --gold: #f0b429;
  --cyan: #5ef2e0;
  --text: #f3e6d2;
  --hud: 15px;
}

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

button, .act, a.btn {
  font-family: inherit; color: var(--text); cursor: pointer;
  background: linear-gradient(#5a3a26, #3a2418);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 12px; font-size: var(--hud);
}
button:hover { background: linear-gradient(#6d4830, #462c1c); }
button:active { transform: translateY(1px); }

/* ------------------------------------------------------------- Laden */
#loading {
  position: fixed; inset: 0; z-index: 60; display: flex; gap: 18px;
  flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #4a2a1c, #180f0b 70%);
  transition: opacity .6s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
#loading h1 {
  font-size: clamp(26px, 6vw, 54px); letter-spacing: .18em; margin: 0;
  color: var(--gold); text-shadow: 0 0 26px rgba(240,180,41,.35);
}
#loading h1 span { display: block; font-size: .45em; color: var(--cyan); letter-spacing: .5em; }
#loading .bar { width: min(420px, 70vw); height: 8px; background: #2c1c14; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#loading .bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--cyan)); transition: width .2s; }
#loading .txt { opacity: .7; font-size: 14px; }

/* ----------------------------------------------------------- Kopfzeile */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 46px; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: linear-gradient(#241711ee, #241711aa);
  border-bottom: 1px solid var(--line);
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
#resbar { display: flex; gap: 6px; }
.res {
  display: flex; align-items: center; gap: 5px; font-size: var(--hud);
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 3px 9px 3px 4px; min-width: 62px;
}
.res img { width: 22px; height: 22px; object-fit: contain; }
.res.warn { border-color: #e0603c; color: #ffbfa8; }
#ageinfo { font-size: 13px; opacity: .95; min-width: 120px; }
#agebar { height: 5px; background: #2c1c14; border-radius: 4px; margin-top: 3px; display: none; }
#agebar > i { display: block; height: 100%; width: 0; background: var(--cyan); border-radius: 4px; }
.spacer { flex: 1; }
.tb { padding: 6px 10px; font-size: 13px; letter-spacing: .06em; }

/* ------------------------------------------------------------ Minimap */
#minimap {
  position: fixed; right: max(8px, env(safe-area-inset-right)); top: 54px; z-index: 20;
  width: 180px; height: 180px; border: 2px solid var(--line); border-radius: 8px;
  background: #3a2418; box-shadow: 0 6px 18px #0008;
}

/* ------------------------------------------------------- Auswahlpanel */
#selPanel {
  position: fixed; left: max(8px, env(safe-area-inset-left)); bottom: 8px; z-index: 22;
  width: min(420px, 46vw); max-height: 42vh; overflow-y: auto; display: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; box-shadow: 0 8px 22px #0007;
}
#selPanel.show { display: block; }
#selTitle { font-size: 16px; color: var(--gold); font-weight: bold; }
#selSub { font-size: 12.5px; opacity: .8; margin: 2px 0 7px; line-height: 1.3; }
#selActions { display: flex; flex-direction: column; gap: 5px; }
.act { display: flex; align-items: center; gap: 8px; text-align: left; font-size: 13.5px; padding: 7px 9px; }
.act img { width: 20px; height: 20px; object-fit: contain; }
.queue { font-size: 12px; opacity: .8; padding: 3px 2px; }

/* ---------------------------------------------------------- Baumenue */
#buildToggle {
  position: fixed; right: max(10px, env(safe-area-inset-right)); bottom: 12px; z-index: 24;
  font-size: 17px; letter-spacing: .1em; padding: 12px 22px;
  background: linear-gradient(#8a5a20, #5a3a12); border-color: var(--gold);
}
#buildPanel {
  position: fixed; right: max(8px, env(safe-area-inset-right)); bottom: 62px; z-index: 23;
  width: min(640px, 62vw); max-height: 56vh; display: none;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 26px #0009; overflow: hidden;
}
body.build-open #buildPanel { display: flex; flex-direction: column; }
.bp-head {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-bottom: 1px solid var(--line); font-size: 14px; color: var(--gold);
}
#hint { flex: 1; font-size: 12px; color: var(--text); opacity: .75; font-weight: normal; }
#cancelBuild { padding: 2px 10px; }
.bp-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 7px; padding: 9px; overflow-y: auto;
}
.card.locked { opacity: .32; filter: grayscale(1); }
.card.poor { border-color: #7a3a30; }
.bp-grid .card {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; font-size: 11.5px; line-height: 1.15;
}
.thumb { width: 62px; height: 52px; object-fit: contain; }
.cname { color: var(--gold); font-size: 12px; text-align: center; }
.cost { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; opacity: .85; }
.cost .c { display: inline-flex; align-items: center; gap: 2px; }
.cost img { width: 13px; height: 13px; }

/* ------------------------------------------------------------ Meldungen */
#msgs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 8px; z-index: 21;
  font-size: 13px; text-align: center; text-shadow: 0 2px 4px #000; pointer-events: none;
  opacity: .92; max-width: 46vw;
}
#toast {
  position: fixed; left: 50%; top: 58px; transform: translateX(-50%) translateY(-8px);
  z-index: 30; background: var(--panel2); border: 1px solid var(--gold); color: var(--gold);
  padding: 7px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: .25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#flashLayer { position: fixed; inset: 0; pointer-events: none; z-index: 25; }
.gain {
  position: absolute; transform: translate(-50%, -50%); font-size: 13px; font-weight: bold;
  text-shadow: 0 2px 4px #000;
}
.ping {
  position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border: 2px solid #fff; border-radius: 50%; animation: ping .55s ease-out forwards;
}
@keyframes ping { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.selbox {
  position: absolute; border: 1.5px solid var(--cyan); background: rgba(94,242,224,.12);
}

/* ------------------------------------------------------------- Overlays */
.overlay, #menu {
  position: fixed; inset: 0; z-index: 40; display: none;
  align-items: center; justify-content: center; background: rgba(10,6,4,.72);
  padding: 16px;
}
.overlay.show, #menu.open { display: flex; }
.overlay .card, #menu .card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; max-width: 620px; max-height: 88vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 16px 40px #000a;
}
.overlay h2, #menu h2 { margin: 0; color: var(--gold); letter-spacing: .06em; }
.overlay p, #menu p { margin: 0; font-size: 14px; line-height: 1.45; opacity: .9; }
.keys { margin: 0; padding-left: 18px; font-size: 12.5px; opacity: .8; line-height: 1.5; }
#menu a { color: var(--cyan); font-size: 13px; text-align: center; }
button.ghost { background: none; border-color: #55402e; }

/* --------------------------------------------------------- Querformat */
#portrait {
  position: fixed; inset: 0; z-index: 90; display: none;
  align-items: center; justify-content: center; text-align: center;
  background: #180f0b; color: var(--text); font-size: 17px;
}
#portrait .rot { font-size: 60px; color: var(--gold); animation: turn 2s infinite ease-in-out; }
@keyframes turn { 0%,100% { transform: rotate(0); } 50% { transform: rotate(90deg); } }
@media (orientation: portrait) and (pointer: coarse) {
  #portrait { display: flex; }
}

/* --------------------------------------------------------- Mobile-Tuning */
body.touch { --hud: 12px; }
body.touch #topbar { height: 34px; gap: 6px; }
body.touch .res { min-width: 46px; padding: 1px 6px 1px 2px; border-radius: 6px; }
body.touch .res img { width: 15px; height: 15px; }
body.touch #ageinfo { font-size: 11px; min-width: 84px; }
body.touch .tb { padding: 4px 8px; font-size: 11px; }
body.touch #minimap { width: 92px; height: 92px; top: 38px; }
body.touch #selPanel { width: min(300px, 44vw); max-height: 44vh; padding: 7px 8px; }
body.touch #selTitle { font-size: 13.5px; }
body.touch #selSub { font-size: 11px; margin-bottom: 5px; }
body.touch .act { padding: 8px 8px; font-size: 12px; }
body.touch #buildPanel { width: min(520px, 66vw); bottom: 52px; max-height: 62vh; }
body.touch .bp-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 5px; padding: 6px; }
body.touch .bp-grid .card { font-size: 10px; padding: 4px 2px; }
body.touch .cname { font-size: 10.5px; }
body.touch .thumb { width: 44px; height: 38px; }
body.touch .cost img { width: 11px; height: 11px; }
body.touch #buildToggle { padding: 9px 16px; font-size: 14px; bottom: 8px; }
body.touch #msgs { max-width: 36vw; font-size: 11px; bottom: 4px; }
/* Auf kleinen Displays nie zwei grosse Panels gleichzeitig */
body.touch.build-open #selPanel { display: none; }
body.touch.build-open #msgs { display: none; }

@media (max-height: 430px) {
  #minimap { width: 92px; height: 92px; }
  #selPanel { max-height: 46vh; }
  #buildPanel { max-height: 64vh; }
}

/* Lange Gebäudenamen dürfen die Kacheln nicht sprengen */
.cname { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Untätige Bots melden sich am BOTS-Knopf, wie der Idle-Villager-Button in AoE */
.tb.alert { border-color: var(--gold); color: var(--gold); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 rgba(240,180,41,0); } 50% { box-shadow: 0 0 12px rgba(240,180,41,.55); } }
