:root {
  --bg: #f5f4f0;
  --stage: #e7e5df;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #d9d6cf;
  --accent: #0083c7;
  --ok: #02a301;
  --shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 16px rgba(0, 0, 0, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --stage: #121211;
    --card: #262624;
    --text: #efeee9;
    --muted: #a3a19b;
    --line: #3a3936;
    --accent: #3ba7e0;
    --ok: #39c238;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand img { image-rendering: pixelated; border-radius: 3px; }
.tabs { display: flex; gap: 4px; background: var(--stage); padding: 3px; border-radius: 8px; }
.tab {
  border: 0;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); font-weight: 600; }
.count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 9px;
  background: var(--line);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.name { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.name span { color: var(--muted); }
.name input {
  width: 150px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}
.name input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Leinwand ---------- */
#stage { position: relative; background: var(--stage); overflow: hidden; touch-action: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
#view.zoom-in { cursor: zoom-in; }
#view.panning { cursor: grabbing; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }

.palette {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(16, 30px);
  gap: 5px;
  padding: 8px;
}
.swatch {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(0, 0, 0, .18);
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
  transition: transform .08s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch[aria-checked="true"] { outline: 2px solid var(--text); outline-offset: 2px; transform: translateY(-2px); }

.zoom { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; overflow: hidden; }
.zoom button {
  width: 36px;
  height: 34px;
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: var(--stage); }

.coords {
  position: absolute;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  font: 12px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  pointer-events: none;
}

/* ---------- Kreativ-Modus ---------- */
.goal { position: absolute; top: 16px; right: 16px; width: 260px; padding: 12px; display: grid; gap: 10px; }
.goal-head { display: flex; justify-content: space-between; font-weight: 600; }
.goal-body { display: flex; gap: 12px; align-items: center; }
#goal-img {
  width: 88px;
  height: 88px;
  flex: none;
  image-rendering: pixelated;
  border-radius: 4px;
  background: repeating-conic-gradient(#fff 0 25%, #ececec 0 50%) 0 0 / 11px 11px;
  border: 1px solid var(--line);
}
.goal-info { display: grid; gap: 6px; flex: 1; }
.goal-name { font-size: 16px; font-weight: 700; }
.meter { position: relative; height: 10px; border-radius: 5px; background: var(--stage); overflow: hidden; }
#meter-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s, background .25s; }
.meter.reached #meter-fill { background: var(--ok); }
.meter .mark { position: absolute; top: 0; bottom: 0; left: 70%; width: 2px; background: var(--text); opacity: .55; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.solved { font-size: 13px; }

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 3;
}
.toast.good { background: var(--ok); color: #fff; }
.conn {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 6px;
  background: #b3261e;
  color: #fff;
  font-size: 13px;
}

/* ---------- Handy ---------- */
@media (max-width: 760px) {
  .bar { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; padding: 6px 8px; }
  .name span { display: none; }
  .name input { width: 130px; }
  .palette { grid-template-columns: repeat(8, 32px); gap: 6px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .swatch { width: 32px; height: 32px; }
  .zoom { display: none; }
  .coords { display: none; }
  .goal { top: 12px; left: 12px; right: 12px; width: auto; padding: 10px; gap: 6px; }
  .goal-body { gap: 10px; }
  #goal-img { width: 56px; height: 56px; }
  .goal-head, .solved { display: none; }
  .conn { bottom: 110px; }
}
