.insane-memory-shell {
  width: min(1240px, 94vw);
}

.insane-memory-panel {
  position: relative;
  z-index: 10;
  padding: 1rem;
}

.insane-memory-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 1rem;
}

.insane-memory-top-left {
  justify-self: start;
}

.insane-memory-top-right {
  justify-self: end;
  transform: none;
}

.insane-memory-score-center {
  justify-self: center;
}

.insane-memory-panel[data-game-type="versus"] .insane-memory-score-center {
  display: none !important;
}

.insane-memory-controls,
.insane-memory-top-left,
.insane-memory-top-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.insane-memory-floating-tools {
  position: fixed;
  top: clamp(18px, 4.5vh, 44px);
  right: clamp(18px, 4vw, 56px);
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.insane-memory-floating-tools .warmup-settings-icon-btn {
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(1.5px);
}

.insane-memory-start-cue {
  margin: 0;
  font-size: 0.84rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  white-space: nowrap;
}

.insane-memory-start-cue-board {
  margin-top: 0.55rem;
  text-align: center;
  white-space: normal;
}

.insane-memory-score {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  min-width: 120px;
  text-align: center;
}

.insane-memory-score-label {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.insane-memory-score-time {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.memory-versus-hud {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.3rem 0 0.6rem;
}

.insane-memory-panel[data-game-type]:not([data-game-type="versus"]) .memory-versus-hud {
  display: none !important;
}

.memory-versus-box {
  position: relative;
  min-width: 150px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  padding: 0.42rem 0.62rem 0.5rem;
  text-align: center;
  transition: box-shadow 180ms ease, border-color 180ms ease;
}

.memory-versus-player-name {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.memory-versus-player-score {
  margin: 0.1rem 0 0;
  font-size: 1.32rem;
  font-weight: 700;
}

.memory-versus-box.is-turn {
  border-color: #0d8f6d;
  box-shadow: 0 0 0 2px rgba(13, 143, 109, 0.25);
  animation: versusGlow 960ms ease-in-out infinite;
}

.memory-versus-box.is-arrow::after {
  position: absolute;
  top: 50%;
  font-size: clamp(1.5rem, 2.8vw, 2.4rem);
  line-height: 1;
  color: #1e64d8;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transform: translateY(-50%);
}

#memoryVersusBox1.is-arrow::after {
  content: "⬅";
  right: -2.1rem;
}

#memoryVersusBox2.is-arrow::after {
  content: "⬅";
  left: -2.1rem;
  transform: translateY(-50%) scaleX(-1);
}


@keyframes versusGlow {
  0% {
    box-shadow: 0 0 0 2px rgba(13, 143, 109, 0.2), 0 0 0 rgba(13, 143, 109, 0.0);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(13, 143, 109, 0.45), 0 0 16px rgba(13, 143, 109, 0.35);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(13, 143, 109, 0.2), 0 0 0 rgba(13, 143, 109, 0.0);
  }
}

.insane-memory-stage {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 0.9rem;
}

.insane-memory-board {
  --cols: 4;
  --rows: 4;
  --board-gap: 0.45rem;
  --board-pad: 0.6rem;
  --card-size: 96px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card-size));
  grid-auto-rows: var(--card-size);
  justify-content: center;
  gap: var(--board-gap);
  align-content: start;
  background: linear-gradient(180deg, #fff, #f7f2eb);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: var(--board-pad);
  min-height: 260px;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-anchor: none;
  overscroll-behavior: contain;
}

.memory-card {
  position: relative;
  border: 0;
  background: transparent;
  padding: 0;
  perspective: 900px;
  cursor: pointer;
  width: var(--card-size);
  height: var(--card-size);
}

.memory-card[disabled] {
  cursor: default;
}

.memory-card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 260ms ease;
  will-change: transform;
}

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

.memory-card-face {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  border: 1px solid #cfc1af;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.insane-memory-board.dense {
  --board-gap: 0.2rem;
  --board-pad: 0.35rem;
}

.memory-card-back {
  display: grid;
  place-items: center;
  background: linear-gradient(165deg, #23473e, #0e2f27);
  color: #d2f2eb;
  font-size: clamp(1rem, 3vw, 1.4rem);
  font-weight: 700;
}

.memory-card-front {
  transform: rotateY(180deg);
  background: #fff;
  overflow: hidden;
}

.memory-card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.memory-card.is-matched {
  visibility: hidden;
}

.insane-memory-matched-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.55rem;
  background: linear-gradient(180deg, #f4f9f6, #edf6f2);
}

body.insane-memory-freed-world .insane-memory-matched-wrap {
  display: none;
}

body.insane-memory-freed-world .insane-memory-stage {
  grid-template-columns: 1fr;
}

body.insane-memory-freed-world:not(.insane-memory-freed-complete) .insane-memory-top-left {
  visibility: hidden;
  pointer-events: none;
}

body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-board,
body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-score-center,
body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-top-right {
  display: none;
}

body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-top {
  grid-template-columns: 1fr;
}

body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-top-left {
  visibility: visible;
  pointer-events: auto;
  justify-self: center;
}

body.insane-memory-freed-world.insane-memory-freed-complete .insane-memory-panel {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

.insane-memory-matched-wrap h2 {
  margin: 0.15rem 0 0.55rem;
  font-size: 1rem;
}

.insane-memory-matched-field {
  position: relative;
  border: 1px dashed #b8ccbf;
  border-radius: 10px;
  min-height: 220px;
  height: clamp(220px, 46dvh, 560px);
  max-height: 56dvh;
  background: #fbfffc;
  overflow: hidden;
}

.memory-matched-chip {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 0;
  overflow: hidden;
  border: 0;
  box-shadow: none;
  background: transparent;
  animation: chipPop 220ms ease;
}

.memory-matched-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.memory-fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.memory-freed-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.memory-matched-chip.memory-matched-chip-freed {
  position: fixed;
  animation: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.memory-matched-chip.memory-matched-chip-freed img {
  transform-origin: center center;
}

.memory-matched-chip.memory-matched-chip-freed.is-facing-right img {
  transform: scaleX(-1);
}

.memory-matched-chip.memory-matched-chip-freed.is-moving {
  animation: freedWiggle 260ms ease-in-out infinite alternate;
}

.memory-fly-card {
  position: fixed;
  margin: 0;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid #cfc1af;
  box-shadow: 0 10px 24px rgba(13, 44, 35, 0.28);
  transform-origin: center;
  will-change: transform, opacity;
}

.memory-fly-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.memory-finish-burst {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 60;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(2rem, 9vw, 5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #0f5a49;
  -webkit-text-stroke: 1.3px #000;
  text-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  will-change: transform, opacity;
}

.memory-freed-final-score {
  position: fixed;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  z-index: 8;
  margin: 0;
  pointer-events: none;
  color: #0f5a49;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.2rem, 3.2vw, 2.1rem);
  font-weight: 700;
  text-shadow: 0 6px 12px rgba(255, 255, 255, 0.65);
}

.memory-freed-high-scores {
  position: fixed;
  left: 50%;
  top: 66%;
  transform: translate(-50%, -50%);
  z-index: 8;
  width: fit-content;
  max-width: min(92vw, 720px);
  margin: 0;
  padding: 0.45rem 0.7rem 0.5rem;
  border: 1px solid rgba(15, 90, 73, 0.45);
  border-radius: 12px;
  background: transparent;
  pointer-events: none;
  color: #0f5a49;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(0.9rem, 2.2vw, 1.2rem);
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  text-shadow: 0 6px 12px rgba(255, 255, 255, 0.62);
}

.memory-freed-high-scores.memory-freed-high-scores--final {
  top: 52%;
}

.memory-freed-high-scores-title {
  margin: 0;
  font-weight: 700;
}

.memory-freed-high-scores-subtitle {
  margin: 0.05rem 0 0.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(15, 90, 73, 0.35);
}

.memory-freed-high-scores-list {
  margin: 0;
  padding: 0;
}

.memory-freed-high-scores-row {
  margin: 0.1rem 0;
  display: grid;
  grid-template-columns: 2ch 4ch minmax(6ch, auto) 1fr;
  column-gap: 0.45rem;
  align-items: baseline;
  text-align: left;
}

.memory-freed-high-scores-row.memory-versus-result-row {
  grid-template-columns: 2ch minmax(12ch, 1fr) minmax(4ch, auto);
}

.memory-versus-name {
  text-align: left;
}

.memory-versus-score {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.memory-score-rank,
.memory-score-initials,
.memory-score-value {
  font-variant-numeric: tabular-nums;
}

.memory-score-date {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.memory-help-modal {
  max-width: 620px;
}

.memory-highscores-modal {
  width: min(760px, 94vw);
  max-height: min(84vh, 860px);
}

.memory-highscores-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 220px);
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.memory-highscores-list {
  max-height: min(60vh, 560px);
  overflow-y: auto;
  padding-right: 0.2rem;
}

.memory-highscores-group {
  margin: 0 0 0.65rem;
  padding: 0.5rem 0.6rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #f9f6f0);
}

.memory-highscores-group:last-child {
  margin-bottom: 0;
}

.memory-highscores-group h3 {
  margin: 0 0 0.34rem;
  font-size: 0.96rem;
}

.memory-highscores-row {
  margin: 0.08rem 0;
  display: grid;
  grid-template-columns: 2ch 4ch minmax(6ch, auto) 1fr;
  column-gap: 0.45rem;
  align-items: baseline;
  text-align: left;
  font-size: 0.94rem;
}

.memory-highscores-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.memory-help-section {
  padding: 0.7rem 0.75rem 0.82rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f8f4ee);
  margin-bottom: 0.75rem;
}

.memory-help-section:last-child {
  margin-bottom: 0;
}

.memory-help-section h3 {
  margin: 0 0 0.42rem;
  font-size: 1.02rem;
}

.memory-help-heading-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  margin-right: 0.2rem;
}

.memory-help-section ol {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text);
}

.memory-help-section li {
  margin: 0.26rem 0;
  line-height: 1.35;
}

.memory-help-section p {
  margin: 0;
  color: var(--text);
}

.memory-help-icon-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.42rem;
  height: 1.42rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  margin-right: 0.3rem;
}

@keyframes chipPop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes freedWiggle {
  from {
    transform: rotate(-1.65deg) translateY(0);
  }
  to {
    transform: rotate(1.65deg) translateY(-1.5px);
  }
}

@media (max-width: 920px) {
  .insane-memory-top {
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
  }

  .insane-memory-stage {
    grid-template-columns: 1fr;
  }

  .insane-memory-matched-field {
    min-height: 180px;
    height: clamp(180px, 38dvh, 420px);
    max-height: 46dvh;
  }

  .insane-memory-board {
    --board-gap: 0.25rem;
    --board-pad: 0.42rem;
  }

  .insane-memory-board.dense {
    --board-gap: 0.1rem;
    --board-pad: 0.22rem;
  }

  .insane-memory-board.dense .memory-card-face {
    border-width: 0.5px;
    border-radius: 8px;
  }
}
