/* ============ Basis / Reset ============ */
:root {
  /* 8 unterscheidbare Farbtöne (farbenblind-freundlich gewählt) */
  --c1: #e6194b; /* rot */
  --c2: #3cb44b; /* grün */
  --c3: #4363d8; /* blau */
  --c4: #ffe119; /* gelb */
  --c5: #f58231; /* orange */
  --c6: #911eb4; /* violett */
  --c7: #42d4f4; /* cyan */
  --c8: #f032e6; /* magenta */

  --bg: #1f2330;
  --panel: #2b3042;
  --panel-2: #353b50;
  --line: #444c66;
  --text: #eef1f8;
  --muted: #9aa3bd;
  --accent: #ffb000;
  --peg-black: #15171f;
  --peg-white: #ffffff;
  --empty: #1a1d28;

  --slot-size: 52px;
  --gap: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  touch-action: manipulation;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; }

/* ============ Screens ============ */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

.panel {
  margin: auto;
  width: 100%;
  max-width: 560px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

h1 { font-size: 2.2rem; letter-spacing: 1px; text-align: center; }
h2 { font-size: 1.4rem; text-align: center; }
.subtitle { text-align: center; color: var(--muted); margin-top: -10px; }
.hint, .subtitle { font-size: .95rem; }
.hint { text-align: center; color: var(--muted); min-height: 1.2em; }
.hint.error { color: #ff6b6b; }

/* ============ Buttons ============ */
.primary {
  background: var(--accent);
  color: #1a1300;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1.05rem;
  font-weight: 700;
}
.primary:disabled { opacity: .4; }
.primary:active:not(:disabled) { transform: translateY(1px); }
.big { width: 100%; min-height: 54px; }

.ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 1rem;
}
.ghost:active { background: var(--panel-2); }

.btn-bar { display: flex; gap: 12px; align-items: stretch; }
.btn-bar.vertical { flex-direction: column; }
.btn-bar .ghost { flex: 0 0 auto; }
.btn-bar .primary { flex: 1; }

/* ============ Settings ============ */
.settings { display: flex; flex-direction: column; gap: 6px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.setting-row label { font-size: 1.05rem; }

.stepper { display: flex; align-items: center; gap: 8px; }
.step-btn {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); font-size: 1.4rem; line-height: 1;
}
.step-btn:active { background: var(--line); }
.stepper input {
  width: 48px; text-align: center; font-size: 1.2rem; font-weight: 700;
  background: transparent; border: none; color: var(--text);
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 58px; height: 34px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 34px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 26px; width: 26px; left: 3px; top: 3px;
  background: var(--muted); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(24px); background: #1a1300; }

/* ============ Code-Reihe (Geheimcode legen) ============ */
.code-row {
  display: flex; gap: var(--gap); justify-content: center; flex-wrap: wrap;
}
.code-row.small { --slot-size: 38px; }

.slot {
  width: var(--slot-size); height: var(--slot-size);
  border-radius: 50%;
  background: var(--empty);
  border: 2px solid var(--line);
  box-shadow: inset 0 3px 6px rgba(0,0,0,.45);
  flex: 0 0 auto;
}
.slot.filled { border-color: rgba(255,255,255,.35); box-shadow: inset 0 2px 4px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.3); }
.slot.active-target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,176,0,.35); }

/* ============ Palette ============ */
.palette {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding: 4px 0;
}
.peg-pick {
  width: 50px; height: 50px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: inset 0 -4px 8px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.4);
  flex: 0 0 auto;
}
.peg-pick.selected { outline: 3px solid var(--accent); outline-offset: 2px; transform: scale(1.08); }
.peg-pick:active { transform: scale(.94); }

/* Farbzuordnung */
.color-1 { background: var(--c1); }
.color-2 { background: var(--c2); }
.color-3 { background: var(--c3); }
.color-4 { background: var(--c4); }
.color-5 { background: var(--c5); }
.color-6 { background: var(--c6); }
.color-7 { background: var(--c7); }
.color-8 { background: var(--c8); }

/* ============ Rate-Screen ============ */
#screen-play.active { display: flex; }

.play-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.reveal-btn {
  position: relative; flex: 1; min-height: 50px;
  background: var(--panel-2); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 1rem; font-weight: 600; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.reveal-btn:active { background: var(--line); }
.reveal-label { transition: opacity .25s; }
.reveal-code {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2);
  opacity: 0; pointer-events: none;
  transition: opacity 1s ease;
}
.reveal-btn.revealed .reveal-code { opacity: 1; transition: opacity .15s ease; }
.reveal-btn.revealed .reveal-label { opacity: 0; }
.reveal-code .mini {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
}

.attempts-badge {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; font-size: .9rem; color: var(--muted);
  white-space: nowrap;
}
.attempts-badge span { color: var(--text); font-weight: 700; font-size: 1.1rem; }

.board-wrap { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.board {
  display: flex; flex-direction: column-reverse; /* erste Reihe unten */
  gap: 8px; padding: 14px; max-width: 560px; margin: 0 auto;
}

.guess-row {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 10px; border-radius: 14px;
  background: var(--panel);
}
.guess-row.current { background: var(--panel-2); box-shadow: 0 0 0 2px var(--accent) inset; }
.guess-row.done { opacity: .92; }

.row-index { width: 22px; text-align: center; color: var(--muted); font-size: .85rem; flex: 0 0 auto; }

.guess-slots { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.guess-row .slot { --slot-size: 40px; }

/* Pin-Feld (schwarz/weiß) */
.pins {
  display: grid; gap: 4px; flex: 0 0 auto;
  grid-template-columns: repeat(2, 1fr);
  width: 40px;
}
.pin {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--empty); border: 1px solid var(--line);
}
.pin.black { background: var(--peg-black); border-color: #000; }
.pin.white { background: var(--peg-white); border-color: #cfd3e0; }

.play-footer {
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.play-footer .palette, .play-footer .btn-bar { max-width: 560px; width: 100%; margin: 0 auto; }

/* ============ Ende-Overlay ============ */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 20;
  background: rgba(10,12,18,.8); backdrop-filter: blur(3px);
  align-items: center; justify-content: center; padding: 20px;
}
.overlay.active { display: flex; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 24px; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 18px; text-align: center;
}
#overlay-text { color: var(--muted); }
.overlay-card .code-row { margin: 4px 0; }

/* ============ iPad / Querformat ============ */
@media (min-width: 768px) {
  :root { --slot-size: 60px; }
  .peg-pick { width: 58px; height: 58px; }
  .guess-row .slot { --slot-size: 46px; }
  h1 { font-size: 2.6rem; }
}

@media (orientation: landscape) and (min-width: 900px) {
  .board { max-width: 720px; }
  .play-footer .palette, .play-footer .btn-bar { max-width: 720px; }
}
