/* SPACE_INVADER Retro Arcade Stylesheet
   Version: 0.5 */

@import url('https://fonts.googleapis.com/css2?family=Amaranth:ital,wght@0,400;0,700;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  /* Internal version checking variable */
  --css-version: "0.5";

  color-scheme: light;
  --cycler-gradient-start: rgba(40, 186, 222, 0.85);
  --cycler-gradient-mid-a: #5ec7e6;
  --cycler-gradient-mid-b: #c989b8;
  --cycler-gradient-end: rgba(180, 100, 160, 0.7);
  --cycler-grid-bg-color: #28bade;
  --medium-paper-texture: url('../_images/blue_m.png');
  --panel-bg-image: var(--medium-paper-texture);
  --cycler-button-bg: #5ccbf3;
  --cycler-button-bg-hover: #4aaecf;
  --cycler-button-text: #000000;
  --cycler-button-glow: rgba(180, 100, 160, 0.6);
  --cycler-border: #555;
  --cycler-shadow: rgba(0, 0, 0, 0.4);
  --cycler-hover: #c72a93;
  --accent-text: #7a145a;
  --required-color: #55073c;
  --cycler-glass-bg: rgba(255, 255, 255, 0.25);
  --cycler-glass-border: rgba(255, 255, 255, 0.33);
  --cycler-header-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
  
  --panel-text: #171717;
  --panel-muted: #21333b;
  --strong-text: #111111;
  --heading-text: #222222;
  --heading-copy: rgba(20, 20, 20, 0.78);
  --panel-soft: rgba(255, 255, 255, 0.35);
  --panel-softer: rgba(255, 255, 255, 0.2);
  --field-bg: rgba(255, 255, 255, 0.58);
  --field-text: #111111;
}

/* Explicit dark theme */
html[data-theme="dark"] {
  color-scheme: dark;
  --cycler-gradient-start: rgba(6, 64, 83, 0.96);
  --cycler-gradient-mid-a: #124f63;
  --cycler-gradient-mid-b: #543452;
  --cycler-gradient-end: rgba(58, 24, 61, 0.92);
  --cycler-grid-bg-color: #0f6178;
  --panel-bg-image: linear-gradient(rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.42)), var(--medium-paper-texture);
  --cycler-button-bg: #2b8ead;
  --cycler-button-bg-hover: #24758f;
  --cycler-button-text: #f4fbff;
  --cycler-button-glow: rgba(199, 42, 147, 0.35);
  --cycler-border: #173846;
  --cycler-glass-bg: rgba(4, 26, 35, 0.55);
  --cycler-glass-border: rgba(182, 226, 238, 0.22);
  --panel-text: #eef9fb;
  --panel-muted: #c6dce3;
  --strong-text: #ffffff;
  --heading-text: #f4fbff;
  --heading-copy: rgba(230, 246, 250, 0.82);
  --panel-soft: rgba(2, 18, 25, 0.66);
  --panel-softer: rgba(0, 0, 0, 0.22);
  --field-bg: rgba(2, 17, 24, 0.82);
  --field-text: #f4fbff;
  --accent-text: #ff9add;
  --required-color: var(--accent-text);
}

/* System dark theme sync */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
    --cycler-gradient-start: rgba(6, 64, 83, 0.96);
    --cycler-gradient-mid-a: #124f63;
    --cycler-gradient-mid-b: #543452;
    --cycler-gradient-end: rgba(58, 24, 61, 0.92);
    --cycler-grid-bg-color: #0f6178;
    --panel-bg-image: linear-gradient(rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.42)), var(--medium-paper-texture);
    --cycler-button-bg: #2b8ead;
    --cycler-button-bg-hover: #24758f;
    --cycler-button-text: #f4fbff;
    --cycler-button-glow: rgba(199, 42, 147, 0.35);
    --cycler-border: #173846;
    --cycler-glass-bg: rgba(4, 26, 35, 0.55);
    --cycler-glass-border: rgba(182, 226, 238, 0.22);
    --panel-text: #eef9fb;
    --panel-muted: #c6dce3;
    --strong-text: #ffffff;
    --heading-text: #f4fbff;
    --heading-copy: rgba(230, 246, 250, 0.82);
    --panel-soft: rgba(2, 18, 25, 0.66);
    --panel-softer: rgba(0, 0, 0, 0.22);
    --field-bg: rgba(2, 17, 24, 0.82);
    --field-text: #f4fbff;
    --accent-text: #ff9add;
    --required-color: var(--accent-text);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: linear-gradient(
    -45deg,
    var(--cycler-gradient-start),
    var(--cycler-gradient-mid-a),
    var(--cycler-gradient-mid-b),
    var(--cycler-gradient-end)
  );
  background-size: 320% 320%;
  background-attachment: fixed;
  background-color: #313131;
  animation: cycler-gradient 40s ease-in-out infinite;
  color: var(--panel-text);
  font-family: 'Amaranth', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: clamp(16px, 0.3vw + 15px, 18px);
  line-height: 1.6;
  padding: 0 0 2rem;
}

@keyframes cycler-gradient {
  0% { background-position: 18% 50%; }
  50% { background-position: 82% 50%; }
  100% { background-position: 18% 50%; }
}

header {
  width: 95%;
  max-width: 55rem;
  margin: 0.5em auto 0.8em;
  padding: 0.5em 0.7em 0.65em;
  text-align: center;
  background: var(--cycler-glass-bg);
  border: 1px solid var(--cycler-glass-border);
  border-radius: 20px;
  box-shadow: var(--cycler-header-shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

header h1 {
  color: var(--heading-text);
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  font-variant: small-caps;
  font-weight: 700;
  line-height: 1.12;
}

header p {
  max-width: 75ch;
  margin: 0.35em auto 0;
  color: var(--heading-copy);
  font-size: clamp(0.9rem, 1vw + 0.7rem, 1.1rem);
  line-height: 1.35;
}

.container {
  width: 95%;
  max-width: 55rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

/* Glass-style container layout panels */
.panel {
  background-color: var(--cycler-grid-bg-color);
  background-image: var(--panel-bg-image);
  border: 1px solid var(--cycler-border);
  border-radius: 20px;
  box-shadow: 1px 1px 4px 0 var(--cycler-shadow);
  padding: 0.9em;
}

/* ============================================================================
   SETTINGS PANEL
   ============================================================================ */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.125rem, 1fr));
  gap: 0.7em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
}

.field label {
  color: var(--panel-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.field select {
  height: 2.6rem;
  color: var(--field-text);
  background: var(--field-bg);
  border: 1px solid var(--cycler-border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35em 0.55em;
  cursor: pointer;
  width: 100%;
}

.field select:focus {
  outline: none;
  border-color: var(--cycler-hover);
  box-shadow: 0 0 0 3px rgba(199, 42, 147, 0.22);
}

/* ============================================================================
   ARCADE CABINET CONTAINER
   ============================================================================ */

.arcade-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.2em 0.9em 0.9em;
}

.screen-container {
  width: 100%;
  max-width: 42rem;
  aspect-ratio: 7 / 8;
  margin: 0 auto 0.6em;
  background-color: #000;
  border: 4px double var(--cycler-border);
  border-radius: 8px;
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.8),
    0 0 20px var(--cycler-button-glow),
    inset 0 0 20px rgba(0, 255, 0, 0.1);
  overflow: hidden;
  position: relative;
}

@media (min-width: 46.875rem) {
  .screen-container {
    width: 42rem;
    height: 48rem;
  }
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

canvas:focus-visible {
  outline: none;
}

.screen-container:has(canvas:focus-visible) {
  border-color: var(--cycler-hover);
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.8),
    0 0 25px var(--cycler-hover),
    inset 0 0 20px rgba(0, 255, 0, 0.1);
}

/* ============================================================================
   ACTIONS PANEL
   ============================================================================ */

.actions {
  display: flex;
  justify-content: center;
  gap: 0.8em;
  width: 100%;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.4em 1.2em;
  color: var(--cycler-button-text);
  background-color: var(--cycler-button-bg);
  background-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.4) 0%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(0, 0, 0, 0.05) 51%,
    rgba(0, 0, 0, 0.1) 100%
  );
  border: 1px solid var(--cycler-border);
  border-radius: 8px;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.6),
    inset -1px -1px 0 rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.2),
    0 0 12px var(--cycler-button-glow);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
  transition: background-color 0.15s ease-out,
              box-shadow 0.15s ease-out,
              transform 0.15s ease-out;
}

button:hover {
  background-color: var(--cycler-button-bg-hover);
  background-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.5) 0%,
    rgba(255, 255, 255, 0.1) 100%
  );
  transform: translateY(1.5px);
  box-shadow:
    inset 2px 2px 6px rgba(0, 0, 0, 0.2),
    inset -1px -1px 4px rgba(255, 255, 255, 0.1),
    0 0 15px var(--cycler-button-glow);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  transform: none;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.35),
    inset -1px -1px 0 rgba(0, 0, 0, 0.08);
}

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

button.primary {
  background-color: var(--cycler-hover);
  color: #ffffff;
  border-color: var(--cycler-hover);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 14px rgba(199, 42, 147, 0.5);
  background-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.2) 0%,
    rgba(255, 255, 255, 0.02) 50%,
    rgba(0, 0, 0, 0.05) 51%,
    rgba(0, 0, 0, 0.15) 100%
  );
}

button.primary:hover {
  background-color: #b01b80;
  box-shadow: 0 0 18px rgba(199, 42, 147, 0.7);
}

/* ============================================================================
   CACHE WARNING BANNER
   ============================================================================ */

.cache-warning {
  display: none;
  background: var(--danger, #a51535);
  color: #fff;
  border-radius: 8px;
  padding: 0.5em 0.8em;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.8em;
  text-align: center;
}

.cache-warning.visible {
  display: block;
}

/* ============================================================================
   FOOTER
   ============================================================================ */

footer {
  text-align: center;
  margin-top: 1.8em;
  padding: 1em;
  color: var(--footer-text, rgba(255, 255, 255, 0.7));
  font-size: 0.82em;
}

/* ============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================ */

@media (max-width: 30rem) {
  body {
    padding-bottom: 1rem;
  }
  
  header {
    width: 95%;
  }

  .container {
    width: 95%;
    gap: 0.7em;
  }

  .panel {
    padding: 0.7em;
  }

  .screen-container {
    border-width: 0.125rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body {
    animation: none;
    background-position: 0% 50%;
  }
}
