/* ------------------------------------------------------------------ *
 * Get Keenan
 * ------------------------------------------------------------------ */

:root {
  --nd-navy: #0c2340;
  --nd-gold: #c99700;

  --ink: #2b2b2b;
  --ink-soft: #6f6f6f;
  --page-bg: #faf8f2;

  --board-bg: #9a9a9a;
  --cell-bg: #c6c6c6;

  /* Everything on the board is derived from these two, so the whole thing
     scales as one unit and the tile maths stays exact. */
  --board-size: min(92vw, 460px);
  --gap: calc(var(--board-size) * 0.026);
  --cell-size: calc((var(--board-size) - 5 * var(--gap)) / 4);
  --radius: calc(var(--board-size) * 0.018);

  --shift: calc(var(--cell-size) + var(--gap));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page-bg);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;

  /* Stops the page rubber-banding while you swipe the board on iOS. */
  overscroll-behavior: none;
}

.page {
  width: var(--board-size);
  margin: 0 auto;
  padding: clamp(16px, 5vw, 40px) 0 32px;
}

/* --- header ------------------------------------------------------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  /* "GetKeenan" plus both score boxes will not fit on a narrow phone, so the
     header is allowed to wrap rather than push the page sideways. */
  flex-wrap: wrap;
}

.title {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--nd-navy);
}

.title span {
  color: var(--nd-gold);
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--board-bg);
  color: #fff;
}

.score-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.score-value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
}

.tagline {
  margin: 20px 0 0;
  font-size: clamp(1rem, 4vw, 1.2rem);
  color: var(--ink);
}

.tagline strong {
  color: var(--nd-navy);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 16px 0 12px;
}

/* --- buttons ------------------------------------------------------ */

.button {
  padding: 10px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--board-bg);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}

.button:hover {
  background: #868686;
}

.button:active {
  transform: translateY(1px);
}

.button-primary {
  background: var(--nd-navy);
}

.button-primary:hover {
  background: #16345c;
}

.button:focus-visible {
  outline: 3px solid var(--nd-gold);
  outline-offset: 2px;
}

/* --- board -------------------------------------------------------- */

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: var(--gap);
  border-radius: calc(var(--radius) * 2);
  background: var(--board-bg);

  /* The board owns all touch gestures so a swipe never scrolls the page. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cells {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--gap);
}

.cell {
  border-radius: var(--radius);
  background: var(--cell-bg);
}

.tiles {
  position: absolute;
  inset: var(--gap);
}

/* --- tiles -------------------------------------------------------- */

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  transform: translate(
    calc(var(--c) * var(--shift)),
    calc(var(--r) * var(--shift))
  );
  transition: transform 110ms ease-in-out;
}

.tile-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--tile-color, #eee);
}

/* The crest sits on top of the abbreviation, so if the image is missing or
   fails to load we fall back to text without any extra scripting. */
.tile-abbr {
  padding: 0 4px;
  color: #fff;
  font-size: calc(var(--cell-size) * 0.2);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.1;
}

/* The arms are shield-shaped (roughly 410x478), so they are contained rather
   than cropped, on a light plate that keeps every hall's heraldry legible. */
.tile-crest {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 7%;
  object-fit: contain;
  background: #f4f2ec;
}

.tile-crest[hidden] {
  display: none;
}

/* Winning tile gets a gold ring so Keenan reads as the prize. */
.tile[data-win="true"] .tile-inner {
  box-shadow: inset 0 0 0 calc(var(--cell-size) * 0.045) var(--nd-gold);
}

@keyframes tile-appear {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes tile-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.16);
  }
  100% {
    transform: scale(1);
  }
}

.tile-new .tile-inner {
  animation: tile-appear 130ms ease-out;
}

.tile-merged .tile-inner {
  animation: tile-pop 150ms ease-in-out;
}

/* --- game over overlay -------------------------------------------- */

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) * 2);
  background: rgba(250, 248, 242, 0.86);
  z-index: 5;
  animation: tile-appear 200ms ease-out;
}

.board-overlay[hidden] {
  display: none;
}

.board-overlay-inner {
  text-align: center;
}

.board-overlay h2 {
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  color: var(--nd-navy);
}

.board-overlay p {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

/* --- dorm popup --------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 35, 64, 0.62);
  animation: fade-in 140ms ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-card {
  position: relative;
  width: min(100%, 440px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  text-align: center;
  animation: card-in 180ms ease-out;
}

.modal-kicker {
  margin: 0 0 12px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nd-gold);
}

.modal-photo {
  margin: 0 0 16px;
  border-radius: 10px;
  overflow: hidden;
  background: #ececec;
  aspect-ratio: 3 / 2;
}

/* Collapses cleanly when no photo has been supplied yet. */
.modal-photo[hidden] {
  display: none;
}

.modal-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-name {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  color: var(--nd-navy);
}

.modal-fact {
  margin: 0 0 20px;
  font-size: 1rem;
  line-height: 1.55;
  text-align: left;
  color: var(--ink);
  white-space: pre-line;
}

.modal-button {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
}

/* Keenan's popup is the win screen. */
.modal.is-win .modal-card {
  background: var(--nd-navy);
  color: #fff;
}

.modal.is-win .modal-name {
  color: var(--nd-gold);
}

.modal.is-win .modal-fact {
  color: rgba(255, 255, 255, 0.92);
}

.modal.is-win .modal-button {
  background: var(--nd-gold);
  color: var(--nd-navy);
}

.modal.is-win .modal-button:hover {
  background: #dcaa10;
}

/* --- how to play / credits ---------------------------------------- */

.about {
  margin-top: 24px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink);
}

.about p {
  margin: 0;
}

.about strong {
  color: var(--nd-navy);
}

.rule {
  height: 0;
  margin: 14px 0;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
}

.about a {
  color: var(--nd-navy);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.about a:hover {
  color: var(--nd-gold);
}

.about a:focus-visible {
  outline: 3px solid var(--nd-gold);
  outline-offset: 2px;
  border-radius: 2px;
}

.colophon {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
