:root {
  --cream: #fff4cf;
  --sun: #ffd15c;
  --coral: #ff6b5f;
  --orange: #f59e0b;
  --teal: #17bebb;
  --ink: #1f2937;
  --paper: rgba(255, 255, 255, 0.88);
  --shadow: 0 18px 45px rgba(106, 62, 20, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.8), transparent 22rem),
    linear-gradient(135deg, #fff3b0 0%, #ffd166 38%, #ff8a65 72%, #f7655b 100%);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: #0f766e;
  font-weight: 800;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  z-index: 50;
  background: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 1rem;
}

.screen {
  display: none;
  min-height: calc(100vh - 4rem);
  padding: 5.5rem 1.25rem 5rem;
}

.screen.active {
  display: block;
}

.hero-grid,
.panel,
.game-header,
.game-layout,
.scoreboard {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 2rem;
  align-items: center;
}

.hero-copy,
.panel,
.board-panel,
.legend-panel,
.turn-card,
.score-card,
.modal-card {
  background: var(--paper);
  border: 3px solid rgba(255, 255, 255, 0.68);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-copy,
.panel {
  padding: clamp(1.5rem, 4vw, 3rem);
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: #a33b28;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4.7rem);
  line-height: 0.95;
}

h2 {
  margin: 0.6rem 0 1rem;
  font-size: clamp(1.2rem, 2.5vw, 2rem);
}

.intro,
.notice,
.final-panel p {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.55;
}

.brand-line,
.site-footer {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.brand-line.centered {
  justify-content: center;
}

.brand-logo {
  width: 62px;
  height: auto;
  object-fit: contain;
}

.footer-logo {
  width: 34px;
  height: auto;
}

.hero-visual {
  position: relative;
  min-height: 500px;
}

.hero-visual img {
  position: absolute;
  object-fit: contain;
  filter: drop-shadow(0 18px 25px rgba(87, 48, 10, 0.24));
}

.hero-visual img:nth-child(1) {
  z-index: 3;
  width: min(72%, 390px);
  max-width: none;
  left: 0;
  top: 3%;
}

.hero-visual img:nth-child(2) {
  z-index: 2;
  width: min(48%, 250px);
  max-width: none;
  left: 38%;
  top: 31%;
  transform: rotate(-8deg);
}

.hero-visual img:nth-child(3) {
  z-index: 1;
  width: min(46%, 250px);
  max-width: none;
  right: 2%;
  bottom: 3%;
}

.primary-button,
.secondary-button,
.ghost-button,
.success-button,
.danger-button,
.utility-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0.78rem 1rem;
  font-weight: 900;
  color: var(--ink);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
}

.primary-button {
  background: #0fb9b1;
  color: #062b2a;
}

.secondary-button {
  background: #ffd166;
}

.ghost-button {
  background: #fff;
  border: 2px solid rgba(31, 41, 55, 0.18);
}

.success-button {
  background: #52d273;
}

.danger-button {
  background: #ff7a72;
}

.small {
  min-height: 38px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

.hero-actions,
.setup-actions,
.modal-actions,
.timer-actions,
.board-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.utility-button {
  position: fixed;
  z-index: 35;
  top: 0.9rem;
  background: #fff;
}

.sound-button {
  right: 1rem;
}

.fullscreen-button {
  right: 12rem;
}

.floating-fan {
  position: fixed;
  z-index: 28;
  right: 1rem;
  bottom: 3.8rem;
  width: clamp(110px, 13vw, 140px);
  max-height: 140px;
  object-fit: contain;
  filter: drop-shadow(0 12px 22px rgba(66, 43, 7, 0.28));
  pointer-events: none;
}

.floating-fan.turbo {
  transform: scale(1.18) rotate(-2deg);
  filter: drop-shadow(0 0 24px rgba(23, 190, 187, 0.72));
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient span {
  position: absolute;
  color: rgba(255, 255, 255, 0.32);
  font-size: clamp(1.5rem, 4vw, 4rem);
  font-weight: 900;
}

.ambient span:nth-child(1) { left: 6%; top: 18%; }
.ambient span:nth-child(2) { right: 14%; top: 18%; }
.ambient span:nth-child(3) { left: 12%; bottom: 18%; }
.ambient span:nth-child(4) { right: 24%; bottom: 24%; }
.ambient span:nth-child(5) { right: 8%; bottom: 46%; }

#app,
.site-footer {
  position: relative;
}

.site-footer {
  z-index: 25;
  min-height: 4rem;
  justify-content: center;
  padding: 0.8rem 1rem;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.95rem;
}

.setup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  margin: 1.3rem 0;
}

.setup-row label,
.team-input label {
  font-weight: 900;
}

select,
input {
  width: 100%;
  border: 2px solid rgba(31, 41, 55, 0.2);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: #fff;
}

.team-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.team-input {
  display: grid;
  gap: 0.35rem;
}

.starter-result {
  min-height: 1.5rem;
  font-weight: 900;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 300px);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.game-header h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
}

.wind-phrase {
  display: inline-block;
  margin: 0.6rem 0 0;
  padding: 0.45rem 0.75rem;
  background: rgba(255, 255, 255, 0.72);
  border-left: 5px solid var(--teal);
  font-weight: 800;
}

.wind-phrase.blow-in {
  animation: blowIn 460ms ease both;
}

.turn-card {
  padding: 1rem;
}

.turn-card span {
  display: block;
  font-size: 0.85rem;
  font-weight: 900;
  text-transform: uppercase;
}

.turn-card strong {
  display: block;
  margin: 0.25rem 0 0.8rem;
  font-size: 1.35rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.score-card {
  padding: 0.9rem;
  border-left: 8px solid var(--teal);
}

.score-card.active-team {
  outline: 4px solid rgba(23, 190, 187, 0.35);
}

.score-card h3 {
  margin: 0;
}

.score-card .points {
  margin: 0.35rem 0;
  font-size: 2.1rem;
  font-weight: 1000;
}

.score-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.score-controls button {
  min-height: 34px;
  padding: 0.3rem;
  border: 0;
  border-radius: 6px;
  background: #fff;
  font-weight: 900;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 1rem;
}

.board-panel,
.legend-panel {
  padding: 1rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.section-head h2,
.legend-panel h2 {
  margin: 0 0 0.75rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 0.45rem;
}

.axis,
.cell {
  min-height: clamp(48px, 8vw, 86px);
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  text-align: center;
  font-weight: 1000;
}

.axis {
  background: rgba(255, 255, 255, 0.7);
}

.cell {
  position: relative;
  border: 0;
  color: #fff;
  background: #334155;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16);
}

.cell small {
  display: block;
  font-size: 0.75rem;
}

.cell.math { background: #2478d4; }
.cell.physics { background: #8b5cf6; }
.cell.chemistry { background: #16a34a; }
.cell.bonus { background: #ec4899; }
.cell.done {
  background: #64748b;
  opacity: 0.72;
}

.pill {
  display: inline-flex;
  min-width: 76px;
  justify-content: center;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
}

.pill.math { background: #2478d4; }
.pill.physics { background: #8b5cf6; }
.pill.chemistry { background: #16a34a; }
.pill.bonus { background: #ec4899; }

.legend-gif {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(31, 41, 55, 0.54);
}

.modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: min(92vh, 820px);
  overflow: auto;
  padding: 1.2rem;
}

.icon-close {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  font-size: 1.5rem;
  font-weight: 900;
}

.modal-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-right: 3rem;
}

.modal-meta span,
.special-note {
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  background: #fff3b0;
  font-weight: 900;
}

.question-box,
.answer-box {
  margin: 1rem 0;
  padding: 1rem;
  border-radius: var(--radius);
  font-size: 1.18rem;
  line-height: 1.5;
}

.question-box {
  background: #eefbff;
}

.answer-box {
  background: #eefbf0;
  border-left: 5px solid #16a34a;
}

.timer {
  display: grid;
  gap: 0.8rem;
  align-items: center;
  margin: 1rem 0;
}

#timerValue {
  display: inline-grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  font-size: 2.2rem;
  font-weight: 1000;
}

.modal-card.shake {
  animation: shake 360ms ease;
}

.modal-message {
  min-height: 1.5rem;
  font-weight: 900;
}

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

.final-gif {
  width: min(220px, 60vw);
  max-height: 180px;
  object-fit: contain;
}

blockquote {
  margin: 1rem auto;
  max-width: 680px;
  padding: 1rem;
  border-left: 6px solid var(--coral);
  background: rgba(255, 255, 255, 0.76);
  font-size: 1.25rem;
  font-weight: 900;
}

.hidden {
  display: none !important;
}

.confetti-layer,
.wind-layer {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -1rem;
  width: 10px;
  height: 16px;
  background: var(--coral);
  animation: fall 950ms ease-in forwards;
}

.gust {
  position: absolute;
  right: -110px;
  width: 96px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  animation: gust 800ms ease-out forwards;
}

img.broken {
  display: none !important;
}

@keyframes blowIn {
  from { transform: translateX(-2rem); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@keyframes fall {
  to { transform: translateY(100vh) rotate(340deg); opacity: 0; }
}

@keyframes gust {
  to { transform: translateX(-120vw); opacity: 0; }
}

@media (max-width: 900px) {
  .hero-grid,
  .game-header,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .hero-visual {
    min-height: 340px;
  }

  .hero-visual img:nth-child(1) {
    width: min(58%, 300px);
    left: 0;
    top: 0;
  }

  .hero-visual img:nth-child(2) {
    width: min(38%, 190px);
    left: 40%;
    top: 24%;
  }

  .hero-visual img:nth-child(3) {
    width: min(38%, 190px);
    right: 0;
    bottom: 0;
  }

  .fullscreen-button {
    right: auto;
    left: 1rem;
  }

  .floating-fan {
    width: 96px;
  }
}

@media (max-width: 640px) {
  .screen {
    padding-inline: 0.7rem;
  }

  .board {
    gap: 0.25rem;
  }

  .axis,
  .cell {
    min-height: 46px;
    font-size: 0.86rem;
  }

  .score-controls {
    grid-template-columns: repeat(3, 1fr);
  }

  .utility-button {
    position: static;
    margin: 0.5rem;
  }
}

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