/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: white;
  background: linear-gradient(135deg, #1e3a8a 0%, #581c87 100%);
}
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

body.app {
  height: 100vh; overflow: hidden;
  touch-action: manipulation; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}
body.app button { user-select: none; -webkit-user-select: none; }

/* ===== Landing ===== */
.site-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 32px;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.3em; font-weight: 800; }
.logo img { width: 36px; height: 36px; }

.cta-button {
  display: inline-block;
  padding: 12px 24px; border-radius: 12px; border: none;
  background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1f2937;
  font-size: 1em; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(251,191,36,0.3);
}
.cta-button:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(251,191,36,0.45); }
.cta-button.large { padding: 20px 48px; font-size: 1.3em; border-radius: 14px; }

.hero {
  text-align: center; padding: 100px 20px 60px;
  max-width: 900px; margin: 0 auto;
}
.hero h1 {
  font-size: clamp(2.5em, 6vw, 5em);
  font-weight: 900; line-height: 1.1; margin-bottom: 20px;
  background: linear-gradient(135deg, #fff 0%, #fbbf24 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero .lead {
  font-size: clamp(1.1em, 2.5vw, 1.4em);
  opacity: 0.85; margin-bottom: 36px; font-weight: 500;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  max-width: 1100px;
  margin: 60px auto;
  padding: 0 20px;
}
.feature {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 28px;
  backdrop-filter: blur(10px);
}
.feature .icon { font-size: 2.5em; margin-bottom: 12px; }
.feature h3 { font-size: 1.3em; margin-bottom: 8px; font-weight: 700; }
.feature p { opacity: 0.75; line-height: 1.5; }

.faq {
  max-width: 720px; margin: 80px auto;
  padding: 0 20px;
}
.faq h2 { text-align: center; font-size: 2em; margin-bottom: 32px; }
.faq details {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px; margin-bottom: 12px; padding: 16px 20px;
}
.faq summary {
  cursor: pointer; font-weight: 600; font-size: 1.05em;
  list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+"; font-size: 1.6em; transition: transform 0.2s; line-height: 1;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { padding-top: 12px; opacity: 0.8; line-height: 1.6; }

.cta-section { text-align: center; padding: 80px 20px; }
.cta-section h2 { font-size: 2.2em; margin-bottom: 16px; }
.cta-section p { opacity: 0.8; margin-bottom: 28px; font-size: 1.1em; }

.site-footer {
  text-align: center; padding: 30px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  opacity: 0.6; font-size: 0.9em;
}

/* ===== App: shared ===== */
.screen { width: 100%; height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* Setup screen */
#setup { align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.setup-card {
  background: rgba(255,255,255,0.08); backdrop-filter: blur(10px);
  border-radius: 24px; padding: 32px; max-width: 600px; width: 100%;
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.setup-card h1 { font-size: 2.5em; text-align: center; margin-bottom: 4px; }
.setup-card .subtitle { text-align: center; opacity: 0.7; margin-bottom: 28px; font-size: 1.05em; }
.field { margin-bottom: 22px; }
.field-label {
  display: block; font-weight: 600; margin-bottom: 10px; font-size: 0.95em;
  opacity: 0.85; text-transform: uppercase; letter-spacing: 0.5px;
}
.team-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type=text] {
  width: 100%; padding: 14px 16px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08); color: white; font-size: 1em; font-weight: 600;
  font-family: inherit;
}
input[type=text]:focus { outline: none; border-color: #fbbf24; }

.toggle-group { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle-btn {
  flex: 1; min-width: 70px; padding: 14px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05); color: white;
  font-size: 1.4em; font-weight: 700; cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn:hover { background: rgba(255,255,255,0.1); }
.toggle-btn.active { background: #fbbf24; color: #1f2937; border-color: #fbbf24; }

.stepper { display: flex; align-items: center; gap: 16px; }
.stepper button {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  font-size: 1.5em; background: rgba(255,255,255,0.15);
  color: white; cursor: pointer; font-weight: 700;
}
.stepper button:hover { background: rgba(255,255,255,0.25); }
.stepper-value { font-size: 1.8em; font-weight: 800; min-width: 60px; text-align: center; }

.start-btn {
  width: 100%; padding: 18px; border-radius: 14px; border: none;
  background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1f2937;
  font-size: 1.3em; font-weight: 800; cursor: pointer; margin-top: 10px;
  box-shadow: 0 8px 20px rgba(251,191,36,0.3);
  transition: transform 0.15s;
}
.start-btn:hover:not(:disabled) { transform: translateY(-2px); }
.start-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Game screen */
#game { display: flex; flex-direction: column; }
.top-bar { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; z-index: 10; }
.top-bar button {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.4); color: white; cursor: pointer; font-size: 1.1em;
}

.rope-container {
  height: 90px; position: relative; padding: 0 40px;
  display: flex; align-items: center;
  background: rgba(0,0,0,0.25);
  border-bottom: 2px solid rgba(255,255,255,0.1);
}
.rope-track {
  position: relative; width: 100%; height: 10px;
  background: linear-gradient(90deg,
    #ef4444 0%, #ef4444 30%,
    rgba(255,255,255,0.3) 30%, rgba(255,255,255,0.3) 70%,
    #3b82f6 70%, #3b82f6 100%);
  border-radius: 5px;
}
.finish-line {
  position: absolute; top: -22px; height: 54px; width: 4px;
  background: white; border-radius: 2px;
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}
.finish-line.left { left: 30%; }
.finish-line.right { left: 70%; }
.knot {
  position: absolute; top: 50%; left: 50%;
  width: 50px; height: 50px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6em;
}

.teams {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: rgba(0,0,0,0.4); min-height: 0;
}
.team-panel { display: flex; flex-direction: column; padding: 16px; min-height: 0; }
.team-panel.team1 { background: linear-gradient(135deg, rgba(239,68,68,0.35), rgba(239,68,68,0.1)); }
.team-panel.team2 { background: linear-gradient(135deg, rgba(59,130,246,0.35), rgba(59,130,246,0.1)); }

.team-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.team-name { font-size: 1.4em; font-weight: 700; }
.team-score {
  font-size: 1.6em; font-weight: 800;
  padding: 4px 18px; background: rgba(0,0,0,0.3);
  border-radius: 999px; min-width: 70px; text-align: center;
  border: 2px solid rgba(255,255,255,0.2);
}

.problem {
  flex: 0 0 auto; min-height: 60px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(1.8em, 5vw, 3.5em); font-weight: 800; text-align: center;
  margin: 8px 0;
}

.answer-display {
  background: rgba(0,0,0,0.4); border-radius: 12px;
  padding: 10px 16px;
  font-size: clamp(1.4em, 3.5vw, 2.2em); font-weight: 700; text-align: center;
  min-height: 56px; margin-bottom: 12px;
  border: 3px solid rgba(255,255,255,0.1);
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.answer-display.correct { border-color: #22c55e; background: rgba(34,197,94,0.3); transform: scale(1.05); }
.answer-display.wrong { border-color: #ef4444; background: rgba(239,68,68,0.3); animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.numpad {
  flex: 1; display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px; min-height: 0;
}
.numpad button {
  border-radius: 12px; border: none;
  background: rgba(255,255,255,0.15); color: white;
  font-size: clamp(1.2em, 3vw, 2em); font-weight: 700;
  cursor: pointer; touch-action: manipulation;
  transition: transform 0.08s, background 0.15s;
  min-height: 0;
}
.numpad button.pressed { transform: scale(0.92); background: rgba(255,255,255,0.35); }
.numpad button.submit { background: #22c55e; grid-column: span 2; }
.numpad button.clear { background: #6b7280; }

/* Win screen */
#win { align-items: center; justify-content: center; }
.win-card { text-align: center; padding: 40px; }
.trophy { font-size: 6em; margin-bottom: 16px; animation: bounce 1.2s ease-in-out infinite; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}
.winner-name {
  font-size: 2.5em; color: #fbbf24; font-weight: 800; margin-bottom: 12px;
  text-shadow: 0 4px 20px rgba(251,191,36,0.5);
}
.final-score { font-size: 1.3em; opacity: 0.8; margin-bottom: 32px; }
.win-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.win-buttons button {
  padding: 16px 32px; border-radius: 12px; border: none;
  font-size: 1.2em; font-weight: 700; cursor: pointer;
}
.play-again { background: #fbbf24; color: #1f2937; }
.new-game { background: rgba(255,255,255,0.2); color: white; }

@media (max-width: 600px) {
  .site-header { padding: 12px 16px; }
  .hero { padding: 60px 20px 40px; }
  .setup-card { padding: 20px; }
  .setup-card h1 { font-size: 2em; }
  .toggle-btn { font-size: 1.2em; padding: 12px 8px; min-width: 60px; }
}
