:root {
  --paper: #f8f6ee;
  --grid: #e8e5d8;
  --ink: #1d1d1f;
  --muted: #8a877c;
  --green: #3a8c4b;
  --blue: #4a92cc;
  --red: #cc4440;
  --col: clamp(46px, 9.4vw, 100px);
  --gap: clamp(2px, 1vw, 14px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .35; }

/* ---------- Kopfbereich ---------- */

.top {
  padding: 8px 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(26px, 4vw, 46px);
  font-weight: 600;
  letter-spacing: -0.5px;
}

.top-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 12px clamp(16px, 3vw, 40px);
  max-width: 100%;
}

.pvt { max-width: 100%; }

.triads, .cols {
  display: grid;
  grid-template-columns: repeat(7, var(--col));
  column-gap: var(--gap);
}

.triads span {
  text-align: center;
  font-size: 12px;
  letter-spacing: .3px;
  color: var(--muted);
  border-bottom: 1px solid #cfcab6;
  margin: 0 4px 4px;
  padding-bottom: 1px;
}

.col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.col .lbl {
  font-size: clamp(16px, 2.3vw, 28px);
  font-weight: 500;
  line-height: 1.1;
  cursor: help;
}

.digit {
  width: calc(var(--col) * .74);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 3px solid var(--c);
  border-radius: 4px;
  background: rgba(255, 255, 255, .8);
  font-size: calc(var(--col) * .46);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.digit.lead { color: #c3bfae; }

.digit.over {
  color: #c62828;
  background: #fff0ee;
  font-size: calc(var(--col) * .36);
  animation: wobble .5s ease-in-out;
}

.digit.pop { animation: pop .35s ease-out; }

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}

.pm-row { display: flex; gap: clamp(2px, .6vw, 8px); }

.pm {
  width: clamp(26px, 3.6vw, 36px);
  height: clamp(26px, 3.6vw, 36px);
  border-radius: 50%;
  border: 2px solid var(--c);
  background: #fff;
  color: var(--c);
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
}

.pm:not(:disabled):active { background: var(--c); color: #fff; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: calc(var(--col) - 6px);
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--c), var(--c)) 0 / var(--p, 0%) 100% no-repeat, #e2dfd2;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  border: 3px solid var(--c);
  background: #fff;
}

.slider::-moz-range-track { height: 6px; border-radius: 3px; background: #e2dfd2; }
.slider::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--c); }
.slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--c); background: #fff; }
.slider:disabled { opacity: .5; cursor: default; }

.manual {
  display: flex;
  flex-direction: column;
  gap: 3px;
  display: none;
}

body.manual-mode .manual { display: flex; }

.manual button {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--c);
  background: #fff;
  color: var(--c);
  white-space: nowrap;
}

.manual button.hidden { visibility: hidden; }

/* ---------- Zahl ---------- */

.numpanel {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 18px;
}

.bignum {
  font-size: clamp(30px, 4.2vw, 46px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.words {
  font-size: 14px;
  color: #55524a;
  min-height: 2.6em;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.numform { display: flex; gap: 6px; }

.numform input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid #c9c4b0;
  border-radius: 8px;
  background: #fff;
}

.numform input.bad { border-color: var(--red); animation: wobble .4s; }

.numform button, .actions button, .info-btn, dialog button {
  padding: 7px 12px;
  border: 1px solid #c9c4b0;
  border-radius: 8px;
  background: #fff;
}

.actions { display: flex; gap: 6px; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  user-select: none;
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- Bühne ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 300px;
  border-top: 1px solid #ddd8c4;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#scene.dragging { cursor: grabbing; }

.info-btn {
  position: absolute;
  left: 12px;
  top: 12px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

.zoombar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px 10px;
  max-width: calc(100% - 24px);
  padding: 6px 12px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid #ddd8c4;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .07);
}

.zoombar .slider { --c: #5f5c52; width: clamp(90px, 18vw, 200px); }

.zbtn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #c9c4b0;
  border-radius: 50%;
  background: #fff;
  font-size: 18px;
  line-height: 1;
}

/* ---------- Info ---------- */

dialog {
  max-width: min(560px, calc(100vw - 32px));
  border: 1px solid #ddd8c4;
  border-radius: 14px;
  padding: 18px 22px;
  background: #fffdf7;
  color: var(--ink);
  line-height: 1.45;
}

dialog::backdrop { background: rgba(30, 30, 20, .35); }

dialog h2 { margin: 0 0 8px; font-size: 22px; }

.sizes { padding-left: 0; list-style: none; }
.sizes li { padding: 3px 0 3px 12px; border-left: 4px solid; margin: 4px 0; }
.sizes li.g { border-color: var(--green); }
.sizes li.b { border-color: var(--blue); }
.sizes li.r { border-color: var(--red); }

@media (max-width: 700px) {
  .numpanel { padding-top: 0; }
  .pm-row { flex-direction: column-reverse; }
  .pm { width: 32px; height: 32px; }
  .zoombar label:last-child { display: none; }
}
