:root {
  --stage-size: min(100vw, 100vh, 1008px);
  --blue-deep: #073469;
  --blue-line: #23a9e6;
  --cyan: #21b5e7;
  --lime: #d8e51d;
  --green: #79c86a;
  --orange: #ffbd65;
  --red: #f04b54;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #001f45;
}

button {
  font: inherit;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  aspect-ratio: 1;
  border: 1px solid rgba(35, 169, 230, 0.9);
  border-radius: 50%;
  color: #fff;
  background: rgba(5, 41, 84, 0.82);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible,
.config-action:hover,
.config-action:focus-visible,
.config-save:hover,
.config-save:focus-visible,
.config-secondary:hover,
.config-secondary:focus-visible {
  filter: brightness(1.1);
  outline: none;
}

.stage {
  position: relative;
  width: var(--stage-size);
  height: var(--stage-size);
  overflow: hidden;
  background: var(--blue-deep);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: cover;
}

.screen.is-active {
  display: block;
}

.screen-start {
  background-image: url("assets/quiz-start-bg.png");
}

.config-open {
  position: absolute;
  top: 3.2%;
  right: 3.2%;
}

.screen-game {
  background-image: url("assets/quiz-playing-bg.png");
}

.start-button {
  position: absolute;
  left: 50%;
  bottom: 21.5%;
  min-width: 25%;
  min-height: 7%;
  padding: 0 4%;
  transform: translateX(-50%);
  border: 3px solid rgba(35, 169, 230, 0.95);
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(90deg, #18aee6 0%, #87c86f 58%, #dce21f 100%);
  box-shadow:
    0 0 0 6px rgba(5, 40, 80, 0.52),
    0 14px 32px rgba(0, 0, 0, 0.22),
    0 0 28px rgba(32, 180, 226, 0.34);
  cursor: pointer;
  font-size: clamp(18px, calc(var(--stage-size) * 0.026), 28px);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.start-button:hover,
.start-button:focus-visible,
.result-button:hover,
.result-button:focus-visible {
  filter: brightness(1.09);
  outline: none;
}

.hud {
  position: absolute;
  top: 25.2%;
  display: flex;
  align-items: center;
  height: 1.2%;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #fff;
  pointer-events: none;
}

.progress-hud {
  left: 31.75%;
  width: 27.8%;
  padding: 0;
}

.score-hud {
  top: calc(23.9% - 5px);
  right: calc(12.6% - 20px);
  width: 12%;
  height: 4.5%;
  padding: 0 2%;
  justify-content: flex-start;
}

.hud-icon {
  display: none;
  flex: 0 0 auto;
  width: 4.2%;
  min-width: 25px;
  aspect-ratio: 1;
  margin-right: 3.6%;
  border-radius: 50%;
}

.progress-icon {
  background:
    radial-gradient(circle at 50% 50%, var(--lime) 0 18%, transparent 19%),
    conic-gradient(from 0deg, #22b9e8, #86c96f, #e3e21b, #22b9e8);
  filter: drop-shadow(0 0 10px rgba(34, 185, 232, 0.65));
  clip-path: polygon(44% 0, 58% 0, 64% 36%, 100% 42%, 100% 58%, 64% 64%, 58% 100%, 44% 100%, 36% 64%, 0 58%, 0 42%, 36% 36%);
}

.score-icon {
  width: 13.5%;
  min-width: 34px;
  border-radius: 0;
  background: linear-gradient(135deg, #ffe04c 0%, #8ed164 48%, #1fb6e8 100%);
  filter: drop-shadow(0 0 12px rgba(255, 224, 76, 0.5));
  clip-path: path("M 50 86 C 18 58 0 42 0 21 C 0 8 10 0 23 0 C 35 0 44 8 50 18 C 56 8 65 0 77 0 C 90 0 100 8 100 21 C 100 42 82 58 50 86 Z");
}

.hud-label {
  display: none;
  flex: 0 0 auto;
  margin-right: 2.8%;
  color: #f6f8ff;
  font-size: clamp(16px, calc(var(--stage-size) * 0.023), 30px);
  font-weight: 900;
  letter-spacing: 0;
}

.progress-track {
  position: relative;
  flex: 1;
  height: 100%;
  min-height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(1, 29, 60, 0.78);
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1db6e8 0%, #77c870 60%, #dce31f 100%);
  transition: width 260ms ease;
}

.score-value {
  min-width: 2ch;
  color: #fff;
  font-size: clamp(16px, calc(var(--stage-size) * 0.022), 30px);
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.board {
  position: absolute;
  left: 4.55%;
  top: 35.4%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1.95% 1.45%;
  width: 90.9%;
  height: 46.5%;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 800px;
  cursor: pointer;
}

.card:disabled {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: 10%;
  transform-style: preserve-3d;
  transition: transform 360ms ease;
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner,
.card.is-preview .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 10%;
  backface-visibility: hidden;
}

.card-back {
  background: var(--card-back-image, url("assets/card_verso.png")) center / contain no-repeat;
}

.card-front {
  transform: rotateY(180deg);
  border: 3px solid #1ab5e9;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.18), transparent 30%),
    linear-gradient(135deg, var(--face-a), var(--face-b));
  box-shadow: inset 0 0 0 5px #0d3f74;
}

.card-symbol {
  display: grid;
  place-items: center;
  width: 74%;
  aspect-ratio: 1;
  border-radius: 18%;
  color: #fff;
  background: rgba(4, 45, 88, 0.34);
  font-size: clamp(18px, calc(var(--stage-size) * 0.03), 34px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.card-front-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card.is-matched {
  animation: matched 480ms ease;
}

.timer {
  --time-progress: 100%;
  position: absolute;
  left: 50%;
  bottom: 1.7%;
  display: grid;
  place-items: center;
  width: 14.2%;
  aspect-ratio: 1;
  transform: translateX(-50%);
}

.timer-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0 var(--time-progress), var(--orange) var(--time-progress) 82%, var(--red) 82% 100%);
  box-shadow: 0 0 0 7px rgba(0, 0, 0, 0.2);
}

.timer-ring::after {
  position: absolute;
  inset: 13%;
  content: "";
  border-radius: inherit;
  background: #073064;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.timer-value {
  position: relative;
  z-index: 1;
  color: #fff;
  font-size: clamp(22px, calc(var(--stage-size) * 0.045), 48px);
  font-weight: 900;
}

.preview-banner {
  position: absolute;
  left: 50%;
  bottom: 16.9%;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 0 28px;
  transform: translateX(-50%);
  border: 1px solid var(--blue-line);
  border-radius: 999px;
  color: #fff;
  background: rgba(5, 41, 84, 0.92);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  font-weight: 900;
  text-transform: uppercase;
}

.preview-banner[hidden] {
  display: none;
}

.preview-banner strong {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #073064;
  background: var(--lime);
}

.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4.5%;
  background: rgba(2, 22, 48, 0.66);
}

.result[hidden] {
  display: none;
}

.result-panel {
  display: grid;
  justify-items: center;
  width: 88%;
  min-height: 48%;
  padding: 3.2% 5%;
  border: 2px solid rgba(35, 169, 230, 0.95);
  border-radius: 8px;
  color: #fff;
  background: rgba(5, 41, 84, 0.97);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
}

.result-percent {
  display: grid;
  place-items: center;
  width: 13.8%;
  min-width: 84px;
  aspect-ratio: 1;
  margin-bottom: 3.2%;
  border: 2px solid var(--blue-line);
  border-radius: 50%;
  color: #fff;
  background: rgba(110, 151, 98, 0.55);
  box-shadow: inset 0 0 0 8px rgba(6, 48, 96, 0.35);
  font-size: clamp(24px, calc(var(--stage-size) * 0.036), 40px);
  font-weight: 900;
}

.result-title {
  margin: 0 0 3%;
  font-size: clamp(22px, calc(var(--stage-size) * 0.035), 40px);
  font-weight: 900;
  text-align: center;
}

.result-text {
  max-width: 72%;
  margin: 0 0 3.2%;
  font-size: clamp(16px, calc(var(--stage-size) * 0.024), 28px);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 64%;
  min-height: 75px;
  margin: 0 0 4%;
  overflow: hidden;
  border: 1px solid var(--blue-line);
  border-radius: 8px;
}

.result-stat {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  min-width: 0;
  padding: 12px 8px;
  border-right: 1px solid rgba(35, 169, 230, 0.65);
  background: rgba(4, 48, 88, 0.7);
  text-transform: uppercase;
}

.result-stat:last-child {
  border-right: 0;
}

.result-stat strong {
  color: var(--lime);
  font-size: clamp(18px, calc(var(--stage-size) * 0.028), 30px);
  line-height: 1;
}

.result-stat:nth-child(3) strong {
  color: var(--red);
}

.result-stat:nth-child(4) strong {
  color: #fff;
}

.result-stat span {
  color: #dceaff;
  font-size: clamp(10px, calc(var(--stage-size) * 0.013), 14px);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.result-button {
  min-height: 48px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  color: #073064;
  background: linear-gradient(90deg, #dce31f, #80c76d, #20b6e8);
  cursor: pointer;
  font-size: clamp(15px, calc(var(--stage-size) * 0.02), 22px);
  font-weight: 900;
  text-transform: uppercase;
}

.config-panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 4.5%;
  color: #fff;
  background: rgba(2, 22, 48, 0.72);
}

.config-panel[hidden] {
  display: none;
}

.config-card {
  width: min(86%, 780px);
  padding: 28px;
  border: 2px solid rgba(35, 169, 230, 0.95);
  border-radius: 8px;
  background: rgba(5, 41, 84, 0.98);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
}

.config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.config-header h1 {
  margin: 0;
  font-size: clamp(24px, calc(var(--stage-size) * 0.032), 36px);
  line-height: 1;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.config-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: #dceaff;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
}

.config-field input {
  width: 100%;
  min-height: 45px;
  border: 1px solid rgba(35, 169, 230, 0.65);
  border-radius: 6px;
  color: #fff;
  background: rgba(4, 48, 88, 0.82);
  padding: 10px;
}

.config-action,
.config-save,
.config-secondary {
  min-height: 45px;
  border: 1px solid rgba(35, 169, 230, 0.78);
  border-radius: 6px;
  color: #fff;
  background: rgba(4, 48, 88, 0.82);
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
}

.config-action {
  align-self: end;
}

.config-action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.config-preview {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 22px;
  margin-top: 24px;
}

.config-preview span {
  display: block;
  margin-bottom: 8px;
  color: #dceaff;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.mini-card,
.front-thumb {
  overflow: hidden;
  border: 1px solid var(--blue-line);
  border-radius: 8px;
  background: rgba(4, 48, 88, 0.72);
}

.mini-card {
  width: 96px;
  aspect-ratio: 1;
  background: var(--card-back-image, url("assets/card_verso.png")) center / contain no-repeat;
}

.front-list {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}

.front-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.front-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.config-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.config-save {
  min-width: 130px;
  color: #073064;
  border: 0;
  background: linear-gradient(90deg, #dce31f, #80c76d, #20b6e8);
}

.config-secondary {
  min-width: 170px;
}

@keyframes matched {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.045);
  }
}

@media (max-aspect-ratio: 1 / 1) {
  :root {
    --stage-size: min(100vw, 1008px);
  }
}
