/* ==========================================================
   WORD SNAKE
   Games to Literacy
   ========================================================== */


/* ==========================================================
   RESET
   ========================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;

  overflow-x: hidden;

  font-family:
    "Nunito",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  color: #26324a;

  background:
    radial-gradient(
      circle at top left,
      rgba(126, 105, 218, 0.11),
      transparent 34%
    ),
    linear-gradient(
      180deg,
      #fbfaff 0%,
      #f5f3fb 100%
    );
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

img,
canvas {
  max-width: 100%;
}


/* ==========================================================
   ACCESSIBILITY
   ========================================================== */

.skip-link {
  position: fixed;

  top: 8px;
  left: 8px;

  z-index: 9999;

  transform: translateY(-150%);

  padding: 10px 14px;

  border-radius: 10px;

  color: #ffffff;

  background: #6047c4;

  font-weight: 900;

  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #f2c94c;
  outline-offset: 3px;
}


/* ==========================================================
   PAGE
   ========================================================== */

.page-shell {
  width: min(
    1180px,
    calc(100% - 32px)
  );

  margin: 0 auto;

  padding:
    18px
    0
    48px;
}


/* ==========================================================
   HEADER
   ========================================================== */

.site-header {
  display: flex;

  align-items: center;
  justify-content: space-between;

  gap: 20px;

  margin-bottom: 24px;
}

.brand {
  display: inline-flex;

  align-items: center;

  gap: 10px;

  color: #33265f;

  font-size: 1rem;
  font-weight: 900;

  text-decoration: none;
}

.brand-mark {
  display: grid;

  width: 38px;
  aspect-ratio: 1;

  place-items: center;

  border-radius: 11px;

  color: #ffffff;

  background:
    linear-gradient(
      145deg,
      #8067da,
      #5a42bd
    );

  box-shadow:
    0 7px 18px
    rgba(89, 67, 184, 0.22);
}

.header-tag {
  color: #746c8d;

  font-size: 0.78rem;
  font-weight: 800;
}


/* ==========================================================
   MAIN LAYOUT
   ========================================================== */

.game-layout {
  display: grid;

  grid-template-columns:
    minmax(250px, 0.72fr)
    minmax(480px, 1.28fr);

  gap: clamp(
    24px,
    4vw,
    56px
  );

  align-items: center;
}


/* ==========================================================
   HERO COPY
   ========================================================== */

.hero-copy {
  padding:
    12px
    0;
}

.eyebrow {
  margin:
    0
    0
    10px;

  color: #765ed0;

  font-size: 0.75rem;
  font-weight: 900;

  letter-spacing: 0.12em;

  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 0;

  color: #2d2451;

  font-size: clamp(
    3rem,
    6vw,
    5.7rem
  );

  font-weight: 900;

  line-height: 0.91;

  letter-spacing: -0.055em;
}

.hero-copy h1 span {
  color: #7259cf;
}

.intro {
  max-width: 530px;

  margin:
    22px
    0
    24px;

  color: #625b76;

  font-size: 1rem;

  font-weight: 600;

  line-height: 1.7;
}


/* ==========================================================
   MINI INSTRUCTIONS
   ========================================================== */

.mini-instructions {
  display: grid;

  gap: 9px;

  margin: 0;

  padding: 0;

  list-style: none;
}

.mini-instructions li {
  display: flex;

  align-items: center;

  gap: 10px;

  color: #4e4763;

  font-size: 0.88rem;

  font-weight: 700;
}

.instruction-number {
  display: grid;

  flex: 0 0 auto;

  width: 27px;
  height: 27px;

  place-items: center;

  border-radius: 8px;

  color: #ffffff;

  background: #8067da;

  font-size: 0.7rem;

  font-weight: 900;
}


/* ==========================================================
   GAME CARD
   ========================================================== */

.game-card {
  position: relative;

  width: 100%;

  overflow: hidden;

  border:
    1px solid
    rgba(95, 72, 173, 0.12);

  border-radius: 24px;

  background: #ffffff;

  box-shadow:
    0 22px 60px
    rgba(60, 44, 105, 0.14);
}


/* ==========================================================
   GAME TOP BAR
   ========================================================== */

.game-topbar {
  display: grid;

  grid-template-columns:
    repeat(3, 1fr)
    auto;

  align-items: center;

  gap: 8px;

  padding:
    10px
    12px;

  border-bottom:
    1px solid
    #eeeaf6;

  background:
    rgba(255, 255, 255, 0.97);
}

.stat {
  min-width: 0;

  padding:
    6px
    9px;
}

.stat-label {
  display: block;

  margin-bottom: 1px;

  color: #9189a5;

  font-size: 0.62rem;

  font-weight: 900;

  letter-spacing: 0.08em;

  text-transform: uppercase;
}

.stat strong {
  display: block;

  overflow: hidden;

  color: #342b53;

  font-size: 1.08rem;

  font-weight: 900;

  text-overflow: ellipsis;

  white-space: nowrap;
}

.icon-button {
  display: grid;

  width: 38px;
  height: 38px;

  place-items: center;

  border:
    1px solid
    #e8e3f3;

  border-radius: 11px;

  color: #5946a5;

  background: #f7f5fb;

  cursor: pointer;

  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);

  border-color: #d9d0ef;

  background: #f0ecf9;
}


/* ==========================================================
   WORD RACK
   ========================================================== */

.word-rack-wrap {
  display: grid;

  grid-template-columns:
    minmax(0, 1fr)
    auto;

  align-items: center;

  gap: 10px;

  padding:
    9px
    12px
    10px;

  border-bottom:
    1px solid
    #eeeaf6;

  background: #fcfbfe;
}

.rack-main {
  min-width: 0;
}

.rack-label {
  display: block;

  margin-bottom: 4px;

  color: #8b829f;

  font-size: 0.62rem;

  font-weight: 900;

  letter-spacing: 0.07em;

  text-transform: uppercase;
}

.word-rack {
  display: flex;

  min-height: 34px;

  align-items: center;

  gap: 5px;

  overflow-x: auto;

  scrollbar-width: none;
}

.word-rack::-webkit-scrollbar {
  display: none;
}

.rack-tile {
  display: grid;

  flex:
    0
    0
    32px;

  width: 32px;
  height: 32px;

  place-items: center;

  border-radius: 8px;

  color: #ffffff;

  background:
    linear-gradient(
      145deg,
      #8b73df,
      #6e54ca
    );

  box-shadow:
    0 3px 8px
    rgba(83, 61, 166, 0.2);

  font-size: 0.9rem;

  font-weight: 900;
}

.empty-rack {
  overflow: hidden;

  color: #9a92aa;

  font-size: 0.75rem;

  font-weight: 700;

  text-overflow: ellipsis;

  white-space: nowrap;
}

.submit-button {
  min-width: 100px;

  border: 0;

  border-radius: 11px;

  padding:
    9px
    12px;

  color: #ffffff;

  background:
    linear-gradient(
      145deg,
      #745bd0,
      #5941b9
    );

  box-shadow:
    0 7px 15px
    rgba(91, 66, 188, 0.22);

  cursor: pointer;

  font-size: 0.78rem;

  font-weight: 900;

  transition:
    transform 140ms ease,
    box-shadow 140ms ease;
}

.submit-button:hover {
  transform: translateY(-1px);

  box-shadow:
    0 9px 18px
    rgba(91, 66, 188, 0.28);
}

.submit-button:active {
  transform: translateY(0);
}

.submit-button:disabled {
  cursor: wait;

  opacity: 0.65;
}


/* ==========================================================
   BOARD
   ========================================================== */

.board-wrap {
  position: relative;

  width: min(
    calc(100% - 32px),
    672px
  );

  aspect-ratio: 1 / 1;

  margin:
    0
    auto;

  overflow: hidden;

  background: #f8f6fc;
}

#gameCanvas {
  display: block;

  width: 100%;
  height: 100%;

  aspect-ratio: 1 / 1;

  touch-action: none;
}


/* ==========================================================
   OVERLAYS
   ========================================================== */

.overlay {
  position: absolute;

  inset: 0;

  z-index: 10;

  display: grid;

  place-items: center;

  overflow-y: auto;

  padding: clamp(
    10px,
    3vw,
    24px
  );

  background:
    rgba(245, 242, 251, 0.88);

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(
    390px,
    100%
  );

  max-height: 100%;

  overflow-y: auto;

  padding:
    clamp(
      16px,
      3vw,
      28px
    );

  border:
    1px solid
    rgba(112, 86, 202, 0.13);

  border-radius: 22px;

  background:
    rgba(255, 255, 255, 0.97);

  box-shadow:
    0 18px 45px
    rgba(62, 45, 110, 0.16);

  text-align: center;
}

.overlay-icon {
  display: grid;

  width: 52px;
  height: 52px;

  margin:
    0
    auto
    10px;

  place-items: center;

  border-radius: 14px;

  background: #f0ebfb;

  font-size: 1.5rem;
}

.overlay-kicker {
  margin:
    0
    0
    5px;

  color: #7962ca;

  font-size: 0.65rem;

  font-weight: 900;

  letter-spacing: 0.1em;

  text-transform: uppercase;
}

.overlay h2 {
  margin: 0;

  color: #342851;

  font-size: clamp(
    1.5rem,
    4vw,
    2rem
  );

  font-weight: 900;

  line-height: 1.08;
}

.overlay p:not(.overlay-kicker) {
  max-width: 330px;

  margin:
    10px
    auto
    16px;

  color: #70677f;

  font-size: 0.84rem;

  font-weight: 600;

  line-height: 1.5;
}

.primary-button {
  border: 0;

  border-radius: 12px;

  padding:
    11px
    20px;

  color: #ffffff;

  background:
    linear-gradient(
      145deg,
      #795fd3,
      #5941b8
    );

  box-shadow:
    0 9px 20px
    rgba(91, 66, 188, 0.25);

  cursor: pointer;

  font-weight: 900;

  transition:
    transform 140ms ease,
    box-shadow 140ms ease;
}

.primary-button:hover {
  transform: translateY(-2px);

  box-shadow:
    0 12px 24px
    rgba(91, 66, 188, 0.3);
}


/* ==========================================================
   GAME FOOTER
   ========================================================== */

.game-footer {
  display: flex;

  min-height: 45px;

  align-items: center;
  justify-content: center;

  padding:
    8px
    12px;

  border-top:
    1px solid
    #eeeaf6;

  background: #fcfbfe;
}

.legend {
  display: flex;

  flex-wrap: wrap;

  justify-content: center;

  gap:
    6px
    14px;

  color: #827a94;

  font-size: 0.7rem;

  font-weight: 700;
}

kbd {
  display: inline-block;

  margin:
    0
    2px;

  padding:
    2px
    5px;

  border:
    1px solid
    #ddd6ec;

  border-bottom-width: 2px;

  border-radius: 5px;

  color: #574b71;

  background: #ffffff;

  font-family: inherit;

  font-size: 0.65rem;

  font-weight: 900;
}


/* ==========================================================
   TOAST
   ========================================================== */

.toast {
  position: fixed;

  z-index: 100;

  left: 50%;
  bottom: 22px;

  width: max-content;

  max-width:
    calc(100% - 30px);

  transform:
    translateX(-50%);

  padding:
    10px
    15px;

  border-radius: 12px;

  color: #ffffff;

  background: #42375e;

  box-shadow:
    0 10px 30px
    rgba(37, 29, 57, 0.22);

  font-size: 0.8rem;

  font-weight: 900;

  text-align: center;
}

.toast.success {
  background: #3c8968;
}

.toast.error {
  background: #b8515c;
}

.toast.hidden {
  display: none;
}


/* ==========================================================
   EDUCATIONAL / SEO CONTENT
   ========================================================== */

.learn-strip {
  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  gap: 14px;

  margin-top: 30px;
}

.learn-card {
  padding: 20px;

  border:
    1px solid
    rgba(95, 72, 173, 0.1);

  border-radius: 18px;

  background:
    rgba(255, 255, 255, 0.76);

  box-shadow:
    0 8px 25px
    rgba(64, 48, 101, 0.06);
}

.learn-card-icon {
  display: grid;

  width: 38px;
  height: 38px;

  margin-bottom: 11px;

  place-items: center;

  border-radius: 10px;

  background: #eee9fa;

  font-size: 1.1rem;
}

.learn-card h2,
.learn-card h3 {
  margin:
    0
    0
    7px;

  color: #372d56;

  font-size: 1rem;

  font-weight: 900;
}

.learn-card p {
  margin: 0;

  color: #71697f;

  font-size: 0.8rem;

  font-weight: 600;

  line-height: 1.55;
}


/* ==========================================================
   SEO CONTENT SECTION
   ========================================================== */

.game-info {
  max-width: 900px;

  margin:
    38px
    auto
    0;

  padding:
    30px;

  border-radius: 22px;

  background: #ffffff;

  box-shadow:
    0 10px 35px
    rgba(59, 44, 96, 0.07);
}

.game-info h2 {
  margin:
    0
    0
    12px;

  color: #332850;

  font-size: clamp(
    1.5rem,
    3vw,
    2.1rem
  );

  font-weight: 900;
}

.game-info h3 {
  margin:
    26px
    0
    8px;

  color: #443660;

  font-size: 1.05rem;

  font-weight: 900;
}

.game-info p,
.game-info li {
  color: #6a6279;

  font-size: 0.92rem;

  font-weight: 600;

  line-height: 1.7;
}

.game-info ol,
.game-info ul {
  padding-left: 22px;
}

.game-info a {
  color: #654bc2;

  font-weight: 900;
}


/* ==========================================================
   TABLETS + SMALL LAPTOPS
   ========================================================== */

@media (max-width: 930px) {

  .page-shell {
    width: 100%;

    max-width: none;

    margin: 0;

    padding:
      8px
      8px
      30px;
  }


  .site-header {
    margin-bottom: 8px;

    padding:
      0
      4px;
  }


  /*
    Hide the large desktop hero while the game is in the
    compact viewport layout.

    SEO content remains in the HTML below the game.
  */

  .hero-copy {
    display: none;
  }


  .game-layout {
    display: block;

    width: 100%;

    min-height: 0;
  }


  .game-card {
    width: 100%;

    max-width: 720px;

    margin:
      0
      auto;

    border-radius: 18px;
  }


  .game-topbar {
    min-height: 52px;

    padding:
      6px
      8px;
  }


  .stat {
    min-width: 0;

    padding:
      5px
      8px;
  }


  .stat-label {
    font-size: 0.6rem;
  }


  .stat strong {
    font-size: 0.95rem;
  }


  .icon-button {
    width: 36px;
    height: 36px;

    border-radius: 10px;
  }


  .word-rack-wrap {
    min-height: 48px;

    padding:
      5px
      8px
      7px;

    gap: 7px;
  }


  .rack-label {
    margin-bottom: 2px;

    font-size: 0.6rem;
  }


  .word-rack {
    min-height: 29px;
  }


  .rack-tile {
    flex-basis: 30px;

    width: 30px;
    height: 30px;
  }


  .submit-button {
    min-width: 88px;

    padding:
      8px
      9px;

    border-radius: 10px;

    font-size: 0.8rem;
  }


  /*
    KEY RESPONSIVE RULE:

    The board uses whichever is smaller:
    available WIDTH or available HEIGHT.
  */

  .board-wrap {
    width: min(
      calc(100vw - 24px),
      calc(100dvh - 185px)
    );

    height: min(
      calc(100vw - 24px),
      calc(100dvh - 185px)
    );

    min-width: 0;
    min-height: 0;

    max-width: 672px;
    max-height: 672px;

    margin:
      0
      auto;

    aspect-ratio: 1 / 1;
  }


  #gameCanvas {
    width: 100%;
    height: 100%;
  }


  .game-footer {
    min-height: 38px;

    padding:
      6px
      8px;
  }


  .legend {
    gap:
      4px
      9px;

    font-size: 0.65rem;
  }


  kbd {
    padding:
      2px
      4px;

    font-size: 0.58rem;
  }


  .learn-strip {
    max-width: 720px;

    margin:
      18px
      auto
      0;
  }


  .game-info {
    max-width: 720px;

    margin-top: 18px;
  }

}


/* ==========================================================
   PHONES
   ========================================================== */

@media (max-width: 680px) {

  .page-shell {
    padding:
      5px
      5px
      24px;
  }


  .site-header {
    min-height: 34px;

    margin-bottom: 4px;
  }


  .brand {
    gap: 7px;

    font-size: 0.82rem;
  }


  .brand-mark {
    width: 29px;

    border-radius: 8px;

    font-size: 0.8rem;
  }


  .header-tag {
    display: none;
  }


  .game-card {
    border-radius: 14px;
  }


  .game-topbar {
    min-height: 46px;

    padding:
      4px
      6px;
  }


  .stat {
    padding:
      4px
      5px;
  }


  .stat-label {
    font-size: 0.53rem;
  }


  .stat strong {
    font-size: 0.85rem;
  }


  .icon-button {
    width: 32px;
    height: 32px;
  }


  .word-rack-wrap {
    min-height: 43px;

    padding:
      4px
      6px
      6px;
  }


  .rack-label {
    display: none;
  }


  .word-rack {
    min-height: 28px;
  }


  .rack-tile {
    flex-basis: 26px;

    width: 26px;
    height: 26px;

    font-size: 0.78rem;
  }


  .submit-button {
    min-width: 79px;

    padding:
      7px;

    font-size: 0.72rem;
  }


  /*
    PHONE BOARD:

    Reserve approximately 150px for the compact header,
    scoreboard, word rack and browser-safe spacing.
  */

  .board-wrap {
    width: min(
      calc(100vw - 14px),
      calc(100dvh - 150px)
    );

    height: min(
      calc(100vw - 14px),
      calc(100dvh - 150px)
    );

    margin:
      0
      auto;

    border-radius: 12px;
  }


  .game-footer {
    display: none;
  }


  /* START / GAME OVER OVERLAYS */

  .overlay {
    padding: 8px;
  }


  .overlay-card {
    width: min(
      320px,
      96%
    );

    max-height: 96%;

    padding:
      12px
      12px
      14px;

    border-radius: 16px;

    overflow-y: auto;
  }


  .overlay-icon {
    width: 40px;
    height: 40px;

    margin-bottom: 6px;

    border-radius: 11px;

    font-size: 1.2rem;
  }


  .overlay-kicker {
    margin-bottom: 2px;

    font-size: 0.58rem;
  }


  .overlay h2 {
    font-size: clamp(
      1.2rem,
      5vw,
      1.65rem
    );

    line-height: 1.05;
  }


  .overlay p:not(.overlay-kicker) {
    margin:
      6px
      auto
      10px;

    font-size: 0.75rem;

    line-height: 1.35;
  }


  .primary-button {
    padding:
      9px
      15px;

    border-radius: 10px;

    font-size: 0.82rem;
  }


  /*
    Supporting content moves beneath gameplay.
  */

  .learn-strip {
    grid-template-columns: 1fr;

    margin-top: 14px;
  }


  .learn-card {
    padding: 16px;
  }


  .game-info {
    margin-top: 14px;

    padding: 20px;

    border-radius: 17px;
  }

}


/* ==========================================================
   EXTRA-SHORT SCREENS
   ========================================================== */

@media (max-height: 620px) and (max-width: 930px) {

  /*
    Remove site header from extremely short viewports so
    gameplay always remains accessible.
  */

  .site-header {
    display: none;
  }


  .page-shell {
    padding: 4px;
  }


  .game-topbar {
    min-height: 42px;
  }


  .word-rack-wrap {
    min-height: 40px;
  }


  .board-wrap {
    width: min(
      calc(100vw - 12px),
      calc(100dvh - 92px)
    );

    height: min(
      calc(100vw - 12px),
      calc(100dvh - 92px)
    );
  }


  .overlay-icon,
  .overlay-kicker {
    display: none;
  }


  .overlay-card {
    padding: 10px;
  }


  .overlay h2 {
    font-size: 1.15rem;
  }


  .overlay p:not(.overlay-kicker) {
    margin:
      4px
      auto
      8px;

    font-size: 0.68rem;

    line-height: 1.25;
  }


  .primary-button {
    padding:
      7px
      12px;

    font-size: 0.76rem;
  }

}


/* ==========================================================
   REDUCED MOTION
   ========================================================== */

@media (
  prefers-reduced-motion:
  reduce
) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;

    transition-duration:
      0.01ms !important;

    animation-duration:
      0.01ms !important;

    animation-iteration-count:
      1 !important;
  }

}