/* ============================================================
   BURGENWERK — Style v2
   Dunkles Tech-Theme im Bytewerk-Stil (Amber + Cyan)
   Glas-UI, Glow, polierte Buttons, Dot-Kosten-Chips
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Manrope:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --paper:  #14161f;
  --paper-2:#191c28;
  --surface:#20242f;
  --surface-2:#2a2f3d;
  --ink:    #eef1f7;
  --ink-soft:#b9c0cf;
  --muted:  #8a93a6;
  --line:   #333a4b;
  --line-2: #414a5f;
  --accent: #e8a45c;
  --accent-300:#f4c995;
  --on-accent:#241a0d;
  --neon:   #6fd3e8;
  --danger: #e05252;
  --good:   #6fd39b;
  --gold:   #f2c14e;
  --wood:   #a9773f;
  --stone:  #8d96a8;
  --radius: 12px;
  --ease: cubic-bezier(0.4, 0, 0.1, 1);
  --font-d: 'Space Grotesk', system-ui, sans-serif;
  --font-b: 'Manrope', system-ui, sans-serif;
  --font-m: 'JetBrains Mono', ui-monospace, monospace;
  --glass: rgba(25, 28, 40, 0.72);
  --glass-strong: rgba(25, 28, 40, 0.92);
  --glow-amber: 0 8px 30px rgba(232, 164, 92, 0.28);
}

* { box-sizing: border-box; margin: 0; }
::selection { background: rgba(232,164,92,0.35); color: var(--ink); }
html, body { height: 100%; }
body {
  font-family: var(--font-b);
  background:
    radial-gradient(900px 600px at 80% -10%, rgba(232,164,92,0.10), transparent 60%),
    radial-gradient(700px 500px at 0% 110%, rgba(111,211,232,0.07), transparent 55%),
    var(--paper);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app { position: relative; width: 100vw; height: 100vh; }
canvas#game {
  position: absolute; inset: 0; margin: auto;
  width: min(100vw, 177.78vh); height: min(100vh, 56.25vw);
  display: block;
  cursor: crosshair;
}
.hidden { display: none !important; }

/* ---------- Generic ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-b); font-weight: 600; font-size: 14px;
  min-height: 42px;
  padding: 11px 20px; border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.btn:active { transform: none; }
.btn:focus-visible, .bb-item:focus-visible, .castle-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-300), var(--accent) 55%, #d98b3f);
  color: var(--on-accent); border-color: transparent;
  box-shadow: 0 4px 16px rgba(232,164,92,0.25);
}
.btn-primary { position: relative; overflow: hidden; }
.btn-primary::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,0.35), transparent);
  transform: skewX(-20deg);
  transition: left 0.5s var(--ease);
  pointer-events: none;
}
.btn-primary:hover::after { left: 120%; }
.btn-primary:hover { box-shadow: var(--glow-amber); filter: brightness(1.05); }
.btn-ghost { background: var(--glass); backdrop-filter: blur(8px); }
.btn-lg { padding: 15px 28px; font-size: 16px; }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn.insufficient { opacity: 0.5; }

/* ---------- Top bar ---------- */
#topbar {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--glass); border: 1px solid rgba(255,255,255,0.07);
  border-top-color: rgba(255,255,255,0.14);
  border-radius: 14px; padding: 9px 16px;
  backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  z-index: 5;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tb-title {
  font-family: var(--font-d); font-weight: 700; letter-spacing: 0.04em;
  color: var(--accent-300);
  text-shadow: 0 0 18px rgba(232,164,92,0.4);
}
.tb-res { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-m); font-size: 13px; color: var(--ink-soft); }
.tb-res b { color: var(--ink); font-weight: 600; min-width: 26px; display: inline-block; transition: color 0.2s; }
.tb-res .lbl { font-size: 10px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.tb-res.bump b { animation: bump 0.4s var(--ease); }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); color: var(--accent-300); text-shadow: 0 0 12px rgba(232,164,92,0.7); }
  100% { transform: scale(1); }
}
.tb-tag {
  font-family: var(--font-m); font-size: 12px; color: var(--ink-soft);
  border: 1px solid var(--line-2); background: rgba(20,22,31,0.4);
  padding: 4px 12px; border-radius: 999px;
}
.tb-tag.warn { color: var(--danger); border-color: var(--danger); animation: pulse-warn 1.4s infinite; }
@keyframes pulse-warn { 0%,100% { box-shadow: none; } 50% { box-shadow: 0 0 12px rgba(224,82,82,0.5); } }

/* ---------- Icons (Ressourcen-Dots) ---------- */
.ic { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: currentColor; -webkit-mask: center/contain no-repeat; mask: center/contain no-repeat; color: var(--accent); }
.ic-wood { -webkit-mask-image: radial-gradient(circle, #000 0 100%); mask-image: radial-gradient(circle, #000 0 100%); background: var(--wood); color: var(--wood); }
.ic-stone { background: var(--stone); color: var(--stone); mask-image: none; -webkit-mask-image: none; border-radius: 2px; }
.ic-gold { background: var(--gold); color: var(--gold); border-radius: 50%; box-shadow: 0 0 8px rgba(242,193,78,0.5); }
.ic-army { background: var(--neon); color: var(--neon); -webkit-mask-image: radial-gradient(circle at 50% 30%, #000 0 46%, transparent 47%), linear-gradient(#000,#000); -webkit-mask-size: 100% 70%, 100% 30%; -webkit-mask-position: 0 0, 0 70%; }
.ic-tower { background: #c9d2e0; color: #c9d2e0; -webkit-mask-image: linear-gradient(#000 60%, transparent 60%); -webkit-mask-size: 60% 100%; -webkit-mask-position: center; }
.ic-wall { background: #8d97a9; color: #8d97a9; -webkit-mask-image: linear-gradient(90deg, transparent 0 12%, #000 12% 88%, transparent 88%); }
.ic-house { background: #c8b08a; color: #c8b08a; -webkit-mask-image: linear-gradient(135deg, transparent 0 30%, #000 30% 70%, transparent 70%); }
.ic-saw { background: #8a6f4a; color: #8a6f4a; -webkit-mask-image: radial-gradient(circle, #000 0 45%, transparent 46%); }
.ic-smith { background: #c7a1e8; color: #c7a1e8; -webkit-mask-image: linear-gradient(#000,#000); -webkit-mask-size: 70% 45%; -webkit-mask-position: center top 30%; }

/* ---------- Build bar ---------- */
#buildbar {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 190px; background: var(--glass);
  border: 1px solid rgba(255,255,255,0.08); border-radius: 16px; padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: 0 16px 50px rgba(0,0,0,0.45);
  z-index: 4;
}
.bb-head {
  font-family: var(--font-m); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); padding-bottom: 6px; display: flex; align-items: center; gap: 8px;
}
.bb-head::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-2), transparent); }
.bb-item {
  display: flex; align-items: center; gap: 9px; min-height: 40px;
  font-family: var(--font-b); font-weight: 600; font-size: 13px; color: var(--ink-soft);
  background: rgba(32,36,47,0.75); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; cursor: pointer; text-align: left;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}
.bb-item:hover { border-color: var(--accent); color: var(--ink); background: rgba(42,47,61,0.9); box-shadow: 0 0 14px rgba(232,164,92,0.12); }
.bb-item.selected {
  border-color: var(--accent); background: linear-gradient(90deg, rgba(232,164,92,0.18), rgba(232,164,92,0.05));
  color: var(--ink); box-shadow: inset 0 0 0 1px rgba(232,164,92,0.3), 0 0 16px rgba(232,164,92,0.15);
}
.bb-item .ic { width: 18px; height: 18px; flex-shrink: 0; }
.bb-item.insufficient { opacity: 0.42; }
.bb-cost {
  display: inline-flex; align-items: center; gap: 3px; margin-left: auto;
  font-family: var(--font-m); font-size: 10px; color: var(--muted); white-space: nowrap;
}
.bb-cost .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin: 0 2px 0 4px; }
.bb-cost .dot.w { background: var(--wood); box-shadow: 0 0 6px rgba(169,119,63,0.55); }
.bb-cost .dot.s { background: var(--stone); box-shadow: 0 0 6px rgba(141,150,168,0.45); }
.bb-cost .dot.g { background: var(--gold); box-shadow: 0 0 6px rgba(242,193,78,0.55); }
.bb-sell { margin-top: 8px; font-size: 13px; }
.bb-help { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 8px; }

/* ---------- Action bar ---------- */
#actionbar {
  position: absolute; right: 12px; bottom: 14px;
  display: flex; gap: 10px; z-index: 5; flex-wrap: wrap; justify-content: flex-end;
}

/* ---------- Panels ---------- */
.panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--glass-strong);
  border: 1px solid rgba(255,255,255,0.10);
  border-top-color: rgba(255,255,255,0.18);
  border-radius: 20px; padding: 36px 40px; z-index: 20;
  backdrop-filter: blur(18px) saturate(1.3);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 30px 90px rgba(0,0,0,0.6),
    0 0 60px rgba(232,164,92,0.06);
  max-width: min(92vw, 560px); max-height: 86vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
  animation: panel-in 0.35s var(--ease);
}
@keyframes panel-in { from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.panel::before {
  content: ""; position: absolute; inset: -1px; border-radius: 21px; pointer-events: none;
  background: linear-gradient(160deg, rgba(232,164,92,0.25), transparent 30%, transparent 70%, rgba(111,211,232,0.18));
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  padding: 1px;
}
.panel h2 { font-family: var(--font-d); font-size: 30px; letter-spacing: -0.02em; }
.panel p, .panel li { color: var(--ink-soft); font-size: 15px; line-height: 1.6; }
.panel ul { padding-left: 18px; display: flex; flex-direction: column; gap: 10px; }
.panel b { color: var(--accent-300); }
.ap-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; align-items: center; }
.ap-row .btn { flex: 1; justify-content: center; }
#attackPanel .ap-row .btn { flex: 1; }

.castle-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; background: var(--surface);
  min-height: 44px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.castle-row .cr-name { font-weight: 700; }
.castle-row .cr-meta { margin-left: auto; font-family: var(--font-m); font-size: 12px; color: var(--muted); }
.castle-row .cr-state { font-family: var(--font-m); font-size: 12px; color: var(--muted); }
.castle-row:hover { border-color: var(--accent); background: var(--surface-2); transform: translateY(-1px); }

/* ---------- Menu ---------- */
.menu { align-items: stretch; text-align: center; gap: 12px; padding: 46px 52px; min-width: min(92vw, 420px); }
.menu-title {
  font-family: var(--font-d); font-size: 62px; font-weight: 700; letter-spacing: -0.03em; line-height: 0.95;
  background: linear-gradient(180deg, #fff3e0 0%, var(--accent-300) 45%, #d98b3f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 24px rgba(232,164,92,0.45));
}
.menu-title span { color: var(--neon); -webkit-text-fill-color: var(--neon); filter: drop-shadow(0 4px 24px rgba(111,211,232,0.45)); }
.menu { position: relative; }
.menu::before {
  content: "";
  position: absolute; inset: auto 0 0 0; height: 96px; pointer-events: none;
  background:
    radial-gradient(240px 60px at 75% 100%, rgba(232,164,92,0.18), transparent 70%),
    radial-gradient(180px 50px at 15% 100%, rgba(111,211,232,0.12), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 96'%3E%3Cpath d='M0 96V70l14-16 12 16v-24l14-16 12 16v30z' fill='%231c2230'/%3E%3Cpath d='M84 96V62l12-14 12 14v-20l16-18 16 18v34z' fill='%23182028'/%3E%3Cpath d='M168 96V66l14-18 14 18v14l12-14 12 14v16z' fill='%231c2230'/%3E%3Cpath d='M252 96V60l16-20 16 20v-16l14-16 14 16v32z' fill='%23182028'/%3E%3Cpath d='M336 96V70l14-18 14 18v-14l12-14 12 14v22z' fill='%231c2230'/%3E%3C/svg%3E") bottom/cover no-repeat;
  opacity: 0.85;
  border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; overflow: hidden;
}
.menu-title { animation: title-pulse 3.2s ease-in-out infinite; }
@keyframes title-pulse {
  0%, 100% { filter: drop-shadow(0 4px 24px rgba(232,164,92,0.45)); }
  50% { filter: drop-shadow(0 4px 34px rgba(232,164,92,0.75)); }
}
.menu-sub {
  font-family: var(--font-m); font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px;
}
.menu .btn { justify-content: center; box-shadow: none; }
.menu .btn-primary { box-shadow: 0 4px 16px rgba(232,164,92,0.25); }
.menu-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Help ---------- */
#help ul { list-style: none; padding: 0; }
#help li::before { content: "▸ "; color: var(--accent); }
#help .btn { align-self: flex-end; }

/* ---------- Touchziele ---------- */
@media (pointer: coarse) {
  .btn, .bb-item { min-height: 46px; }
  .btn-sm { min-height: 42px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .btn:hover, .btn-primary:hover { transform: none; }
  .btn-primary::after { display: none; }
  .menu::before { display: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  #buildbar { width: 160px; }
  .bb-item { font-size: 12px; padding: 8px 8px; }
  #topbar { padding: 7px 10px; gap: 8px; }
  .tb-title { font-size: 13px; }
  .tb-res { font-size: 11.5px; }
  .menu-title { font-size: 46px; }
}
@media (max-width: 560px) {
  #buildbar {
    display: flex; left: 10px; right: 10px; top: auto; bottom: 88px;
    transform: none; width: auto; flex-direction: row; flex-wrap: wrap; gap: 6px;
    padding: 10px; background: var(--glass-strong);
  }
  #buildbar .bb-head, #buildbar .bb-help { display: none; }
  #buildbar .bb-sell { flex-basis: 100%; }
  .bb-item { flex: 1 1 calc(25% - 6px); justify-content: center; font-size: 0; gap: 0; padding: 10px 6px; }
  .bb-item .ic { width: 22px; height: 22px; }
  .bb-item .bb-cost { display: none; }
  #topbar { flex-direction: column; align-items: stretch; }
  .tb-right { justify-content: flex-end; }
  #actionbar { left: 10px; right: 10px; bottom: 14px; justify-content: center; }
  #actionbar .btn { flex: 1; padding: 13px 10px; }
  .menu { padding: 32px 24px; }
}