:root {
  --ink: #111;
  --bg: #fff;
  --muted: #777;
  --line: #d9d9d9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

/* ---------- Kopfleiste ---------- */
.bar {
  width: 100%;
  max-width: 900px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
}
.icon {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  border: 0;
}
.hud-stars { flex: 1; text-align: center; font-size: 26px; letter-spacing: 6px; }
.hud-stars .off { opacity: 0.3; }
.level { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }

.sub {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  padding: 6px 0 2px;
}
.counter-box { text-align: center; }
.counter { font-size: 28px; font-weight: 700; line-height: 1.1; }
.tri { font-size: 18px; vertical-align: 3px; }
.label { font-size: 12px; color: var(--muted); }
.badge {
  position: absolute;
  right: 0;
  top: 8px;
  padding: 3px 12px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

/* ---------- Spielfeld ---------- */
main { padding: 6px 0; position: relative; }

canvas {
  display: block;
  border: 2px solid var(--ink);
  border-radius: 4px;
  touch-action: none; /* Pan/Pinch selbst behandeln */
}

.tools {
  margin-top: auto;
  padding: 8px 0 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ---------- Bedienelemente ---------- */
button, input, select {
  font: inherit;
  color: var(--ink);
}
button {
  min-height: 40px;
  min-width: 44px;
  padding: 6px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--bg);
}
button:active { background: var(--ink); color: var(--bg); }
button.primary { background: var(--ink); color: var(--bg); }
button.primary:active { background: var(--bg); color: var(--ink); }
button.danger { border-color: var(--muted); color: var(--muted); }
button:disabled { opacity: 0.35; }
input, select {
  padding: 8px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--bg);
  min-height: 40px;
}
input { width: 9em; -webkit-user-select: text; user-select: text; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.82);
}
.overlay[hidden], .modal[hidden] { display: none; }
.card {
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 18px 24px;
  text-align: center;
}
.card h2 { margin: 4px 0 8px; font-size: 24px; }
.card p { margin: 0 0 14px; color: var(--muted); }
.stars-big { font-size: 36px; letter-spacing: 4px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.9);
}
.sheet {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow: auto;
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 16px;
}
.sheet h2 { margin: 0 0 12px; font-size: 22px; }
.sheet h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); }
.muted { font-size: 14px; color: var(--muted); font-weight: 400; }
.stack { display: grid; gap: 8px; }
.free { display: grid; gap: 10px; }
.free label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint { min-height: 1.2em; margin: 8px 0; font-size: 13px; color: var(--muted); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.level-btn {
  min-height: 62px;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}
.level-btn small { font-size: 11px; letter-spacing: 1px; }
.level-btn.current { background: var(--ink); color: var(--bg); }
.level-btn:disabled { border-style: dashed; }

.install { margin: 4px 0 10px; }
.install button { width: 100%; }
