:root {
  --ink: #10243d;
  --muted: #647086;
  --paper: #fffdfb;
  --lilac: #7652d6;
  --green: #55a846;
  --green-soft: #f3fbef;
  --blue: #3277df;
  --blue-soft: #f0f9ff;
  --red: #e9473f;
  --red-soft: #fff0ed;
  --line: #9aa5b5;
  --shadow: 0 20px 60px rgba(16, 36, 61, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(135deg, #f8fbff 0%, #f7fbff 48%, #f3fbf1 100%);
  color: var(--ink);
  font-family: ui-rounded, "Nunito", "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
a {
  font: inherit;
}

.app {
  width: min(100%, 1160px);
  margin: 0 auto;
  padding: 16px;
}

.hero {
  position: relative;
  text-align: center;
  padding: 18px 16px;
}

.hero h1 {
  margin: 0;
  color: #10253f;
  font-size: clamp(2.2rem, 7vw, 4.8rem);
  line-height: 0.9;
  letter-spacing: 0;
  font-weight: 950;
}

.hero p {
  margin: 18px auto 0;
  max-width: 560px;
  color: #18304f;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  line-height: 1.42;
  font-weight: 750;
}

.game-shell {
  height: 100svh;
  width: 100vw;
  overflow: hidden;
}

.stage-viewport {
  height: 100%;
  overflow: hidden;
}

.stage-track {
  display: flex;
  height: 100%;
  transition: margin-left 560ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: margin-left;
}

.stage-panel {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(10px, 1.3svh, 16px);
  padding: max(14px, env(safe-area-inset-top)) clamp(10px, 3vw, 28px) max(12px, env(safe-area-inset-bottom));
}

.stage-header {
  display: grid;
  justify-items: center;
  text-align: center;
}

.brand-mark {
  margin: 0 0 6px;
  color: #10253f;
  font-size: clamp(1.05rem, 3vw, 1.55rem);
  line-height: 1;
  letter-spacing: 0;
  font-weight: 950;
}

.stage-header h1 {
  margin: 0;
  color: #10253f;
  font-size: clamp(1.45rem, 5.2vw, 3rem);
  line-height: 1.02;
  letter-spacing: 0;
  font-weight: 950;
}

.stage-header p {
  margin: 7px auto 0;
  max-width: 720px;
  color: var(--muted);
  font-size: clamp(0.88rem, 2.9vw, 1.08rem);
  line-height: 1.35;
  font-weight: 760;
}

.stage-count {
  margin-top: 8px;
  min-width: 112px;
  padding: 6px 14px;
  border: 1px solid #d7c9f5;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: #1c2440;
  font-size: clamp(0.8rem, 2.3vw, 0.95rem);
  font-weight: 950;
}

.match-board {
  position: relative;
  min-height: 0;
  width: min(100%, 1020px);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(38px, 10vw, 118px) minmax(0, 1fr);
  gap: clamp(6px, 1.8vw, 16px);
  align-items: stretch;
}

.match-column {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(6px, 1svh, 10px);
}

.match-column h2 {
  margin: 0;
  color: var(--lilac);
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  line-height: 1;
  text-align: center;
  font-weight: 950;
}

.stage-panel:nth-child(2) .match-column:first-child h2 {
  color: var(--green);
}

.stage-panel:nth-child(2) .match-column:last-child h2 {
  color: var(--blue);
}

.option-stack {
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(15, minmax(0, 1fr));
  gap: clamp(4px, 0.75svh, 8px);
}

.option {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 0 7px;
  border: 2px solid var(--option-border);
  border-radius: 7px;
  background: var(--option-bg);
  color: #11233a;
  box-shadow: 0 3px 0 rgba(16, 36, 61, 0.03);
  cursor: pointer;
  font-size: clamp(0.63rem, 2.25vw, 0.92rem);
  font-weight: 950;
  line-height: 1.05;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

.option:hover,
.option:focus-visible {
  outline: 0;
  transform: translateY(-1px);
  box-shadow: 0 0 0 4px rgba(126, 85, 215, 0.14);
}

.option.selected {
  border-color: var(--lilac);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(126, 85, 215, 0.18);
}

.option.done {
  border-color: #4fae48;
  background: #f4ffef;
}

.option.error {
  border-color: var(--red);
  background: var(--red-soft);
  animation: shake 260ms ease-in-out;
}

.option[disabled] {
  cursor: default;
}

.nick {
  --option-border: #cbb8f1;
  --option-bg: #fff;
}

.language-country {
  --option-border: #bde1a5;
  --option-bg: #fbfff7;
}

.rank {
  --option-border: #abd9f3;
  --option-bg: #f6fcff;
}

.word {
  --option-border: #abd9f3;
  --option-bg: #f6fcff;
  font-style: italic;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 11px 14px;
  border: 1px solid #ffd4cc;
  border-radius: 8px;
  background: var(--red-soft);
  color: #b52520;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 22, 39, 0.42);
  backdrop-filter: blur(10px);
}

.modal[hidden] {
  display: none;
}

.summary-card {
  position: relative;
  width: min(100%, 480px);
  max-height: min(90svh, 650px);
  overflow: auto;
  border: 1px solid #bce2a8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: clamp(18px, 5vw, 28px);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #eef4ea;
  color: #315f29;
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 950;
}

.summary-card h2 {
  margin: 0 42px 16px 0;
  font-size: clamp(1.55rem, 6vw, 2.2rem);
  line-height: 1;
}

.summary-card dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.summary-card dl div {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 12px;
}

.summary-card dt {
  font-weight: 950;
}

.summary-card dd {
  margin: 0;
  color: var(--lilac);
  font-weight: 950;
}

.curiosity {
  margin: 18px 0 0;
  line-height: 1.42;
  font-size: 1rem;
}

.final-panel {
  place-items: center;
  text-align: center;
}

.final-copy {
  display: grid;
  gap: 18px;
  justify-items: center;
  width: min(100%, 760px);
}

.final-copy .brand-mark {
  margin-bottom: 2px;
}

.final-copy h1 {
  margin: 0;
  color: #10253f;
  font-size: clamp(2.6rem, 12vw, 6rem);
  line-height: 0.92;
  letter-spacing: 0;
  font-weight: 950;
}

.final-copy p {
  margin: 0;
  max-width: 540px;
  color: var(--muted);
  font-size: clamp(1rem, 4vw, 1.35rem);
  line-height: 1.35;
  font-weight: 850;
}

.reset-link {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid #d7c9f5;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  cursor: pointer;
  font-weight: 950;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  33% { transform: translateX(-4px); }
  66% { transform: translateX(4px); }
}

@media (min-width: 900px) {
  .stage-panel {
    padding-inline: 42px;
  }

  .option {
    font-size: 0.96rem;
  }
}

@media (max-width: 560px) {
  .stage-panel {
    gap: 8px;
    padding-inline: 10px;
  }

  .match-board {
    grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
    gap: 5px;
  }

  .option {
    padding-inline: 4px;
    border-radius: 6px;
  }

  .summary-card dl div {
    grid-template-columns: 95px 1fr;
    gap: 9px;
  }
}
