/* ============================================================
   Architecture Elo — Stylesheet
   ============================================================ */

/* ----- Custom Properties ----- */
:root {
  /* Palette — sophisticated, muted, architecture-appropriate */
  --color-bg:           #f5f2ee;
  --color-bg-alt:       #eae6e0;
  --color-surface:      #ffffff;
  --color-nav:          #2c2c2c;
  --color-nav-text:     #d4cfc8;
  --color-nav-active:   #ffffff;
  --color-text:         #333333;
  --color-text-muted:   #7a7570;
  --color-heading:      #1e1e1e;
  --color-accent:       #8b6f4e;
  --color-accent-hover: #a38260;
  --color-border:       #d9d4cd;
  --color-shadow:       rgba(0, 0, 0, 0.08);
  --color-shadow-lg:    rgba(0, 0, 0, 0.12);
  --color-success:      #5a8a5e;
  --color-error:        #b5564d;
  --color-error-bg:     #fdf0ef;
  --color-selected:     #8b6f4e;
  --color-skeleton:     #e4e0da;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Spacing scale */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Sizing */
  --max-width:    1100px;
  --nav-height:   56px;
  --radius:       6px;
  --radius-lg:    10px;
  --transition:   0.2s ease;
}

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  min-height: 100vh;
}

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

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--color-accent-hover);
}

h1, h2, h3 {
  color: var(--color-heading);
  line-height: 1.25;
}

/* ----- Navigation ----- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  padding: 0 var(--space-lg);
  background: var(--color-nav);
  color: var(--color-nav-text);
}

.nav__brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-nav-active);
  letter-spacing: 0.02em;
}

.nav__links {
  display: flex;
  gap: var(--space-lg);
  list-style: none;
}

.nav__link {
  color: var(--color-nav-text);
  font-size: 0.9rem;
  font-weight: 500;
  padding: var(--space-xs) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.nav__link:hover {
  color: var(--color-nav-active);
}

.nav__link--active {
  color: var(--color-nav-active);
  border-bottom-color: var(--color-accent);
}

/* ----- Layout ----- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

.section {
  margin-bottom: var(--space-2xl);
}

.text-center {
  text-align: center;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.75rem 1.75rem;
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition),
    box-shadow var(--transition);
}

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

.btn--primary {
  background: var(--color-accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--color-accent-hover);
  box-shadow: 0 4px 12px var(--color-shadow-lg);
  color: #fff;
}

.btn--secondary {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn--secondary:hover {
  background: var(--color-border);
}

.btn--small {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

/* ----- Cards ----- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px var(--color-shadow);
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  box-shadow: 0 6px 20px var(--color-shadow-lg);
}

/* ----- About / Index Page ----- */
.hero {
  text-align: center;
  padding: var(--space-3xl) 0 var(--space-xl);
}

.hero__title {
  font-size: 2.4rem;
  margin-bottom: var(--space-md);
  letter-spacing: -0.02em;
}

.hero__subtitle {
  font-size: 1.1rem;
  color: var(--color-text-muted);
  max-width: 640px;
  margin: 0 auto var(--space-xl);
  line-height: 1.7;
}

.how-it-works {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-lg);
  margin: var(--space-xl) 0;
}

.how-it-works__step {
  text-align: center;
  padding: var(--space-lg);
}

.how-it-works__number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: var(--space-md);
}

.how-it-works__title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.how-it-works__desc {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.stats-bar {
  display: flex;
  justify-content: center;
  gap: var(--space-2xl);
  padding: var(--space-lg) 0;
  flex-wrap: wrap;
}

.stats-bar__item {
  text-align: center;
}

.stats-bar__value {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--color-heading);
}

.stats-bar__label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.credits {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-lg);
  margin-top: var(--space-2xl);
  line-height: 1.7;
}

/* ----- Play Page ----- */
.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.play-header__counter {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.play-header__hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.play-header__hint kbd {
  display: inline-block;
  padding: 0.1em 0.45em;
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 3px;
}

.match-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.match-card {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px var(--color-shadow);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition),
    border-color var(--transition);
  border: 3px solid transparent;
}

.match-card:hover {
  box-shadow: 0 8px 28px var(--color-shadow-lg);
  transform: translateY(-3px);
}

.match-card:active {
  transform: translateY(0) scale(0.98);
}

.match-card--selected {
  border-color: var(--color-selected);
  box-shadow: 0 0 0 2px var(--color-selected), 0 8px 28px var(--color-shadow-lg);
  transform: translateY(-3px);
}

.match-card--selected .match-card__check {
  opacity: 1;
  transform: scale(1);
}

.match-card--dimmed {
  opacity: 0.5;
  filter: grayscale(0.3);
  pointer-events: none;
}

.match-card__image-wrap {
  position: relative;
  width: 100%;
  padding-top: 70%;         /* 10:7 aspect ratio */
  background: var(--color-skeleton);
  overflow: hidden;
}

.match-card__image-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
}

.match-card__image-wrap img.loading {
  opacity: 0;
}

.match-card__check {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-selected);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 2;
}

.match-card__info {
  padding: var(--space-md) var(--space-lg);
  text-align: center;
}

.match-card__style {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-heading);
  margin-bottom: var(--space-xs);
}

.match-card__rating {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.match-card__rating.visible {
  opacity: 1;
  transform: translateY(0);
}

.play-next {
  text-align: center;
  margin-top: var(--space-md);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.play-next.visible {
  opacity: 1;
}

/* Skeleton loading for match cards */
.match-card--skeleton .match-card__image-wrap {
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.match-card--skeleton .match-card__style {
  width: 60%;
  height: 1em;
  margin: 0 auto;
  border-radius: 4px;
  background: var(--color-skeleton);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* N > 2: Ranking interface */
.match-area--ranking {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.match-card__rank-badge {
  position: absolute;
  top: var(--space-md);
  left: var(--space-md);
  min-width: 28px;
  height: 28px;
  border-radius: 14px;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 2;
}

.match-card__rank-badge.visible {
  opacity: 1;
  transform: scale(1);
}

/* ----- Results / Leaderboard Page ----- */
.results-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-2xl);
  padding: var(--space-lg) 0;
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
}

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 2px 8px var(--color-shadow);
}

.leaderboard th,
.leaderboard td {
  padding: var(--space-md) var(--space-lg);
  text-align: left;
}

.leaderboard thead {
  background: var(--color-nav);
  color: var(--color-nav-text);
}

.leaderboard th {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--transition);
}

.leaderboard th:hover {
  color: var(--color-nav-active);
}

.leaderboard th.sorted-asc::after {
  content: " \25B2";
  font-size: 0.65em;
}

.leaderboard th.sorted-desc::after {
  content: " \25BC";
  font-size: 0.65em;
}

.leaderboard th.no-sort {
  cursor: default;
}

.leaderboard th.no-sort:hover {
  color: var(--color-nav-text);
}

.leaderboard tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.leaderboard tbody tr:last-child {
  border-bottom: none;
}

.leaderboard tbody tr:hover {
  background: var(--color-bg);
}

.leaderboard__rank {
  font-weight: 700;
  color: var(--color-accent);
  width: 50px;
}

.leaderboard__thumb {
  width: 48px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 1px 3px var(--color-shadow);
}

.leaderboard__name {
  font-weight: 600;
}

.leaderboard__rating {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.leaderboard__uncertainty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.leaderboard__matches {
  font-variant-numeric: tabular-nums;
}

/* ----- Toast / Error Banner ----- */
.toast-container {
  position: fixed;
  top: calc(var(--nav-height) + var(--space-md));
  right: var(--space-lg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error);
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
  font-size: 0.9rem;
  box-shadow: 0 4px 14px var(--color-shadow-lg);
  animation: toast-in 0.3s ease forwards;
  max-width: 380px;
}

.toast--leaving {
  animation: toast-out 0.25s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ----- Responsive ----- */
@media (max-width: 700px) {
  .match-area {
    grid-template-columns: 1fr;
  }

  .hero__title {
    font-size: 1.7rem;
  }

  .hero__subtitle {
    font-size: 1rem;
  }

  .stats-bar {
    gap: var(--space-lg);
  }

  .nav {
    padding: 0 var(--space-md);
  }

  .nav__links {
    gap: var(--space-md);
  }

  .play-header {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Leaderboard responsive: hide uncertainty on small screens */
  .leaderboard .col-uncertainty {
    display: none;
  }

  .leaderboard th,
  .leaderboard td {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.88rem;
  }

  .leaderboard__thumb {
    width: 44px;
  }

  .leaderboard__thumb img {
    width: 40px;
    height: 30px;
  }

  .container {
    padding: var(--space-lg) var(--space-md);
  }
}

@media (max-width: 440px) {
  .nav__brand {
    font-size: 0.95rem;
  }

  .nav__link {
    font-size: 0.8rem;
  }
}
