/* ============================================================
   Design System — ゲームライブラリ
   ============================================================ */

:root {
  /* Colors */
  --color-bg:             #f8f6f2;
  --color-surface:        #ffffff;
  --color-surface-glass:  rgba(255, 255, 255, 0.68);
  --color-border-glass:   rgba(255, 255, 255, 0.45);
  --color-accent-sakura:  #f4a7b9;
  --color-accent-sakura-dark: #e8829a;
  --color-accent-sky:     #87c5ea;
  --color-accent-sky-dark: #5daad5;
  --color-accent-mint:    #a8d8b9;
  --color-text-primary:   #2d2d2d;
  --color-text-secondary: #6b6b6b;
  --color-text-muted:     #9e9e9e;
  --color-shadow-soft:    rgba(0, 0, 0, 0.07);
  --color-shadow-medium:  rgba(0, 0, 0, 0.13);
  --color-border-subtle:  rgba(0, 0, 0, 0.06);

  /* Typography */
  --font-ja: "Hiragino Kaku Gothic ProN", "Hiragino Sans",
             "Yu Gothic Medium", "Yu Gothic", "Meiryo",
             "Noto Sans JP", sans-serif;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.125rem;
  --font-size-xl:   1.375rem;
  --font-size-2xl:  1.75rem;
  --font-size-3xl:  2.25rem;
  --line-height-tight:  1.3;
  --line-height-normal: 1.65;

  /* Spacing (4px base) */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radii */
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --radius-xl:   28px;
  --radius-pill: 999px;

  /* Shadows — three-layer depth */
  --shadow-card-rest:
    0 1px 2px var(--color-shadow-soft),
    0 4px 12px var(--color-shadow-soft),
    0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-card-hover:
    0 2px 4px var(--color-shadow-soft),
    0 8px 24px var(--color-shadow-medium),
    0 20px 48px rgba(0, 0, 0, 0.09);
  --shadow-header:
    0 2px 16px rgba(0, 0, 0, 0.06);
  --shadow-input:
    0 2px 8px rgba(0, 0, 0, 0.05);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   420ms cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* Layout */
  --card-min-width:    280px;
  --content-max-width: 1200px;
  --header-height:     72px;
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ja);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

button, select, input {
  font-family: inherit;
  font-size: inherit;
}

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Background decorative layer
   ============================================================ */

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 800px 600px at 10% 20%, rgba(244, 167, 185, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 600px 500px at 90% 80%, rgba(135, 197, 234, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 400px 400px at 50% 50%, rgba(168, 216, 185, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

/* ============================================================
   Header
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  backdrop-filter: blur(14px) saturate(1.6);
  -webkit-backdrop-filter: blur(14px) saturate(1.6);
  background: rgba(248, 246, 242, 0.85);
  border-bottom: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-header);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--content-max-width);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space-6);
  gap: var(--space-4);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.logo-icon {
  font-size: 1.75rem;
  line-height: 1;
  display: inline-block;
}

.site-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(
    135deg,
    var(--color-accent-sakura-dark) 0%,
    #c06080 40%,
    var(--color-accent-sky-dark) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: var(--line-height-tight);
}

.site-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

/* Header navigation */
.header-nav {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

.header-link {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.header-link:hover {
  color: var(--color-accent-sakura-dark);
  background: rgba(244, 167, 185, 0.1);
}

.header-link.active {
  color: var(--color-text-primary);
  background: rgba(0, 0, 0, 0.04);
}

/* ============================================================
   Main Content
   ============================================================ */

.main-content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

/* ============================================================
   Controls bar (search + sort + count)
   ============================================================ */

.controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-8);
}

.search-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: 1rem;
  pointer-events: none;
  line-height: 1;
}

.search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) calc(var(--space-4) + 1.4rem);
  border-radius: var(--radius-pill);
  border: 1.5px solid rgba(0, 0, 0, 0.09);
  background: var(--color-surface-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-input);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.search-input::placeholder {
  color: var(--color-text-muted);
}

.search-input:focus {
  border-color: var(--color-accent-sakura);
  box-shadow: var(--shadow-input), 0 0 0 3px rgba(244, 167, 185, 0.2);
}

/* Clear button for search (type="search" native) */
.search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.sort-wrapper {
  position: relative;
  flex-shrink: 0;
}

.sort-select {
  appearance: none;
  -webkit-appearance: none;
  padding: var(--space-3) calc(var(--space-6) + 0.5rem) var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  border: 1.5px solid rgba(0, 0, 0, 0.09);
  background-color: var(--color-surface-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--color-text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-input);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239e9e9e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  transition: border-color var(--transition-fast);
  outline: none;
}

.sort-select:focus {
  border-color: var(--color-accent-sky);
  box-shadow: var(--shadow-input), 0 0 0 3px rgba(135, 197, 234, 0.2);
}

.game-count {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================================
   Game Grid
   ============================================================ */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width), 1fr));
  gap: var(--space-6);
}

/* ============================================================
   Game Card
   ============================================================ */

.game-card {
  background: var(--color-surface-glass);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border: 1px solid var(--color-border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card-rest);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition:
    transform var(--transition-slow),
    box-shadow var(--transition-slow);
  will-change: transform, box-shadow;
}

.game-card:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: var(--shadow-card-hover);
}

/* Thumbnail */
.card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: linear-gradient(
    135deg,
    var(--color-accent-sakura) 0%,
    #c8b4e8 50%,
    var(--color-accent-sky) 100%
  );
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

.game-card:hover .card-thumb img {
  transform: scale(1.04);
}

/* Placeholder when no thumbnail */
.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: rgba(255, 255, 255, 0.85);
}

.thumb-placeholder-icon {
  font-size: 2.5rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.thumb-placeholder-text {
  font-size: var(--font-size-xs);
  letter-spacing: 0.08em;
  font-weight: 500;
  opacity: 0.8;
}

/* Card body */
.card-body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
}

.card-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}

.card-title-en {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  margin-top: var(--space-1);
}

.card-description {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: var(--line-height-normal);
  flex: 1;
}

/* Tags */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag {
  display: inline-block;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.tag:nth-child(odd) {
  background: rgba(244, 167, 185, 0.2);
  color: #c06080;
}

.tag:nth-child(even) {
  background: rgba(135, 197, 234, 0.2);
  color: #4a8fba;
}

/* Card meta (creator + date) */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
}

.card-creator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.creator-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent-sakura), var(--color-accent-sky));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

.card-date {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* Card footer */
.card-footer {
  padding: 0 var(--space-5) var(--space-5);
}

.btn-play {
  display: block;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  background: linear-gradient(
    135deg,
    var(--color-accent-sakura) 0%,
    var(--color-accent-sakura-dark) 100%
  );
  color: white;
  font-weight: 700;
  font-size: var(--font-size-sm);
  letter-spacing: 0.06em;
  text-align: center;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(232, 130, 154, 0.35);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    filter var(--transition-fast);
}

.btn-play:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(232, 130, 154, 0.45);
}

.btn-play:active {
  transform: translateY(0);
  filter: brightness(0.97);
}

/* ============================================================
   Skeleton loading cards
   ============================================================ */

.game-card.skeleton {
  pointer-events: none;
}

.skeleton-thumb {
  aspect-ratio: 16 / 9;
  background: linear-gradient(90deg,
    rgba(0,0,0,0.05) 25%,
    rgba(0,0,0,0.09) 50%,
    rgba(0,0,0,0.05) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.skeleton-line {
  height: 14px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg,
    rgba(0,0,0,0.05) 25%,
    rgba(0,0,0,0.09) 50%,
    rgba(0,0,0,0.05) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.skeleton-line.wide  { width: 75%; }
.skeleton-line.medium { width: 55%; }
.skeleton-line.short  { width: 35%; }

.skeleton-body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  gap: var(--space-4);
}

.empty-state-icon {
  font-size: 4rem;
  line-height: 1;
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-text-secondary);
}

.empty-state-body {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  max-width: 320px;
  line-height: var(--line-height-normal);
}

/* ============================================================
   Error state
   ============================================================ */

.error-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-12) var(--space-8);
  text-align: center;
  gap: var(--space-3);
}

.error-state-icon {
  font-size: 3rem;
  opacity: 0.6;
}

.error-state-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: #c06060;
}

.error-state-body {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-family: monospace;
}

/* ============================================================
   Footer
   ============================================================ */

.site-footer {
  text-align: center;
  padding: var(--space-8) var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  margin-top: var(--space-8);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 640px) {
  :root {
    --header-height: 60px;
  }

  .site-title {
    font-size: var(--font-size-lg);
  }

  .site-subtitle {
    display: none;
  }

  .main-content {
    padding: var(--space-6) var(--space-4) var(--space-12);
  }

  .header-inner {
    padding: 0 var(--space-4);
  }

  .controls {
    margin-bottom: var(--space-6);
  }

  .game-grid {
    gap: var(--space-4);
  }
}

/* ============================================================
   Reduced motion
   ============================================================ */

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