/* Crack It — scoped under .game-code. An aubergine injection-moulded decoding tray. */

.game-code { --title: var(--aubergine); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .game-code { --title: #C9A6D3; }
}
:root[data-theme="dark"] .game-code { --title: #C9A6D3; }

.game-code main { padding-block: 8px 48px; }

.game-title { font-family: var(--font-display); font-size: clamp(30px, 6vw, 44px); color: var(--title); }
.game-lede { color: var(--ink-2); margin-top: 6px; }

.status { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin: 10px 0 4px; font-weight: 600; }
.status .muted { color: var(--ink-2); font-weight: 500; }
.status b { font-family: var(--font-display); font-size: 22px; font-weight: 400; color: var(--title); }

/* The moulded tray. --len and --kcols are set from JS. */
.tray {
  --len: 4;
  --kcols: 2;
  width: min(100%, 430px);
  margin: 8px auto 0;
  padding: clamp(14px, 4vw, 22px);
  border-radius: var(--radius-toy);
  background: linear-gradient(160deg, #6B4575 0%, var(--aubergine) 45%, #33203A 100%);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.18),
    inset 0 -3px 0 rgba(0,0,0,.45),
    0 24px 30px -18px rgba(29,35,51,.7),
    0 2px 4px rgba(29,35,51,.3);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* Pegs: a slot is a recessed hole until it is filled. */
.peg {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: #33203A;
  box-shadow: inset 0 3px 5px rgba(0,0,0,.6), inset 0 -1px 0 rgba(255,255,255,.08);
  color: rgba(255,255,255,.88);
  display: grid;
  place-items: center;
  transition: transform .06s ease, box-shadow .12s ease;
}
.peg svg { width: 58%; height: 58%; fill: currentColor; filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
.peg.filled, .tray-peg {
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.55) 0%, var(--peg) 32%, var(--peg-dark) 100%);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.5), inset 0 -3px 4px rgba(0,0,0,.35), 0 3px 0 rgba(0,0,0,.45), 0 4px 6px rgba(0,0,0,.35);
}
.peg[data-color="0"] { --peg: var(--peg-0); --peg-dark: #9E2A2F; }
.peg[data-color="1"] { --peg: var(--peg-1); --peg-dark: #A0701C; }
.peg[data-color="2"] { --peg: var(--peg-2); --peg-dark: #2B6E38; }
.peg[data-color="3"] { --peg: var(--peg-3); --peg-dark: #0B6E80; }
.peg[data-color="4"] { --peg: var(--peg-4); --peg-dark: #263F98; }
.peg[data-color="5"] { --peg: var(--peg-5); --peg-dark: #5C2F86; }

/* Guess rows */
.rows { display: grid; gap: clamp(6px, 1.6vw, 9px); }
.row {
  display: grid;
  grid-template-columns: repeat(var(--len), 1fr) auto;
  gap: clamp(6px, 1.8vw, 10px);
  align-items: center;
  padding: 5px;
  border-radius: 999px;
}
.row.active { background: rgba(0,0,0,.18); box-shadow: inset 0 1px 3px rgba(0,0,0,.35); }
.row .slot { cursor: pointer; }
.row .slot:disabled { cursor: default; }
.row.active .slot.cursor { outline: 3px solid rgba(255,255,255,.85); outline-offset: 2px; }
.row .slot:active { transform: translateY(2px); }
.row .slot:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Key pegs: solid = exact, hollow = near, hole = nothing. Always drawn exact-first. */
.keys {
  display: grid;
  grid-template-columns: repeat(var(--kcols), 12px);
  gap: 5px;
  padding: 6px;
  border-radius: 10px;
  background: rgba(0,0,0,.22);
}
.keys i { display: block; width: 12px; height: 12px; border-radius: 50%; background: #3B2742; box-shadow: inset 0 1px 2px rgba(0,0,0,.55); }
.keys i.exact { background: radial-gradient(circle at 35% 30%, #5A5060, #17111A 55%); box-shadow: 0 1px 1px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.3); }
.keys i.near  { background: transparent; box-shadow: inset 0 0 0 3px #F4EEF6, 0 1px 0 rgba(0,0,0,.5); }

/* The answer row lives behind a sliding shield until the game ends */
.answer {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--len), 1fr);
  gap: clamp(6px, 1.8vw, 10px);
  padding: 8px 10px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: #33203A;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.6);
  overflow: hidden;
}
.answer .slot { width: 66%; margin: 0 auto; }
.shield {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #CBC5CE 0%, #B9B2BC 55%, #A39BA7 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), inset 0 -2px 0 rgba(0,0,0,.18);
  transition: transform .55s cubic-bezier(.4, 0, .2, 1);
  display: grid; place-items: center;
  font: 700 11px/1 var(--font-body);
  letter-spacing: .18em;
  color: rgba(74,46,82,.55);
}
.shield::after { content: 'CODE'; }
.answer.open .shield { transform: translateX(102%); }

/* The peg well: the six colours to pick from */
.palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 16px 4px 4px; }
.tray-peg { width: 46px; height: 46px; cursor: pointer; }
.tray-peg:active { transform: translateY(3px); box-shadow: inset 0 1px 1px rgba(255,255,255,.5), inset 0 -2px 3px rgba(0,0,0,.35), 0 0 0 rgba(0,0,0,.45); }
.tray-peg:disabled { opacity: .5; cursor: default; }
.tray-peg:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Controls and hint */
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }
.hint { text-align: center; color: var(--ink-2); margin: 14px auto 0; min-height: 1.5em; max-width: 46ch; }
.free-controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; }
.opts { display: inline-flex; gap: 6px; }

.verdict { font-family: var(--font-display); font-size: 34px; color: var(--title); line-height: 1.05; }
.verdict.win { color: var(--ok); }

@media (max-width: 480px) {
  .status b { font-size: 20px; }
  .controls .btn { flex: 1 1 40%; }
  .tray-peg { width: 44px; height: 44px; }
}
