:root {
  --bg-deep: #17141f;
  --bg-panel: #241f30;
  --bg-slot: #2c2639;
  --bg-slot-empty: #1c1826;
  --ink: #f5f1fe;
  --ink-soft: #c8bfda;
  --ink-faint: #9186a6;
  --line: #453c58;
  --line-strong: #5c5175;
  --accent: #f2c14e;
  --accent-ink: #2a2113;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow-soft: 0 18px 45px -22px rgba(0, 0, 0, 0.75);
  --shadow-peg: inset 0 3px 6px rgba(255, 255, 255, 0.32), inset 0 -6px 10px rgba(0, 0, 0, 0.35);

  --c-red: #ef6f67;
  --c-amber: #f2c14e;
  --c-blue: #56aede;
  --c-green: #82d072;
  --c-violet: #b083e8;
  --c-teal: #46c9b4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  font-family: "Inter", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 20% -10%, #2f2748 0%, transparent 55%),
    radial-gradient(900px 500px at 92% 8%, #26203c 0%, transparent 50%),
    var(--bg-deep);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- App shell: full-height, no page scroll ---------- */
.app {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.85rem 0;
}

/* ---------- Masthead ---------- */
.masthead {
  flex: 0 0 auto;
  padding-bottom: 0.5rem;
}

.masthead__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.masthead__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(120deg, #f6dda0, #ef6f67 45%, #b083e8 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.masthead__actions { display: flex; gap: 0.4rem; }

.masthead__greeting {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.masthead__tagline {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin-top: 0.1rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- Board (scroll area) ---------- */
.board {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.25rem 0.15rem 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.board::-webkit-scrollbar { width: 6px; }
.board::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

.rows {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.row {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-md);
  background: var(--bg-slot-empty);
  border: 1px solid transparent;
  opacity: 0.55;
  transition: opacity 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}

.row--active {
  opacity: 1;
  background: var(--bg-slot);
  border-color: var(--line-strong);
  box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.25);
}

.row--done { opacity: 1; }

.row__num {
  font-size: 0.78rem;
  color: var(--ink-faint);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.row__slots {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.slot {
  width: clamp(1.9rem, 8.5vw, 2.5rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg-slot-empty);
  border: 2px solid var(--line);
  transition: transform 0.12s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.row--active .slot:not(.slot--filled) {
  border-color: var(--line-strong);
  border-style: dashed;
  background: #221d2f;
}

.slot--filled {
  border-style: solid;
  border-color: rgba(0, 0, 0, 0.25);
  box-shadow: var(--shadow-peg);
}

.slot--pop { animation: pop 0.22s ease; }

@keyframes pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------- Feedback pegs (high contrast) ---------- */
.feedback {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 0.68rem);
  gap: 0.3rem;
  width: max-content;
  padding-right: 0.1rem;
}

.hint {
  width: 0.68rem;
  height: 0.68rem;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--line-strong);
}

/* Right place — bright filled dot */
.hint--exact {
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--accent) 85%);
  border-color: #fff3d0;
  box-shadow: 0 0 6px rgba(242, 193, 78, 0.75);
}

/* Right colour, wrong place — hollow bright ring */
.hint--color {
  background: transparent;
  border: 2px solid #f3eefe;
}

/* ---------- Console (sticky bottom) ---------- */
.console {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-soft);
  padding: 0.85rem 0.9rem calc(0.85rem + env(safe-area-inset-bottom));
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board__status {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
  min-height: 1.2rem;
  transition: color 0.2s ease;
}
.board__status em {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}

.palette {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip {
  width: clamp(2.4rem, 11vw, 3rem);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: pointer;
  box-shadow: var(--shadow-peg);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.chip:hover { transform: translateY(-3px) scale(1.05); }
.chip:active { transform: translateY(0) scale(0.96); }
.chip:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Peg colours (chips, slots, end-code) */
.peg-red { background: radial-gradient(circle at 32% 28%, #ff9089, var(--c-red)); }
.peg-amber { background: radial-gradient(circle at 32% 28%, #ffe09a, var(--c-amber)); }
.peg-blue { background: radial-gradient(circle at 32% 28%, #a6dcf6, var(--c-blue)); }
.peg-green { background: radial-gradient(circle at 32% 28%, #bff0b3, var(--c-green)); }
.peg-violet { background: radial-gradient(circle at 32% 28%, #d9bef8, var(--c-violet)); }
.peg-teal { background: radial-gradient(circle at 32% 28%, #90efdf, var(--c-teal)); }

.controls {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.6rem;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.98rem;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.18s ease, opacity 0.18s ease, filter 0.18s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--small { padding: 0.55rem 0.9rem; font-size: 0.9rem; }

.btn--primary {
  background: linear-gradient(135deg, #f6d67a, var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -12px rgba(242, 193, 78, 0.8);
}
.btn--primary:hover:not(:disabled) { filter: brightness(1.05); }

.btn--soft {
  background: var(--bg-slot);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn--soft:hover:not(:disabled) { background: #332c44; }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 16, 0.74);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 1.25rem;
  z-index: 50;
  animation: fade 0.2s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal__card {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 1.6rem 1.5rem;
  max-width: 400px;
  width: 100%;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  box-shadow: var(--shadow-soft);
  animation: rise 0.25s ease;
}
.modal__card--center { text-align: center; }
@keyframes rise {
  from { transform: translateY(14px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal__card h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  padding-right: 1.5rem;
}
.modal__card p { color: var(--ink-soft); line-height: 1.55; margin-bottom: 0.8rem; }
.modal__card strong { color: var(--ink); }

.modal__close {
  position: absolute;
  top: 0.7rem;
  right: 0.85rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}
.modal__close:hover { color: var(--ink); }

.legend {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.4rem 0 1rem;
}
.legend li { display: flex; align-items: center; gap: 0.6rem; color: var(--ink-soft); }

.peg-hint { width: 1rem; height: 1rem; border-radius: 50%; flex-shrink: 0; }
.peg-hint--exact {
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--accent) 85%);
  border: 1px solid #fff3d0;
  box-shadow: 0 0 6px rgba(242, 193, 78, 0.7);
}
.peg-hint--color { background: transparent; border: 2px solid #f3eefe; }

/* ---------- Settings / constructor ---------- */
.settings__hint { font-size: 0.9rem; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.4rem;
  border-bottom: 1px solid var(--line);
}
.stepper__label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-weight: 600;
  color: var(--ink);
  font-size: 0.98rem;
}
.stepper__val {
  color: var(--accent);
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  font-family: "Fraunces", Georgia, serif;
}
.stepper__buttons { display: flex; gap: 0.5rem; }
.stepper__btn {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg-slot);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
.stepper__btn:hover:not(:disabled) { background: #332c44; }
.stepper__btn:active:not(:disabled) { transform: scale(0.92); }
.stepper__btn:disabled { opacity: 0.3; cursor: not-allowed; }

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 0.4rem 0.4rem;
  cursor: pointer;
}
.toggle__label { font-weight: 600; color: var(--ink); font-size: 0.98rem; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle__track {
  width: 3rem;
  height: 1.7rem;
  border-radius: 999px;
  background: var(--bg-slot);
  border: 1px solid var(--line-strong);
  flex-shrink: 0;
  position: relative;
  transition: background 0.2s ease;
}
.toggle__thumb {
  position: absolute;
  top: 50%;
  left: 0.2rem;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: transform 0.2s ease, background 0.2s ease;
}
.toggle input:checked + .toggle__track { background: linear-gradient(135deg, #f6d67a, var(--accent)); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateY(-50%) translateX(1.3rem); background: var(--accent-ink); }
.toggle input:focus-visible + .toggle__track { outline: 3px solid var(--ink); outline-offset: 2px; }

.settings__preview {
  color: var(--ink-soft);
  font-size: 0.88rem;
  text-align: center;
  padding: 0.9rem 0 0.4rem;
  line-height: 1.5;
}
.settings__preview strong { color: var(--accent); }

.settings__actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

/* ---------- End code ---------- */
.end-code { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.6rem; margin: 0.5rem 0 1.5rem; }
.end-code .slot {
  width: 2.4rem;
  border: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: var(--shadow-peg);
  animation: pop 0.3s ease backwards;
}
.end-code .slot:nth-child(1) { animation-delay: 0.05s; }
.end-code .slot:nth-child(2) { animation-delay: 0.13s; }
.end-code .slot:nth-child(3) { animation-delay: 0.21s; }
.end-code .slot:nth-child(4) { animation-delay: 0.29s; }
.end-code .slot:nth-child(5) { animation-delay: 0.37s; }
.end-code .slot:nth-child(6) { animation-delay: 0.45s; }

/* ---------- Add-to-home-screen banners (in-flow, top) ---------- */
.a2hs {
  position: relative;
  flex: 0 0 auto;
  background: linear-gradient(135deg, #2b2440, var(--bg-panel));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px -18px rgba(0, 0, 0, 0.8);
  padding: 0.8rem 2.4rem 0.8rem 1rem;
  margin-bottom: 0.6rem;
  animation: slidedown 0.3s ease;
}
.a2hs[hidden] { display: none; }
@keyframes slidedown {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.a2hs p { color: var(--ink-soft); font-size: 0.9rem; line-height: 1.45; }
.a2hs strong { color: var(--ink); }
.a2hs--android { display: flex; align-items: center; gap: 0.75rem; }
.a2hs--android p { flex: 1; }
.a2hs__icon { vertical-align: -4px; color: var(--accent); }
.a2hs__close {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  width: 1.8rem;
  height: 1.8rem;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.a2hs__close:hover { color: var(--ink); }

/* ---------- Larger screens ---------- */
@media (min-width: 520px) {
  .app { padding-top: 1.75rem; }
  .console { border-radius: var(--radius-lg); margin-bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
