/* Memory Grid - Visual Working Memory Training Game */
/* Version 1.0.0 */

:root {
  --bg: #0b1424;
  --surface: rgba(15, 25, 45, 0.95);
  --ink: #ffffff;
  --muted: #d1d5db;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.2);
  --tile: rgba(30, 45, 70, 0.9);
  --tile-border: rgba(120, 140, 170, 0.5);
  --tile-lit: #60a5fa;
  --tile-correct: #4ade80;
  --tile-wrong: #f87171;
  --tile-missed: #fbbf24;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --tile-size: 64px;
}

body.high-contrast {
  --bg: #000000;
  --surface: #000000;
  --ink: #ffffff;
  --muted: #ffffff;
  --accent: #ffffff;
  --accent-soft: #000000;
  --tile: #000000;
  --tile-border: #ffffff;
  --tile-lit: #ffffff;
  --tile-correct: #ffffff;
  --tile-wrong: #ffffff;
  --tile-missed: #ffffff;
  --shadow: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: #0b1424;
  min-height: 100vh;
  position: relative;
  touch-action: manipulation;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('../brain.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

body.high-contrast {
  background: #000000;
}

body.high-contrast::before {
  opacity: 0.08;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: #ffffff;
  padding: 8px 16px;
  z-index: 100;
  text-decoration: none;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  position: relative;
  z-index: 1;
}

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

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand span {
  font-size: 12px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: #93c5fd;
}

.brand h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0.08em;
}

.quit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.1);
  color: #d1d5db;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.quit-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffffff;
}

.quit-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.quit-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

body.reduced-motion .quit-btn {
  transition: none;
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  background: var(--surface);
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-card span {
  font-size: 12px;
  color: #9ca3af;
}

.status-card strong {
  font-size: 18px;
  color: #ffffff;
}

main {
  margin-top: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.grid-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  min-height: 560px;
  position: relative;
}

.prompt {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ffffff;
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 10px;
  align-content: center;
  justify-content: center;
  width: 100%;
  padding: 16px 0;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 12px;
  border: 1px solid var(--tile-border);
  background: var(--tile);
  cursor: pointer;
  box-shadow: inset 0 0 0 rgba(0, 0, 0, 0);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.tile:focus {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.tile:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

body.reduced-motion .tile {
  transition: none;
}

.tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(75, 123, 159, 0.2);
  transform: scale(1.03);
}

.tile.lit {
  background: var(--tile-lit);
  box-shadow: 0 0 12px rgba(126, 177, 199, 0.8);
  animation: glow 0.9s ease-in-out infinite alternate;
}

.tile.correct {
  background: var(--tile-correct);
  box-shadow: 0 0 16px rgba(76, 175, 80, 0.7);
}

.tile.wrong {
  background: var(--tile-wrong);
  box-shadow: 0 0 16px rgba(217, 92, 92, 0.7);
}

.tile.missed {
  background: var(--tile-missed);
  box-shadow: 0 0 16px rgba(212, 166, 77, 0.7);
}

body.color-blind .tile::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 2px dashed transparent;
  opacity: 0;
}

body.color-blind .tile.lit::after,
body.color-blind .tile.correct::after,
body.color-blind .tile.missed::after,
body.color-blind .tile.selected::after {
  opacity: 1;
  border-color: currentColor;
}

body.color-blind .tile.lit::after {
  border-style: solid;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  font-family: inherit;
  font-size: inherit;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  min-width: 140px;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

button.primary:hover:not(:disabled) {
  background: #3b82f6;
}

button.primary:active:not(:disabled) {
  transform: scale(0.98);
}

button.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

button.secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffffff;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.mode-select {
  display: grid;
  gap: 10px;
}

.mode-select button {
  text-align: left;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--accent-soft);
  color: #e5e7eb;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.mode-select button strong {
  color: #60a5fa;
}

.mode-select button:hover {
  background: rgba(96, 165, 250, 0.25);
  border-color: var(--tile-border);
}

.mode-select button.active {
  border-color: var(--accent);
  background: rgba(96, 165, 250, 0.3);
  color: #ffffff;
}

.mode-select button.active strong {
  color: #93c5fd;
}

.panel h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #ffffff;
  font-weight: 600;
}

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting:last-child {
  border-bottom: none;
}

.setting label {
  cursor: pointer;
  color: #e5e7eb;
  font-size: 14px;
}

.stats-list {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: #e5e7eb;
}

.stats-list strong {
  color: #ffffff;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 36, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--ink);
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.high-contrast .overlay {
  background: rgba(0, 0, 0, 0.86);
}

.overlay.show {
  opacity: 1;
  pointer-events: all;
}

.footer-tabs {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.footer-tabs button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #d1d5db;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.footer-tabs button:hover {
  background: var(--accent-soft);
  color: #ffffff;
}

.footer-tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffffff;
}

.tab-content {
  margin-top: 14px;
  font-size: 14px;
  color: #e5e7eb;
  line-height: 1.6;
}

/* Visually hidden but accessible */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes glow {
  from {
    box-shadow: 0 0 6px rgba(126, 177, 199, 0.5);
  }
  to {
    box-shadow: 0 0 16px rgba(126, 177, 199, 0.9);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive */
@media (max-width: 980px) {
  main {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  :root {
    --tile-size: 56px;
  }

  body.large-tiles {
    --tile-size: 68px;
  }

  .status-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand h1 {
    font-size: 24px;
  }

  .app {
    padding: 16px 12px 32px;
  }
}

@media (max-width: 400px) {
  :root {
    --tile-size: 48px;
  }

  body.large-tiles {
    --tile-size: 60px;
  }
}

/* Print styles */
@media print {
  .app {
    background: white;
  }

  .controls,
  .mode-select,
  .footer-tabs {
    display: none;
  }
}
