/* =========================================================
   Quak Attack – Styles (bunter, knubbeliger Cartoon-Look)
   ========================================================= */
:root {
  --panel: #3a7bd0;
  --panel-l: #5b9cea;
  --panel-d: #173a70;
  --ink: #10223f;
  --gold: #ffd23f;
  --green: #5ccf3a;
  --green-d: #25700f;
  --red: #ec4339;
  --red-d: #8a1712;
  --blue: #3d8ff0;
  --blue-d: #17457f;
  --wood: #c98b4a;
  --sidebar-w: 268px;
  --outline: 0 2px 0 var(--ink), 0 -1px 0 var(--ink), 1.5px 0 0 var(--ink), -1.5px 0 0 var(--ink), 1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: radial-gradient(ellipse at 50% 20%, #2f74c9 0%, #164a93 55%, #0c2b5c 100%);
  color: #fff;
  font-family: 'Lilita One', 'Nunito', system-ui, sans-serif;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; color: inherit; }
.hidden { display: none !important; }
#app { height: 100%; }
.screen { height: 100%; }

/* ---------- Buttons ---------- */
.btn {
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px 22px;
  font-size: 20px;
  letter-spacing: 0.5px;
  text-shadow: var(--outline);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25), inset 0 3px 0 rgba(255, 255, 255, 0.35), 0 4px 0 var(--ink);
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 1px 0 var(--ink); }
.btn-green { background: linear-gradient(#7fe05a, #47b32a); }
.btn-blue { background: linear-gradient(#69aaf7, #2f78d4); }
.btn-red { background: linear-gradient(#ff7468, #d6342b); }
.btn-big { font-size: 30px; padding: 12px 46px; margin-top: 18px; }

.btn-icon {
  width: 42px; height: 42px;
  border: 3px solid var(--ink); border-radius: 12px;
  background: linear-gradient(#69aaf7, #2f78d4);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 var(--ink);
  display: grid; place-items: center; padding: 0;
}
.btn-icon svg { width: 22px; height: 22px; fill: #fff; color: #fff; filter: drop-shadow(0 1.5px 0 var(--ink)); }
.btn-icon:active { transform: translateY(2px); }

kbd {
  font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 12px;
  background: rgba(255, 255, 255, 0.15); border: 1px solid rgba(255, 255, 255, 0.35);
  border-bottom-width: 3px; border-radius: 5px; padding: 0 5px;
}

/* ---------- Menü ---------- */
#menu {
  overflow-y: auto;
  display: flex; justify-content: center;
  background:
    radial-gradient(circle at 15% 85%, rgba(92, 207, 58, 0.25), transparent 40%),
    radial-gradient(circle at 85% 15%, rgba(255, 210, 63, 0.18), transparent 35%);
}
.menu-inner { width: min(860px, 100%); padding: 24px 16px 40px; text-align: center; }
.logo {
  margin: 8px 0 0; line-height: 0.9;
  display: flex; flex-direction: column; align-items: center;
  transform: rotate(-3deg);
}
.logo span { display: block; text-shadow: 0 6px 0 var(--ink), 0 -3px 0 var(--ink), 4px 0 0 var(--ink), -4px 0 0 var(--ink), 3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink), 0 10px 18px rgba(0, 0, 0, 0.35); }
.logo .l1 { font-size: clamp(56px, 11vw, 104px); color: #7fe05a; }
.logo .l2 { font-size: clamp(48px, 9vw, 86px); color: var(--gold); margin-top: -6px; }
.tagline { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 18px; margin: 14px 0 18px; opacity: 0.95; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }

.panel {
  background: linear-gradient(var(--panel-l), var(--panel));
  border: 4px solid var(--ink);
  border-radius: 24px;
  padding: 10px 20px 26px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.3), inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 8px 0 var(--ink), 0 18px 40px rgba(0, 0, 0, 0.35);
}
.panel h2 { font-weight: 400; font-size: 26px; margin: 14px 0 10px; text-shadow: var(--outline); }

.map-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.map-card {
  background: var(--panel-d); border: 4px solid var(--ink); border-radius: 18px;
  padding: 6px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.12s;
}
.map-card canvas { width: 100%; aspect-ratio: 3 / 2; border-radius: 12px; display: block; }
.map-card:hover { transform: translateY(-3px); }
.map-card.active { background: var(--gold); outline: 3px solid #fff; outline-offset: 2px; }
.map-card.active .map-info b { color: var(--ink); text-shadow: none; }
.map-info { display: flex; flex-direction: column; align-items: center; gap: 3px; padding-bottom: 4px; }
.map-info b { font-weight: 400; font-size: 20px; text-shadow: var(--outline); }
.lvl { font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 12px; border-radius: 99px; padding: 2px 10px; border: 2px solid var(--ink); }
.lvl-0 { background: #7fe05a; color: var(--ink); }
.lvl-1 { background: #ffb02e; color: var(--ink); }
.lvl-2 { background: #ff5a4e; color: #fff; }
.best { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; color: #dff0ff; min-height: 16px; }
.map-card.active .best { color: var(--ink); }

.diff-list { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.diff-btn {
  min-width: 150px;
  border: 3px solid var(--ink); border-radius: 14px; padding: 8px 14px;
  background: linear-gradient(#69aaf7, #2f78d4);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 4px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center;
}
.diff-btn b { font-weight: 400; font-size: 22px; text-shadow: var(--outline); }
.diff-btn small { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; opacity: 0.95; }
.diff-btn.active { background: linear-gradient(#ffe57a, #f5b616); color: var(--ink); }
.diff-btn.active b { color: #fff; }
.hint { font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 13px; opacity: 0.85; margin-top: 26px; line-height: 2; }

/* ---------- Spiel-Layout ---------- */
#game { display: grid; grid-template-columns: 1fr var(--sidebar-w); height: 100%; }
#stage { position: relative; display: grid; place-items: center; padding: 10px; min-width: 0; min-height: 0; overflow: hidden; }
#canvasWrap {
  position: relative;
  border: 4px solid var(--ink); border-radius: 14px; overflow: hidden;
  box-shadow: 0 8px 0 var(--ink), 0 18px 40px rgba(0, 0, 0, 0.4);
  box-sizing: content-box;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
#canvas.placing { cursor: crosshair; }

#hud { position: absolute; left: 10px; top: 8px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#hudRight { position: absolute; right: 10px; top: 8px; display: flex; align-items: center; gap: 8px; }
.hud-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 26px; text-shadow: var(--outline); line-height: 1;
}
.hud-item small { font-size: 18px; opacity: 0.9; }
.hud-item.round { margin-right: 4px; font-size: 24px; }
.hud-item.hit { animation: hit 0.35s; }
@keyframes hit { 30% { transform: scale(1.25); color: #ff8a80; } }
.ico { width: 26px; height: 26px; display: inline-block; flex: none; }
.ico.heart {
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-8.5-5.3-8.5-11.2A4.8 4.8 0 0 1 12 6.6a4.8 4.8 0 0 1 8.5 3.2C20.5 15.7 12 21 12 21z' fill='%23ff4d4d' stroke='%2310223f' stroke-width='2.2' stroke-linejoin='round'/%3E%3Cellipse cx='8' cy='9.5' rx='2' ry='1.3' fill='%23fff' opacity='.7'/%3E%3C/svg%3E");
}
.ico.coin {
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='%23ffd23f' stroke='%2310223f' stroke-width='2.2'/%3E%3Ccircle cx='12' cy='12' r='5.8' fill='none' stroke='%23b37800' stroke-width='1.6'/%3E%3Cellipse cx='12' cy='12' rx='1.6' ry='2.8' fill='%23b37800'/%3E%3C/svg%3E");
}

#toast {
  position: absolute; left: 50%; top: 14%;
  transform: translate(-50%, -10px) scale(0.9);
  padding: 8px 20px; border-radius: 14px; border: 3px solid var(--ink);
  background: var(--panel); font-size: 22px; text-shadow: var(--outline);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; white-space: nowrap;
  box-shadow: 0 4px 0 var(--ink);
}
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#toast.good { background: linear-gradient(#7fe05a, #47b32a); }
#toast.bad { background: linear-gradient(#ff7468, #d6342b); }

/* ---------- Seitenleiste ---------- */
#sidebar {
  display: flex; flex-direction: column;
  margin: 10px 10px 10px 0;
  background: linear-gradient(var(--panel-l), var(--panel) 30%, #2f69b8);
  border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.3), 0 8px 0 var(--ink);
  padding: 10px; min-height: 0;
}
#shopView, #towerView { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.side-title { font-size: 26px; text-align: center; text-shadow: var(--outline); margin-bottom: 8px; }
.shop { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.shop-item { min-width: 0; touch-action: none; cursor: grab; }
.shop-item:active { cursor: grabbing; }
#dragGhost { position: fixed; z-index: 20; pointer-events: none; transform: translate(-50%, -50%) scale(1.1); filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4)); }
#dragGhost canvas { width: 64px; height: 64px; display: block; }
.shop-item {
  position: relative;
  background: linear-gradient(#2d5f9e, #214a80);
  border: 3px solid var(--ink); border-radius: 14px;
  padding: 4px 4px 6px;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 3px 0 var(--ink);
  transition: transform 0.08s;
}
.shop-item canvas { width: 56px; height: 56px; }
.shop-item:hover { transform: translateY(-2px); background: linear-gradient(#3a72bb, #28589a); }
.shop-item.active { background: linear-gradient(#ffe57a, #f5b616); }
.shop-item.active .si-name { color: var(--ink); text-shadow: none; }
.si-key { position: absolute; left: 6px; top: 3px; font-size: 13px; opacity: 0.7; text-shadow: var(--outline); }
.si-name { font-size: 12px; text-shadow: var(--outline); line-height: 1.1; text-align: center; }
.si-cost { font-size: 15px; color: var(--gold); text-shadow: var(--outline); }
.si-cost::before, .up-cost::before, .info .cost::before, .tp-sv::before { content: ''; display: inline-block; width: 13px; height: 13px; margin-right: 3px; border-radius: 50%; background: var(--gold); border: 2px solid var(--ink); vertical-align: -1px; }
.shop-item.poor { filter: saturate(0.4) brightness(0.8); }
.shop-item.poor .si-cost { color: #ff7a70; }

.info {
  margin-top: 10px; padding: 8px 10px;
  background: rgba(10, 30, 60, 0.35); border-radius: 12px; border: 2px solid rgba(16, 34, 63, 0.6);
  min-height: 92px;
}
.info b { font-weight: 400; font-size: 17px; text-shadow: var(--outline); }
.info .cost { color: var(--gold); margin-left: 6px; }
.info p { font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 13px; margin: 4px 0 0; line-height: 1.35; }

/* Turm-Panel */
.tp-head { display: flex; align-items: center; gap: 6px; }
.tp-icon { width: 64px; height: 64px; background: rgba(10, 30, 60, 0.35); border-radius: 12px; border: 2px solid rgba(16, 34, 63, 0.6); }
.tp-title { flex: 1; display: flex; flex-direction: column; }
.tp-title b { font-weight: 400; font-size: 20px; text-shadow: var(--outline); line-height: 1.1; }
.tp-title small { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; opacity: 0.9; }
.tp-close {
  width: 32px; height: 32px; border-radius: 10px; border: 3px solid var(--ink);
  background: linear-gradient(#ff7468, #d6342b); font-size: 16px; padding: 0; text-shadow: var(--outline);
  box-shadow: 0 2px 0 var(--ink); align-self: flex-start;
}
.tp-stats {
  margin-top: 8px; padding: 6px 8px; border-radius: 12px;
  background: rgba(10, 30, 60, 0.35); border: 2px solid rgba(16, 34, 63, 0.6);
  transition: background 0.15s, border-color 0.15s;
}
.tp-stats.preview { background: rgba(40, 90, 20, 0.45); border-color: #7fe05a; }
.st-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 10px; }
.st { display: flex; justify-content: space-between; align-items: baseline; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11.5px; }
.st span { opacity: 0.8; }
.st b { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 14px; text-shadow: 0 1px 0 var(--ink); }
.st.changed { grid-column: 1 / -1; }
.st.changed b { color: #b6ff7a; font-size: 15px; }
.tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.tag { font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 10.5px; padding: 1px 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.18); border: 1.5px solid rgba(16, 34, 63, 0.7); }
.tag.bad { background: rgba(236, 67, 57, 0.45); }
.tag.new { background: #7fe05a; color: var(--ink); animation: pulse 0.8s infinite; }

.tp-paths { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.tp-path { background: rgba(10, 30, 60, 0.35); border-radius: 12px; padding: 6px; border: 2px solid rgba(16, 34, 63, 0.6); border-left: 6px solid #ffb02e; }
.tp-path.p1 { border-left-color: #4fd6ff; }
.tp-pname { font-size: 14px; text-shadow: var(--outline); margin: 0 0 3px 2px; }
.tp-path.p0 .tp-pname { color: #ffcf6e; }
.tp-path.p1 .tp-pname { color: #8ee6ff; }
.tp-steps { list-style: none; margin: 0 0 5px; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.tp-steps li { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11.5px; opacity: 0.5; display: flex; align-items: center; gap: 5px; }
.tp-steps li i { font-style: normal; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; background: rgba(255, 255, 255, 0.2); border: 1.5px solid var(--ink); flex: none; }
.tp-steps li.done { opacity: 1; }
.tp-steps li.done i { background: #7fe05a; color: var(--ink); }
.tp-steps li.next { opacity: 1; color: var(--gold); }
.tp-steps li.next i { background: var(--gold); color: var(--ink); }
.tp-up {
  width: 100%; min-height: 70px;
  border: 3px solid var(--ink); border-radius: 12px;
  padding: 5px 8px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 3px 0 var(--ink);
  background: linear-gradient(#7fe05a, #47b32a);
}
.tp-up:active { transform: translateY(2px); }
.tp-up.poor { background: linear-gradient(#8a98ab, #626f82); }
.tp-up.poor .up-cost { color: #ff8a80; }
.tp-up.locked { background: linear-gradient(#6c7686, #4d5666); cursor: not-allowed; opacity: 0.85; }
.tp-up.max { background: linear-gradient(#ffe57a, #f5b616); cursor: default; }
.tp-up.max .up-name { color: #fff; }
.up-name { font-size: 16px; text-shadow: var(--outline); }
.up-desc { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11.5px; line-height: 1.25; text-align: center; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); }
.up-cost { font-size: 17px; color: var(--gold); text-shadow: var(--outline); }
.tp-target { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; background: rgba(10, 30, 60, 0.35); border-radius: 12px; padding: 4px; border: 2px solid rgba(16, 34, 63, 0.6); }
.tp-target button {
  width: 36px; height: 32px; border-radius: 9px; border: 3px solid var(--ink); font-size: 22px; line-height: 1; padding: 0 0 3px;
  background: linear-gradient(#69aaf7, #2f78d4); text-shadow: var(--outline); box-shadow: 0 2px 0 var(--ink);
}
.tp-tval { font-size: 18px; text-shadow: var(--outline); }
.tp-sell {
  margin-top: 10px; border: 3px solid var(--ink); border-radius: 12px; padding: 8px; font-size: 18px;
  background: linear-gradient(#ff7468, #d6342b); text-shadow: var(--outline);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 3px 0 var(--ink);
}
.tp-sell b { font-weight: 400; color: var(--gold); margin-left: 4px; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 2px solid rgba(16, 34, 63, 0.4); margin-top: 8px; }
.auto { font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 14px; display: flex; align-items: center; gap: 6px; cursor: pointer; text-shadow: 0 1px 0 var(--ink); }
.auto input { width: 20px; height: 20px; accent-color: var(--green); }
.btn-go {
  width: 82px; height: 82px; border-radius: 50%;
  border: 4px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #a6f47f, #47b32a 70%);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.25), inset 0 4px 0 rgba(255, 255, 255, 0.4), 0 5px 0 var(--ink);
  display: grid; place-items: center; padding: 0;
  transition: transform 0.08s;
}
.btn-go svg { width: 40px; height: 40px; fill: #fff; filter: drop-shadow(0 2px 0 var(--ink)); margin-left: 4px; }
.btn-go.fast svg, .btn-go.fast-on svg { width: 44px; margin-left: 2px; }
.btn-go.fast { background: radial-gradient(circle at 35% 30%, #9ccaf7, #3a73b8 70%); }
.btn-go.fast-on { background: radial-gradient(circle at 35% 30%, #ffe98a, #f39c12 70%); animation: pulse 0.9s infinite; }
.btn-go.play { animation: pulse 1.6s infinite; }
.btn-go:active { transform: translateY(3px) scale(0.97); }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 15, 35, 0.6); display: grid; place-items: center; z-index: 10; padding: 16px; animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }
.modal-box {
  width: min(460px, 100%); text-align: center;
  background: linear-gradient(var(--panel-l), var(--panel));
  border: 4px solid var(--ink); border-radius: 24px; padding: 18px 22px 24px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.3), 0 8px 0 var(--ink), 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: popin 0.3s cubic-bezier(.2, 1.6, .5, 1);
}
@keyframes popin { from { transform: scale(0.6); opacity: 0; } }
.modal-box h2 { font-weight: 400; font-size: 34px; margin: 4px 0 10px; text-shadow: var(--outline); }
.modal-box.win h2 { color: var(--gold); }
.modal-box.lose h2 { color: #ff8a80; }
.modal-body p { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 16px; margin: 6px 0; }
.modal-body b { color: var(--gold); }
.modal-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 860px), (max-height: 520px) and (orientation: portrait) {
  html, body { overflow: auto; }
  #game { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; min-height: 100%; }
  #stage { height: 66.6vw; max-height: 70vh; padding: 8px 16px; }
  #sidebar { margin: 0 16px 16px; }
  #shopView, #towerView { overflow: visible; }
  .shop { grid-template-columns: repeat(5, 1fr); }
  .map-list { grid-template-columns: 1fr; }
  .hud-item { font-size: 20px; }
  .hud-item.round { font-size: 18px; }
  .ico { width: 20px; height: 20px; }
  .btn-icon { width: 34px; height: 34px; }
  .btn-icon svg { width: 18px; height: 18px; }
}
@media (max-width: 860px) and (orientation: landscape) and (max-height: 520px) {
  #game { grid-template-columns: 1fr 220px; grid-template-rows: 1fr; height: 100%; }
  #stage { height: 100%; max-height: none; }
  #sidebar { margin: 8px 8px 8px 0; }
  #shopView, #towerView { overflow-y: auto; }
  .shop { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .shop { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .shop-item canvas { width: 40px; height: 40px; }
  .si-name { font-size: 9.5px; }
  .si-cost { font-size: 14px; }
}
