:root {
  color-scheme: light dark;
  --bg: #f8f8ee;
  --surface: #ffffff;
  --surface-soft: #eff0ed;
  --surface-strong: #20211f;
  --text: #1b1b1c;
  --muted: #60625c;
  --line: rgba(27, 27, 28, 0.13);
  --accent: #a7e92f;
  --accent-strong: #7dbd00;
  --accent-soft: #e8ffc1;
  --danger: #d93030;
  --danger-soft: #ffe3df;
  --shadow: 0 18px 45px rgba(43, 53, 25, 0.1);
  --radius-card: 16px;
  --radius-panel: 24px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 6%, rgba(167, 233, 47, 0.17), transparent 28rem),
    var(--bg);
  font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.site-shell {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 12px;
  background: #f8f8ee;
}

.brand img { width: 132px; height: auto; display: block; }

.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.header-meta span + span {
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.intro {
  max-width: 760px;
  padding: clamp(30px, 6vw, 68px) 0 clamp(26px, 4vw, 44px);
}

.intro h1,
.landing-copy h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(1.2rem, 3.25vw, 2.6rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
  font-weight: 760;
}

.intro p,
.landing-copy p {
  max-width: 620px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.55;
}

.game-board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: clamp(64px, 12vw, 170px);
  padding: clamp(20px, 4vw, 44px);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
  isolation: isolate;
}

.card-column {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: start;
  gap: clamp(12px, 2vw, 18px);
}

.column-title {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.match-card {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: clamp(68px, 8vw, 82px);
  padding: 14px clamp(14px, 2.2vw, 24px);
  color: var(--text);
  text-align: left;
  font-size: clamp(0.92rem, 2vw, 1.18rem);
  line-height: 1.18;
  font-weight: 720;
  border: 2px solid transparent;
  border-radius: var(--radius-card);
  background: var(--surface-soft);
  box-shadow: 0 7px 18px rgba(43, 53, 25, 0.07);
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease, color 180ms ease;
}

.match-card:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent-strong) 48%, transparent);
  box-shadow: 0 11px 23px rgba(83, 113, 26, 0.13);
}

.match-card:active:not(:disabled) { transform: scale(0.985); }

.match-card:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.game-link:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 4px;
}

.match-card.is-selected {
  background: var(--surface-strong);
  color: #f9f9f1;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(167, 233, 47, 0.23), 0 13px 28px rgba(27, 27, 28, 0.18);
}

.match-card.is-matched {
  color: var(--text);
  border-color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: none;
  cursor: default;
}

.match-card.is-wrong {
  color: #6f1717;
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: shake 340ms ease both;
}

.card-port {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  transform: translateY(-50%) scale(0.2);
  transition: background-color 180ms ease, transform 180ms ease;
}

[data-card-side="country"] .card-port { right: -7px; }
[data-card-side="concept"] .card-port { left: -7px; }
.match-card.is-matched .card-port { background: var(--accent-strong); transform: translateY(-50%) scale(1); }

.connection-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.match-line {
  fill: none;
  stroke: var(--accent-strong);
  stroke-width: 8;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.feedback {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 22px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: var(--radius-card);
  background: var(--danger-soft);
}

.feedback[hidden] { display: none; }

.feedback strong { display: block; margin-bottom: 3px; color: #6f1717; }
.feedback p { margin: 0; color: #7a2a26; line-height: 1.45; }

.primary-button,
.secondary-button,
.game-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 14px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease;
}

.primary-button,
.game-link {
  color: #162000;
  border: 1px solid #8bc81e;
  background: var(--accent);
}

.secondary-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

.primary-button:hover,
.game-link:hover { background: #b4f448; }
.primary-button:active,
.secondary-button:active,
.game-link:active { transform: scale(0.98); }

.completion-dialog {
  width: min(530px, calc(100% - 32px));
  padding: 0;
  color: var(--text);
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(13, 17, 7, 0.28);
}

.completion-dialog::backdrop {
  background: rgba(20, 24, 13, 0.56);
  backdrop-filter: blur(8px);
}

.completion-content {
  position: relative;
  overflow: hidden;
  padding: clamp(34px, 8vw, 62px);
  text-align: center;
}

.completion-content::before,
.completion-content::after {
  content: "";
  position: absolute;
  width: 190px;
  height: 62px;
  border-radius: 16px;
  background: var(--accent);
  transform: rotate(-34deg);
  opacity: 0.24;
}

.completion-content::before { top: -28px; left: -72px; }
.completion-content::after { right: -74px; bottom: -30px; }

.success-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 24px;
  color: #162000;
  font-size: 2rem;
  font-weight: 800;
  border-radius: 18px;
  background: var(--accent);
  transform: rotate(-4deg);
}

.completion-content h2 { margin: 0; font-size: clamp(2rem, 7vw, 3.6rem); letter-spacing: -0.045em; line-height: 1; }
.completion-content p { max-width: 390px; margin: 18px auto 28px; color: var(--muted); line-height: 1.5; }

.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;
}

.landing-shell {
  width: min(1160px, calc(100% - 40px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0 40px;
}

.landing-main {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(330px, 0.92fr);
  align-items: center;
  gap: clamp(38px, 7vw, 90px);
  min-height: calc(100dvh - 100px);
}

.landing-copy h1 { max-width: 670px; }
.landing-copy p { max-width: 540px; }

.game-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }

.landing-visual {
  position: relative;
  align-self: center;
}

.landing-visual::before {
  content: "";
  position: absolute;
  inset: 12% -3% 4% 10%;
  z-index: -1;
  border-radius: 28px;
  background: var(--accent);
  transform: rotate(5deg);
}

.landing-visual img {
  display: block;
  width: 100%;
  border-radius: 28px;
  box-shadow: var(--shadow);
}

@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

@media (min-width: 721px) {
  .site-shell {
    width: min(640px, calc(100% - 40px));
    padding: 12px 0 24px;
  }

  .site-header {
    min-height: 38px;
    gap: 12px;
  }

  .brand {
    padding: 4px 6px;
    border-radius: 8px;
  }

  .brand img { width: 76px; }

  .header-meta {
    gap: 8px;
    font-size: 0.68rem;
  }

  .header-meta span + span { padding-left: 8px; }

  .intro {
    max-width: 500px;
    padding: 22px 0 18px;
  }

  .intro p {
    max-width: 480px;
    margin-top: 10px;
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .game-board {
    column-gap: clamp(38px, 7vw, 76px);
    padding: 20px;
    border-radius: 16px;
  }

  .card-column { gap: 9px; }

  .column-title {
    margin-bottom: 0;
    font-size: 0.58rem;
  }

  .match-card {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 0.78rem;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(43, 53, 25, 0.06);
  }

  .card-port {
    width: 7px;
    height: 7px;
  }

  [data-card-side="country"] .card-port { right: -5px; }
  [data-card-side="concept"] .card-port { left: -5px; }
  .match-line { stroke-width: 5; }

  .feedback {
    gap: 12px;
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.76rem;
  }

  .primary-button,
  .secondary-button,
  .game-link {
    min-height: 34px;
    padding: 0 13px;
    border-radius: 9px;
    font-size: 0.76rem;
  }

  .completion-dialog {
    width: min(380px, calc(100% - 32px));
    border-radius: 16px;
  }

  .completion-content { padding: 32px; }

  .success-mark {
    width: 42px;
    height: 42px;
    margin-bottom: 14px;
    border-radius: 11px;
    font-size: 1.3rem;
  }

  .completion-content h2 { font-size: 1.8rem; }
  .completion-content p { max-width: 300px; margin: 10px auto 16px; font-size: 0.8rem; }

  .landing-shell {
    width: min(760px, calc(100% - 40px));
    padding: 12px 0 24px;
  }

  .landing-main {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.82fr);
    gap: 40px;
    min-height: calc(100dvh - 70px);
  }

  .landing-copy p {
    max-width: 430px;
    margin-top: 10px;
    font-size: 0.82rem;
  }

  .game-links { gap: 8px; margin-top: 16px; }
  .landing-visual img,
  .landing-visual::before { border-radius: 18px; }
}

@media (max-width: 720px) {
  .site-shell { width: min(100% - 24px, 620px); padding-top: 12px; }
  .site-header { min-height: 52px; }
  .brand img { width: 106px; }
  .header-meta { gap: 8px; font-size: 0.72rem; }
  .header-meta span + span { padding-left: 8px; }
  .intro { padding: 26px 4px 24px; }
  .intro h1 { font-size: clamp(1.2rem, 6vw, 1.75rem); }
  .intro p { margin-top: 14px; font-size: 0.96rem; }
  .game-board { column-gap: 34px; padding: 16px 10px; border-radius: 20px; }
  .card-column { gap: 10px; }
  .column-title { font-size: 0.62rem; }
  .match-card { min-height: 62px; padding: 10px 10px; font-size: clamp(0.78rem, 3.7vw, 0.96rem); border-radius: 13px; }
  .match-line { stroke-width: 6; }
  .feedback { grid-template-columns: 1fr; gap: 14px; }
  .feedback .primary-button { width: 100%; }
  .landing-shell { width: min(100% - 28px, 620px); padding-top: 14px; }
  .landing-main { grid-template-columns: 1fr; align-content: center; padding: 34px 0; }
  .landing-copy h1 { font-size: clamp(1.35rem, 7vw, 2.2rem); }
  .landing-visual { max-width: 420px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151712;
    --surface: #20231d;
    --surface-soft: #2b2e28;
    --surface-strong: #a7e92f;
    --text: #f1f3e9;
    --muted: #b3b7aa;
    --line: rgba(241, 243, 233, 0.13);
    --accent-soft: #293a15;
    --danger-soft: #44211f;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  }
  .match-card.is-selected { color: #162000; }
  .match-card.is-wrong, .feedback strong { color: #ffb5ae; }
  .feedback p { color: #f3b5af; }
}

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