/* REtrO — Common CRT-styled tokens + components */

:root {
  --bg: #000;
  --primary: #00ffff;
  --magenta: #ff00ff;
  --yellow: #ffff00;
  --green: #00ff66;
  --red: #ff3355;
  --gray-1: #1a1a1a;
  --gray-2: #0a0a0a;
  --gray-3: #2a2a2a;
  --txt: var(--primary);

  --r-sm: 2px;
  --r-md: 4px;
  --r-lg: 8px;

  --gap-1: 4px;
  --gap-2: 8px;
  --gap-3: 12px;
  --gap-4: 16px;
  --gap-5: 24px;
  --gap-6: 32px;
  --gap-7: 48px;

  --tap: 48px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--primary);
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  touch-action: manipulation;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
}

/* CRT overlays (injected by lib/ui.js) */
#crt-scan {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.28) 3px,
    rgba(0, 0, 0, 0.28) 4px
  );
  pointer-events: none;
  z-index: 100;
  mix-blend-mode: multiply;
}

#crt-vig {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.7) 100%);
  pointer-events: none;
  z-index: 101;
}

@media (prefers-reduced-motion: reduce) {
  #crt-scan {
    opacity: 0.5;
  }
}

/* Title glow */
.retro-title {
  font-size: clamp(28px, 7vw, 56px);
  color: var(--primary);
  text-shadow: 0 0 12px var(--primary), 0 0 24px var(--primary);
  letter-spacing: 0.15em;
  font-weight: bold;
  line-height: 1;
  text-align: center;
}

.retro-subtitle {
  font-size: clamp(10px, 2.5vw, 14px);
  color: var(--magenta);
  text-shadow: 0 0 8px var(--magenta);
  letter-spacing: 0.4em;
  margin-top: 8px;
  text-align: center;
  animation: retro-blink 1.4s ease-in-out infinite;
}

@keyframes retro-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .retro-subtitle {
    animation: none;
  }
}

/* Credit display (sticky header) */
.retro-credit-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.85);
  border-bottom: 2px solid var(--primary);
  backdrop-filter: blur(2px);
}

.retro-credit-bar .label {
  font-size: 10px;
  color: var(--yellow);
  text-shadow: 0 0 6px var(--yellow);
  letter-spacing: 0.2em;
}

.retro-credit-bar .value {
  font-size: 22px;
  color: var(--primary);
  text-shadow: 0 0 10px var(--primary);
  letter-spacing: 0.1em;
}

.retro-credit-bar .value.empty {
  color: var(--red);
  text-shadow: 0 0 10px var(--red);
  animation: retro-blink 0.8s steps(2) infinite;
}

/* Buttons */
.retro-btn {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.15em;
  padding: 14px 22px;
  min-height: var(--tap);
  min-width: var(--tap);
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.4), inset 0 0 12px rgba(0, 255, 255, 0.08);
  transition: transform 0.08s steps(2), box-shadow 0.08s steps(2);
  text-transform: uppercase;
}

.retro-btn:active {
  transform: scale(0.97);
}

.retro-btn:hover {
  box-shadow: 0 0 16px rgba(0, 255, 255, 0.7), inset 0 0 18px rgba(0, 255, 255, 0.18);
}

.retro-btn.primary {
  border-color: var(--yellow);
  color: var(--yellow);
  box-shadow: 0 0 8px rgba(255, 255, 0, 0.4), inset 0 0 12px rgba(255, 255, 0, 0.08);
}
.retro-btn.primary:hover {
  box-shadow: 0 0 16px rgba(255, 255, 0, 0.7), inset 0 0 18px rgba(255, 255, 0, 0.18);
}

.retro-btn.danger {
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 8px rgba(255, 51, 85, 0.4), inset 0 0 12px rgba(255, 51, 85, 0.08);
}

.retro-btn.secondary {
  border-color: var(--gray-3);
  color: #888;
  box-shadow: none;
}

.retro-btn:disabled,
.retro-btn[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* Card grid (game selection) */
.retro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: clamp(12px, 3vw, 24px);
  padding: 16px;
  max-width: 1000px;
  margin: 0 auto;
}

.retro-card {
  position: relative;
  aspect-ratio: 1 / 1.1;
  background: var(--gray-2);
  border: 3px solid var(--primary);
  border-radius: var(--r-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.35), inset 0 0 18px rgba(0, 255, 255, 0.08);
  transition: transform 0.1s steps(2);
  overflow: hidden;
}

.retro-card:active {
  transform: scale(0.97);
}

.retro-card.magenta {
  border-color: var(--magenta);
  color: var(--magenta);
  box-shadow: 0 0 10px rgba(255, 0, 255, 0.35), inset 0 0 18px rgba(255, 0, 255, 0.08);
}

.retro-card.disabled {
  opacity: 0.35;
  filter: grayscale(1);
  pointer-events: none;
}

.retro-card-year {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 9px;
  color: var(--yellow);
  border: 1px solid var(--yellow);
  padding: 2px 6px;
  border-radius: 2px;
  letter-spacing: 0.1em;
}

.retro-card-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.retro-card-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px currentColor);
}

.retro-card-title {
  font-size: 14px;
  text-shadow: 0 0 8px currentColor;
  letter-spacing: 0.1em;
  text-align: center;
  line-height: 1.2;
}

.retro-card-sub {
  font-size: 9px;
  color: var(--yellow);
  text-shadow: 0 0 6px var(--yellow);
  letter-spacing: 0.2em;
  margin-top: 6px;
  text-align: center;
}

.retro-card-cost {
  margin-top: 10px;
  font-size: 10px;
  color: var(--green);
  text-shadow: 0 0 6px var(--green);
  letter-spacing: 0.15em;
}

.retro-card-soon {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--yellow);
  font-size: 11px;
  letter-spacing: 0.25em;
  text-shadow: 0 0 6px var(--yellow);
  pointer-events: none;
}

/* Modal */
.retro-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.retro-modal {
  background: var(--bg);
  border: 3px solid var(--primary);
  border-radius: var(--r-md);
  padding: 20px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 0 24px rgba(0, 255, 255, 0.5);
}

.retro-modal-title {
  font-size: 16px;
  color: var(--yellow);
  text-shadow: 0 0 8px var(--yellow);
  letter-spacing: 0.15em;
  margin-bottom: 14px;
  text-align: center;
}

.retro-modal-body {
  font-size: 12px;
  line-height: 1.7;
  color: var(--primary);
  text-align: center;
  margin-bottom: 18px;
  font-family: "Noto Sans JP", sans-serif;
  letter-spacing: 0.05em;
}

.retro-modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Toast */
.retro-toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 2px solid var(--yellow);
  color: var(--yellow);
  padding: 12px 18px;
  font-size: 11px;
  letter-spacing: 0.15em;
  border-radius: var(--r-md);
  z-index: 150;
  box-shadow: 0 0 12px rgba(255, 255, 0, 0.5);
  transition: opacity 0.3s;
}

/* Page section */
.retro-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}

.retro-section h1,
.retro-section h2 {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 0 0 8px currentColor;
  margin-bottom: 16px;
}

.retro-section h1 {
  font-size: 22px;
}
.retro-section h2 {
  font-size: 16px;
  color: var(--magenta);
  margin-top: 24px;
}

.retro-section p {
  font-family: "Noto Sans JP", sans-serif;
  font-size: 13px;
  line-height: 1.8;
  margin-bottom: 12px;
  color: #ccc;
  letter-spacing: 0.03em;
}

.retro-section ul,
.retro-section ol {
  font-family: "Noto Sans JP", sans-serif;
  font-size: 13px;
  line-height: 1.8;
  margin-bottom: 12px;
  margin-left: 24px;
  color: #ccc;
}

/* Footer */
.retro-footer {
  text-align: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  font-size: 9px;
  color: #555;
  letter-spacing: 0.2em;
}

.retro-footer a {
  color: var(--primary);
  text-decoration: none;
  margin: 0 6px;
}

.retro-footer a:hover {
  text-decoration: underline;
}

/* Sound toggle (corner) */
.retro-sound-toggle {
  position: fixed;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: 2px solid var(--primary);
  background: rgba(0, 0, 0, 0.7);
  color: var(--primary);
  font-size: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 90;
}

/* Container layouts */
.retro-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.retro-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.retro-hero .insert {
  margin-top: 18px;
  font-size: 11px;
  color: var(--yellow);
  text-shadow: 0 0 6px var(--yellow);
  letter-spacing: 0.3em;
  animation: retro-blink 1s ease-in-out infinite;
}

/* Form */
.retro-input {
  font-family: inherit;
  font-size: 16px; /* iOS Safari 自動ズーム回避（< 16px だとフォーカス時に勝手にズーム） */
  padding: 12px;
  background: var(--gray-2);
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--r-md);
  min-height: var(--tap);
  width: 100%;
  letter-spacing: 0.1em;
}

.retro-input:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
  box-shadow: 0 0 8px var(--primary);
}

.retro-btn:focus-visible,
.retro-card:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.retro-sound-toggle {
  width: var(--tap);
  height: var(--tap);
}

/* Stars background (optional decoration) */
.retro-stars {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: -1;
  overflow: hidden;
}
.retro-stars::before,
.retro-stars::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  box-shadow: 50px 80px #fff, 120px 200px var(--yellow), 200px 50px #fff, 300px 250px var(--magenta), 380px 120px #fff,
    450px 300px var(--primary), 520px 60px #fff, 600px 180px #fff, 680px 280px var(--yellow), 750px 90px var(--primary),
    820px 220px #fff, 900px 30px #fff, 150px 380px #fff, 250px 450px var(--primary), 350px 400px #fff,
    440px 480px var(--yellow), 550px 420px var(--magenta), 650px 460px #fff, 750px 380px #fff, 870px 440px #fff,
    100px 540px var(--primary), 250px 580px #fff, 400px 620px var(--yellow), 570px 590px #fff, 700px 640px var(--magenta),
    850px 560px #fff;
  animation: retro-twinkle 3s ease-in-out infinite;
}
.retro-stars::after {
  animation-delay: 1.5s;
  transform: translate(60px, 30px);
}
@keyframes retro-twinkle {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .retro-stars::before,
  .retro-stars::after {
    animation: none;
  }
}
