/* Mastermind — paper-and-ink palette layered with six muted peg colours */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.mode-toggle select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 32px 10px 12px;
  font: 600 13px 'Inter', sans-serif;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%231f3a5f' stroke-width='1.4' stroke-linecap='round' d='M1 1 5 5 9 1'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.mode-toggle select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* Peg colour tokens — chosen to sit on the cream paper without shouting */
:root {
  --peg-red: #b8434a;
  --peg-amber: #d99a2b;
  --peg-green: #4a7a52;
  --peg-blue: #2f5e8c;
  --peg-purple: #6f4a8a;
  --peg-tan: #8a6a44;
  --peg-empty: #efe5cf;
  --peg-border: rgba(31, 58, 95, 0.18);
}

.peg {
  display: inline-block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--peg-border);
  background: var(--peg-empty);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.12), inset 0 3px 5px rgba(255,255,255,0.35);
  vertical-align: middle;
}
.peg.is-empty {
  background: var(--peg-empty);
  box-shadow: inset 0 1px 2px rgba(31, 58, 95, 0.08);
}
.peg[data-color="red"]    { background: var(--peg-red); }
.peg[data-color="amber"]  { background: var(--peg-amber); }
.peg[data-color="green"]  { background: var(--peg-green); }
.peg[data-color="blue"]   { background: var(--peg-blue); }
.peg[data-color="purple"] { background: var(--peg-purple); }
.peg[data-color="tan"]    { background: var(--peg-tan); }

/* Board: 10 rows of guesses, oldest at top */
.board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid transparent;
  transition: background 160ms ease, border-color 160ms ease;
}
.row.is-active {
  background: rgba(244, 227, 178, 0.45);
  border-color: var(--line);
  box-shadow: inset 0 0 0 1px rgba(31, 58, 95, 0.06);
}
.row.is-past { opacity: 0.92; }
.row.is-future { opacity: 0.5; }

.row-num {
  font: 600 12px 'Inter', sans-serif;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.slots {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
}

.slot {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  cursor: default;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.row.is-active .slot { cursor: pointer; }
.row.is-active .slot:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 50%; }
.row.is-active .slot.is-selected .peg {
  box-shadow:
    0 0 0 3px var(--accent-soft),
    0 0 0 4px var(--accent),
    inset 0 -3px 6px rgba(0,0,0,0.12),
    inset 0 3px 5px rgba(255,255,255,0.35);
}
.row.is-active .slot.is-selected .peg.is-empty {
  box-shadow:
    0 0 0 3px var(--accent-soft),
    0 0 0 4px var(--accent),
    inset 0 1px 2px rgba(31, 58, 95, 0.08);
}

.slot .peg {
  width: 34px;
  height: 34px;
}

/* Feedback cluster: 2x2 grid of tiny pegs */
.feedback {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-template-rows: repeat(2, 12px);
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(31, 58, 95, 0.04);
  border: 1px solid rgba(31, 58, 95, 0.06);
}
.fb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(31, 58, 95, 0.18);
  box-sizing: border-box;
}
.fb.is-black {
  background: var(--ink);
  border-color: var(--ink);
}
.fb.is-white {
  background: #fbf6ea;
  border-color: rgba(31, 58, 95, 0.45);
  box-shadow: inset 0 0 0 1px rgba(31, 58, 95, 0.08);
}

/* Feedback pegs reveal one by one — staggered pop-in */
@keyframes mm-fb-in {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.fb.is-black, .fb.is-white {
  animation: mm-fb-in 220ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.fb:nth-child(1).is-black, .fb:nth-child(1).is-white { animation-delay: 40ms; }
.fb:nth-child(2).is-black, .fb:nth-child(2).is-white { animation-delay: 100ms; }
.fb:nth-child(3).is-black, .fb:nth-child(3).is-white { animation-delay: 160ms; }
.fb:nth-child(4).is-black, .fb:nth-child(4).is-white { animation-delay: 220ms; }

/* Peg drop — subtle pop when a colour is placed on the guess row */
@keyframes mm-peg-drop {
  0%   { transform: scale(0.5); }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.peg:not(.is-empty) {
  animation: mm-peg-drop 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (prefers-reduced-motion: reduce) {
  .fb, .peg { animation: none; }
}

/* Composer */
.composer {
  border-top: 1px dashed var(--line);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.composer-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.composer-label {
  font: 600 12px 'Inter', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.palette {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.swatch {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 140ms ease;
}
.swatch:hover { transform: translateY(-1px); }
.swatch .peg { width: 36px; height: 36px; }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 50%; }
.swatch.is-selected .peg {
  box-shadow:
    0 0 0 3px var(--accent-soft),
    0 0 0 4px var(--accent),
    inset 0 -3px 6px rgba(0,0,0,0.12),
    inset 0 3px 5px rgba(255,255,255,0.35);
}

.composer-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--paper); }
.btn-primary:disabled:hover { background: var(--accent); color: var(--paper); }

/* Win/lose overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 42, 58, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 30px;
  text-align: center;
  box-shadow: var(--shadow-lift);
  max-width: 380px;
  width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.overlay-body {
  color: var(--ink-soft);
  margin: 0 0 16px;
  font-size: 14px;
}
.reveal {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 18px 0 22px;
}
.reveal .peg { width: 38px; height: 38px; }
.overlay-actions { display: flex; justify-content: center; gap: 8px; }

/* Mobile */
@media (max-width: 520px) {
  .play { padding: 14px; }
  .row { grid-template-columns: 22px 1fr auto; gap: 8px; padding: 6px 8px; }
  .slots { gap: 6px; }
  .slot { width: 32px; height: 32px; }
  .slot .peg { width: 28px; height: 28px; }
  .feedback { grid-template-columns: repeat(2, 10px); grid-template-rows: repeat(2, 10px); gap: 3px; padding: 3px; }
  .fb { width: 10px; height: 10px; }
  .swatch { width: 36px; height: 36px; }
  .swatch .peg { width: 32px; height: 32px; }
}
