:root {
  --ink: #1d2340;
  --panel: rgba(6, 10, 30, 0.66);
  --brand: #3b3f9e;
  --gold: #ffc861;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: #fff; background: #03050f; }
button { font: inherit; touch-action: manipulation; color: inherit; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #eef0fa;
  border: 1px solid #c6cbe4;
  color: var(--ink);
}

#sky {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none;
}
body.playing #sky { cursor: crosshair; }

/* ---------- Top: toolbar and progress ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.6vh; }
#toolbar button {
  width: clamp(40px, min(6vh, 7.5vw), 64px); height: clamp(40px, min(6vh, 7.5vw), 64px);
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: clamp(20px, min(3vh, 3.75vw), 32px);
  cursor: pointer;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(10, 16, 44, 0.92); }
#progress {
  display: flex; gap: 1.4vh; align-items: center;
  font-weight: 800; font-size: clamp(18px, min(3.4vh, 4.25vw), 40px); line-height: 1;
}
#progress div { background: var(--panel); border-radius: 2vh; padding: 1vh 1.8vh 0.7vh; white-space: nowrap; }
#progress div:empty { display: none; }
#score { color: #8ef0a0; }

/* ---------- The metal card for "What colour?" ---------- */
#tag {
  position: fixed; left: 50%; top: 20vh;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  animation: bob 3s ease-in-out infinite;
  transition: opacity 0.6s, top 0.8s;
}
#tag.gone { opacity: 0; top: 10vh; }
@keyframes bob { 50% { margin-top: -1.2vh; } }

/* ---------- Bottom panels ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 2vh;
  margin: 0 auto;
  width: fit-content; max-width: 97vw; min-width: min(620px, 97vw);
  background: var(--panel);
  border-radius: 2.6vh;
  padding: 1.2vh 1.6vh 1.6vh;
  z-index: 10;
  backdrop-filter: blur(3px);
}
#msg, #play-msg {
  margin: 0;
  min-height: 1.2em;
  text-align: center;
  font-weight: 800;
  font-size: clamp(20px, min(4.2vh, 5vw), 50px);
  line-height: 1.2;
  text-shadow: 0 0.25vh 0 rgba(0, 0, 0, 0.35);
}
#play-msg { font-size: clamp(17px, min(3.2vh, 4vw), 38px); }
#msg.right { color: #8ef0a0; }
#msg.wrong { color: #ffb4a8; }
#msg.note { color: #d6dcff; }
#msg.pop { animation: pop 0.45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }
#fact {
  margin: 0.2vh 0 0;
  text-align: center;
  font-size: clamp(15px, min(2.6vh, 3.2vw), 30px);
  font-weight: 600;
  color: #d6dcff;
  line-height: 1.25;
}
#fact:empty { display: none; }

#options, #play-metals {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 1.2vh;
  margin-top: 1.2vh;
}

/* An element as it is on the periodic table */
.element {
  position: relative;
  width: clamp(62px, min(12vh, 12.5vw), 136px); aspect-ratio: 1;
  border-radius: 1.4vh;
  border: 0.4vh solid transparent;
  background: linear-gradient(#fbfcff, #dfe4f6);
  color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0.5vh 0 #8b93c2;
  transition: transform 0.12s, border-color 0.15s;
}
.element small {
  position: absolute; top: 7%; left: 10%;
  font-size: clamp(11px, min(1.9vh, 2vw), 22px); font-weight: 700; color: #59618c;
}
.element b { font-size: clamp(26px, min(5.2vh, 5.5vw), 62px); font-weight: 800; margin-top: 0.4vh; }
.element span { font-size: clamp(11px, min(1.9vh, 2vw), 22px); font-weight: 700; color: #3c4470; }
.element em {
  font-style: normal;
  font-size: clamp(10px, min(1.6vh, 1.7vw), 19px); font-weight: 700; color: #59618c;
  display: flex; align-items: center; gap: 0.25em;
}
.element em::before {
  content: ''; width: 0.75em; height: 0.75em; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
button.element:hover { transform: translateY(-0.3vh); }
button.element:active { transform: translateY(0.4vh); box-shadow: none; }
.element.right { border-color: #3fbf5a; background: linear-gradient(#efffef, #c9f3cf); }
.element.wrong { opacity: 0.55; cursor: default; }
.element.wrong::after {
  content: '✗'; position: absolute; top: 4%; right: 9%;
  color: #d33a2c; font-weight: 800; font-size: clamp(14px, min(2.6vh, 2.8vw), 30px);
}
.element[aria-pressed='true'] {
  border-color: var(--c);
  box-shadow: 0 0 2.4vh var(--c), 0 0.5vh 0 #8b93c2;
}

.element.big {
  width: clamp(130px, min(26vh, 30vw), 280px);
  border-radius: 3vh;
  border-width: 0.6vh;
  border-color: #fff;
  box-shadow: 0 0 6vh rgba(255, 220, 150, 0.45), 0 1vh 0 #8b93c2;
  cursor: default;
}
.element.big small { font-size: clamp(18px, min(3.6vh, 4vw), 40px); }
.element.big b { font-size: clamp(56px, min(11vh, 12vw), 124px); }
.element.big span { font-size: clamp(20px, min(3.8vh, 4.2vw), 42px); }

/* A colour to pick */
.swatch {
  min-width: clamp(70px, min(13vh, 13vw), 150px);
  white-space: nowrap;
  border: 0.4vh solid transparent;
  border-radius: 1.6vh;
  background: rgba(255, 255, 255, 0.1);
  padding: 1vh 0.6vh 0.6vh;
  display: flex; flex-direction: column; align-items: center; gap: 0.6vh;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}
.swatch i {
  width: clamp(40px, min(7.5vh, 8vw), 86px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, #fff 0, var(--c) 28%, var(--c) 52%, transparent 72%);
  box-shadow: 0 0 2vh var(--c);
}
.swatch span { font-weight: 800; font-size: clamp(13px, min(2.5vh, 2.6vw), 28px); line-height: 1; padding: 0 0.3em; }
.swatch:hover { transform: translateY(-0.3vh); }
.swatch.chosen { border-color: #fff; }
.swatch.right { border-color: #6ee77f; background: rgba(110, 231, 127, 0.22); }
.swatch.wrong { border-color: #ff8a7a; background: rgba(255, 120, 100, 0.2); }
.swatch:disabled { cursor: default; }
#options:has(.swatch:disabled) .swatch:not(.chosen, .right, .wrong) { opacity: 0.5; }
#options.waiting .element:not(.wrong) { opacity: 0.75; cursor: wait; }

#actions { display: flex; gap: 1.2vh; justify-content: center; margin-top: 1.4vh; }
#actions button, #finale, #play-shapes button {
  border: none;
  border-radius: 1.6vh;
  font-weight: 800; line-height: 1;
  cursor: pointer;
}
#replay {
  height: clamp(40px, min(6.4vh, 8vw), 72px); padding: 0 3vh;
  background: rgba(255, 255, 255, 0.18);
  font-size: clamp(17px, min(3vh, 3.6vw), 34px);
}
#next {
  height: clamp(44px, min(7vh, 9vw), 80px); padding: 0 4vh;
  background: var(--gold); color: #4a3300;
  font-size: clamp(20px, min(3.8vh, 4.8vw), 46px);
  box-shadow: 0 0.5vh 0 #c99a12;
}
#actions button:active, #finale:active { transform: translateY(0.4vh); box-shadow: none; }

/* ---------- Free play ---------- */
#play-row {
  display: flex; flex-wrap: wrap; gap: 1.2vh; justify-content: center; align-items: center;
  margin-top: 1.4vh;
}
#play-shapes { display: flex; flex-wrap: wrap; gap: 0.8vh; justify-content: center; }
#play-shapes button {
  height: clamp(40px, min(6.4vh, 8vw), 72px); padding: 0 1.8vh;
  display: flex; align-items: center; gap: 0.8vh;
  background: rgba(255, 255, 255, 0.12);
  border: 0.35vh solid transparent;
  font-size: clamp(15px, min(2.8vh, 3.2vw), 32px);
}
#play-shapes svg { height: 70%; width: auto; }
#play-shapes button[aria-pressed='true'] { border-color: #fff; background: rgba(255, 255, 255, 0.26); }
#finale {
  height: clamp(40px, min(6.4vh, 8vw), 72px); padding: 0 3vh;
  background: var(--gold); color: #4a3300;
  font-size: clamp(17px, min(3vh, 3.6vw), 34px);
  box-shadow: 0 0.5vh 0 #c99a12;
}

/* ---------- Menu and end of round ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(3, 5, 20, 0.35), rgba(3, 5, 20, 0.75));
  overflow: auto;
  padding: 3vh 2vw;
}
#end {
  position: fixed; left: 0; right: 0; bottom: 2vh;
  display: grid; justify-items: center;
  z-index: 20;
  padding: 0 2vw;
}
.panel {
  width: min(900px, 94vw);
  background: rgba(250, 251, 255, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
#end .panel { padding: 18px 28px; }
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--brand); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #4a5070; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cards.wide { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.cards.narrow { grid-template-columns: repeat(auto-fill, minmax(110px, 140px)); }
.cards.wide-text { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pair { display: flex; flex-wrap: wrap; gap: 0 28px; }
.pair > div { flex: 1 1 340px; }
.pair > div:first-child { flex: 0 1 450px; }
.cards button {
  border: 3px solid #dadff0;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.cards button:hover { transform: translateY(-2px); }
.cards button[aria-pressed='true'] { border-color: var(--brand); background: #eceefb; }
.cards b { display: block; font-size: 22px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #5d6386; line-height: 1.3; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
#end .buttons { margin-top: 14px; }
.buttons button {
  border: 2px solid var(--brand);
  background: #fff;
  color: var(--brand);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px; font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: var(--brand); color: #fff; font-size: 22px; padding: 12px 34px; box-shadow: 0 6px 0 #23266b; }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #23266b; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 16px; font-size: 15px; color: #4a5070; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }

#end-score { margin: 0; font-size: 56px; line-height: 1; color: var(--brand); }
#end-first { margin: 4px 0 12px; }
#end-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 0; padding: 0; list-style: none;
}
#end-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 14px 3px 10px;
  border-radius: 999px;
  font-size: 18px; font-weight: 700;
}
#end-list li i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
#end-list .right { background: #d8f5dd; color: #1d6b2c; }
#end-list .missed { background: #fde0dc; color: #9b2a1f; }

@media (max-width: 600px) {
  #toolbar button { width: 38px; height: 38px; font-size: 19px; border-radius: 10px; }
  #progress { font-size: 17px; gap: 6px; }
  #progress div { padding: 6px 10px 4px; border-radius: 12px; }
  .panel { padding: 18px 18px 16px; }
  .logo { font-size: 38px; }
  #end-score { font-size: 42px; }
  #play-shapes button span { display: none; }
}

@media (max-height: 560px) {
  .panel { padding: 16px 22px; }
  .logo { font-size: 36px; }
}
