/* APM CSS STYLE */

:root {
  --preview-cell-bg: rgba(255, 255, 255, 0.05);
  --preview-cell-border: rgba(255, 255, 255, 0.1);
  --arena-bg: var(--color-surface, rgba(0, 0, 0, 0.2));
  --arena-border: var(--card-border, var(--color-outline, rgba(255, 255, 255, 0.08)));
  --overlay-bg: rgba(10, 15, 25, 0.85);
  --cursor-color: white;
  --cell-bg: var(--color-surface-variant, rgba(255, 255, 255, 0.04));
  --cell-border: var(--color-outline, rgba(255, 255, 255, 0.1));
  --cell-hover-bg: rgba(255, 255, 255, 0.06);
  --cell-hover-border: rgba(255, 255, 255, 0.12);
  --key-bg: var(--color-surface-variant, rgba(255, 255, 255, 0.03));
  --key-border: var(--color-outline, rgba(255, 255, 255, 0.08));
  --key-shadow: var(--color-outline);
}

html.light {
  --preview-cell-bg: rgba(15, 23, 42, 0.05);
  --preview-cell-border: rgba(15, 23, 42, 0.15);
  --arena-bg: rgba(15, 23, 42, 0.02);
  --arena-border: rgba(15, 23, 42, 0.08);
  --overlay-bg: rgba(255, 255, 255, 0.93);
  --cursor-color: #0f172a;
  --cell-bg: rgba(15, 23, 42, 0.04);
  --cell-border: rgba(15, 23, 42, 0.08);
  --cell-hover-bg: rgba(15, 23, 42, 0.08);
  --cell-hover-border: rgba(15, 23, 42, 0.15);
  --key-bg: rgba(15, 23, 42, 0.03);
  --key-border: rgba(15, 23, 42, 0.08);
  --key-shadow: rgba(15, 23, 42, 0.1);
}

/* Config Card on Intro */
.apm-config-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px auto 24px;
  background: var(--color-surface-dim, rgba(255, 255, 255, 0.02));
  border: 1px solid var(--card-border, var(--color-outline, rgba(255, 255, 255, 0.08)));
  border-radius: 16px;
  padding: 16px;
  max-width: 380px;
  width: 100%;
  box-sizing: border-box;
}

.apm-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.apm-config-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-h, sans-serif);
}

.apm-config-tabs {
  display: flex;
  gap: 4px;
  background: var(--color-surface, rgba(0, 0, 0, 0.2));
  border: 1px solid var(--color-outline, rgba(255, 255, 255, 0.08));
  border-radius: 10px;
  padding: 3px;
}

.apm-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-b, sans-serif);
}

.apm-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.apm-tab.active {
  color: var(--color-on-primary, #ffffff);
  background: var(--color-primary, #10b981);
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.2);
}

/* Gameplay HUD */
.apm-game-hud {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 24px;
  margin-bottom: 12px;
  max-width: 960px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.apm-hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.apm-hud-val {
  font-family: var(--font-h, sans-serif);
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.apm-hud-val.text-green {
  color: #10b981;
}

.apm-hud-lbl {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* Play Arena */
.apm-arena {
  position: relative;
  width: 100% !important;
  min-height: 480px;
  margin: 20px 0 !important;
  background: var(--arena-bg);
  border-top: 1.5px solid var(--arena-border) !important;
  border-bottom: 1.5px solid var(--arena-border) !important;
  border-left: none !important;
  border-right: none !important;
  border-radius: 0 !important;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apm-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.apm-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.apm-overlay-inner {
  text-align: center;
  animation: pulse 2s infinite ease-in-out;
}

/* Grid Layouts */
.apm-grid-layout {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 10px;
  width: 90%;
  height: 90%;
  max-width: 380px;
  max-height: 380px;
  box-sizing: border-box;
}

.apm-grid-layout.mode-3x3 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.apm-grid-layout.mode-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.apm-grid-layout.mode-5x5 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
}

.apm-grid-layout.mode-6x6 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 8px !important;
}

.apm-grid-layout.mode-6x6 .apm-cell {
  border-radius: 6px;
  border-width: 1.5px;
}

/* Cell */
.apm-cell {
  background: var(--cell-bg);
  border: 2px solid var(--cell-border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.12s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
}

.apm-cell:hover {
  background: var(--cell-hover-bg);
  border-color: var(--cell-hover-border);
}

.apm-cell.active {
  background: #10b981;
  border-color: #34d399;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.apm-cell.hit-active {
  animation: apm-flash-green 0.2s ease-out;
}

.apm-cell.miss-active {
  animation: apm-flash-red 0.2s ease-out;
}

/* Keyboard layout */
.apm-keyboard-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 90%;
  height: 90%;
  max-width: 380px;
  max-height: 380px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.apm-keyboard-row {
  display: flex;
  gap: 10px;
}

.apm-key {
  width: 68px;
  height: 68px;
  background: var(--key-bg);
  border: 2px solid var(--key-border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-h, sans-serif);
  font-size: 18px;
  font-weight: 800;
  color: var(--text-muted);
  transition: all 0.1s ease;
  user-select: none;
  box-shadow: 0 3px 0 var(--key-shadow);
  cursor: pointer;
}

.apm-key .key-lbl {
  transform: translateY(0);
}

.apm-key.active {
  background: rgba(16, 185, 129, 0.1);
  border-color: #10b981;
  color: #10b981;
  box-shadow: 0 3px 0 #047857, 0 0 16px rgba(16, 185, 129, 0.2);
}

.apm-key.pressed {
  transform: translateY(3px);
  box-shadow: 0 0 0 transparent;
}

.apm-key.pressed.correct {
  background: #10b981;
  border-color: #34d399;
  color: white;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.apm-key.pressed.wrong {
  background: #ef4444;
  border-color: #f87171;
  color: white;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

.apm-keyboard-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  font-weight: 500;
  text-align: center;
}

/* Animations */
@keyframes apm-flash-green {
  0% { background: #10b981; box-shadow: 0 0 30px rgba(16, 185, 129, 0.7); }
  100% { background: var(--color-surface-variant); }
}

@keyframes apm-flash-red {
  0% { background: #ef4444; box-shadow: 0 0 30px rgba(239, 68, 68, 0.7); }
  100% { background: var(--color-surface-variant); }
}

/* Preview Arena in Intro */
.apm-preview-arena {
  width: 140px;
  height: 140px;
  margin: 20px auto 10px;
  border: 1px dashed var(--arena-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.apm-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  width: 80px;
  height: 80px;
}

.apm-preview-cell {
  background: var(--preview-cell-bg);
  border: 1px solid var(--preview-cell-border);
  border-radius: 6px;
  cursor: pointer;
}

.apm-preview-cell.active {
  background: #10b981;
  border-color: #34d399;
}

/* Click cursor preview block */
.apm-preview-click {
  position: absolute;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transform-origin: 35% 15%;
  animation: apm-preview-loop 5.0s linear infinite;
}

.apm-preview-click span {
  font-size: 20px;
  line-height: 1;
  display: block;
  color: var(--cursor-color);
  transform: translate(-35%, -15%) scale(1.0);
}

/* Animate cells green active highlights in preview sequence */
.apm-preview-cell:nth-child(2) {
  animation: apm-preview-cell-1 5.0s infinite ease-in-out;
}
.apm-preview-cell:nth-child(1) {
  animation: apm-preview-cell-0 5.0s infinite ease-in-out;
}

@keyframes apm-preview-cell-1 {
  0%, 28% {
    background: #10b981;
    border-color: #34d399;
  }
  28.1%, 100% {
    background: var(--preview-cell-bg);
    border-color: var(--preview-cell-border);
  }
}
@keyframes apm-preview-cell-0 {
  0%, 49.9% {
    background: var(--preview-cell-bg);
    border-color: var(--preview-cell-border);
  }
  50%, 78% {
    background: #10b981;
    border-color: #34d399;
  }
  78.1%, 100% {
    background: var(--preview-cell-bg);
    border-color: var(--preview-cell-border);
  }
}

@keyframes apm-preview-loop {
  0%, 100% { left: 20px; top: 20px; }
  15% { left: 92px; top: 48px; } /* Hover active Cell 1 */
  22% { left: 92px; top: 48px; transform: scale(0.85); } /* Click Cell 1 */
  28% { left: 92px; top: 48px; transform: scale(1.0); }
  50% { left: 48px; top: 92px; } /* Hover Cell 2 */
  65% { left: 48px; top: 48px; } /* Hover active Cell 0 */
  72% { left: 48px; top: 48px; transform: scale(0.85); } /* Click Cell 0 */
  78% { left: 48px; top: 48px; transform: scale(1.0); }
}

.apm-preview-caption {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 24px;
}

@media (max-width: 640px) {
  .apm-config-card {
    padding: 12px;
  }
  .apm-key {
    width: 58px;
    height: 58px;
    font-size: 16px;
    border-radius: 12px;
  }
}
