:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #f6f6f7;
  --card: #fff;
  --tx: #15151e;
  --mu: #6b6b78;
  --red: #e10600;
  --g: #2e9e4f;
  --y: #d9a521;
  --n: #9a9aa6;
  --bd: #ddd;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f14;
    --card: #1b1b24;
    --tx: #f2f2f5;
    --mu: #9a9aa8;
    --bd: #32323f;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f14;
  --card: #1b1b24;
  --tx: #f2f2f5;
  --mu: #9a9aa8;
  --bd: #32323f;
}
html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid var(--red);
  padding-bottom: 10px;
}
h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}
h1 span {
  color: var(--red);
}
.stats {
  font-size: 0.85rem;
  color: var(--mu);
  text-align: right;
}
.stats b {
  color: var(--tx);
}
p.sub {
  color: var(--mu);
  font-size: 0.9rem;
  margin: 10px 0;
}
.in {
  position: relative;
  display: flex;
  gap: 8px;
}
input {
  flex: 1;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--bd);
  border-radius: 10px;
  background: var(--card);
  color: var(--tx);
}
button {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
#sug {
  position: absolute;
  top: 100%;
  left: 0;
  right: 70px;
  z-index: 5;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 10px;
  max-height: 220px;
  overflow: auto;
  margin-top: 4px;
  display: none;
}
#sug div {
  padding: 10px 12px;
  cursor: pointer;
}
#sug div:hover,
#sug .on {
  background: var(--bg);
}
.scroll {
  margin-top: 14px;
  position: relative;
}
#fit {
  transform-origin: 0 0;
  width: 520px;
  --cols: minmax(0, 1.45fr) minmax(0, 1.1fr) minmax(0, 1fr)
    repeat(3, minmax(0, 0.8fr));
}
body {
  overflow-x: hidden;
}
@media (max-width: 480px) {
  main {
    padding: 10px;
  }
}
.row {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 6px;
  margin-bottom: 6px;
}
.row.h div {
  background: none;
  color: var(--mu);
  font-size: 0.72rem;
  text-transform: uppercase;
  min-height: 0;
  padding: 0 2px;
  font-weight: 600;
}
.row div {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 8px;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.8rem;
  padding: 4px;
  font-weight: 600;
  overflow-wrap: anywhere;
  line-height: 1.2;
}
.row div.g {
  background: var(--g);
  color: #fff;
  border-color: var(--g);
}
.row div.y {
  background: var(--y);
  color: #fff;
  border-color: var(--y);
}
.row div.n {
  background: var(--n);
  color: #fff;
  border-color: var(--n);
}
.row div.e {
  opacity: 0.35;
}
#msg {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--bd);
  display: none;
  text-align: center;
}
#msg h2 {
  margin: 0 0 6px;
}
#msg button {
  margin-top: 10px;
}
small {
  color: var(--mu);
  display: block;
  margin-top: 18px;
  font-size: 0.75rem;
}
.row.rv div {
  animation: flip 0.6s ease both;
  animation-delay: calc(var(--i) * 0.35s);
}
@keyframes flip {
  0% {
    transform: rotateX(90deg) scale(0.8);
    opacity: 0;
  }
  60% {
    transform: rotateX(-12deg);
  }
  100% {
    transform: none;
    opacity: 1;
  }
}
.row.win div {
  animation: hop 0.7s ease both;
  animation-delay: calc(var(--i) * 0.09s);
  box-shadow: 0 0 14px #2e9e4f88;
}
@keyframes hop {
  40% {
    transform: translateY(-14px) scale(1.1);
  }
}
.row.lose div {
  animation: shake 0.5s;
}
@keyframes shake {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}
#msg.show {
  animation: pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}
.cf {
  position: fixed;
  top: -16px;
  width: 9px;
  height: 14px;
  z-index: 20;
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  to {
    transform: translate(var(--x), 105vh) rotate(var(--r));
  }
}
@media (prefers-reduced-motion: reduce) {
  .row.rv div,
  .row.win div,
  .cf {
    animation: none;
  }
}
#ov {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 15;
  padding: 16px;
}
#ov.on {
  display: flex;
}
#msg {
  display: block;
  margin: 0;
  padding: 26px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 2px solid var(--red);
}
#msg h2 {
  font-size: 1.7rem;
}
#msg button {
  margin: 10px 4px 0;
}
button.alt {
  background: var(--bg);
  color: var(--tx);
  border: 1px solid var(--bd);
}
#nxt {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.dif {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.dif button {
  background: var(--card);
  color: var(--tx);
  border: 1px solid var(--bd);
  padding: 8px 12px;
  font-size: 0.85rem;
}
.dif button.on {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

/* ---- Loader a cerchio ---- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #0d0d11;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.6s;
  overflow: hidden;
}
#loader.out {
  opacity: 0;
  pointer-events: none;
}
.rw {
  position: relative;
  width: min(300px, 72vw, 40vh);
  width: min(300px, 72vw, 40dvh);
  aspect-ratio: 1;
  flex: none;
}
.under {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 12px;
  width: max(100%, 250px);
  max-width: 92vw;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.rw svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.rw img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 88%;
  transform: translate(-50%, -50%);
  -webkit-mask-image: radial-gradient(circle, #000 62%, transparent 71%);
  mask-image: radial-gradient(circle, #000 62%, transparent 71%);
}
.track {
  fill: none;
  stroke: #23232d;
  stroke-width: 7;
}
.arc {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
}
.dash {
  fill: none;
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 1.5;
  stroke-dasharray: 2 7;
  transform-origin: 100px 100px;
  animation: spin 16s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
#tip {
  stroke: #fff;
  stroke-width: 2;
}
#pct {
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
#lmsg {
  color: #9a9aa8;
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}
#lmsg button {
  display: block;
  margin: 10px auto 0;
}
.by {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #8a8a98;
  letter-spacing: 0.04em;
}
.by img {
  height: 28px;
  width: auto;
}
@media (prefers-reduced-motion: reduce) {
  .dash {
    animation: none;
  }
}
