@font-face {
  font-family: 'Google Sans';
  src: url('/fonts/GoogleSans-500.ttf') format('truetype');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Google Sans';
  src: url('/fonts/GoogleSans-700.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

/* Lettumi's palette, with the tile colours deepened to stay readable on a projector. */
:root {
  color-scheme: light;
  --ink: #253247;
  --muted: #5b6880;
  --paper: #f5f7fb;
  --white: #ffffff;
  --purple: #635bd4;
  --purple-light: #eae9f8;
  --line: #d3dbe8;
  --correct: #7fcfa6;
  --present: #f2c65f;
  --absent: #c9c6d2;
  --error: #b3402f;
  --key: #e7e4ee;
  --gap: clamp(5px, 0.9dvh, 12px);
  --keyboard: clamp(190px, 37dvh, 440px);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font:
    500 16px/1.3 'Google Sans',
    system-ui,
    sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

button:focus-visible {
  outline: 4px solid var(--purple);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--keyboard);
  gap: clamp(8px, 1.6dvh, 20px);
  padding: clamp(8px, 1.6dvh, 20px) clamp(10px, 2vw, 40px);
  padding-bottom: max(clamp(8px, 1.6dvh, 20px), env(safe-area-inset-bottom));
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(10px, 2vw, 32px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand img {
  height: clamp(36px, 6dvh, 60px);
  width: auto;
}

.brand-name {
  font-size: clamp(24px, 4dvh, 40px);
  font-weight: 700;
  color: var(--purple);
}

.lengths {
  display: flex;
  gap: 6px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 5px;
}

.length {
  min-width: clamp(44px, 6dvh, 66px);
  min-height: clamp(44px, 6dvh, 60px);
  padding: 0 10px;
  border-radius: 12px;
  background: transparent;
  font-size: clamp(18px, 2.8dvh, 28px);
  font-weight: 700;
}

.length.on {
  background: var(--purple);
  color: var(--white);
}

.stats {
  display: flex;
  gap: clamp(14px, 2.5vw, 44px);
  margin: 0;
}

.stats div {
  text-align: center;
}

.stats dt {
  color: var(--muted);
  font-size: clamp(12px, 1.7dvh, 18px);
}

.stats dd {
  margin: 0;
  font-size: clamp(22px, 3.6dvh, 38px);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

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

.tool {
  min-height: clamp(44px, 6dvh, 60px);
  padding: 0 clamp(12px, 1.4vw, 24px);
  border-radius: 14px;
  background: var(--purple-light);
  color: var(--purple);
  font-size: clamp(15px, 2.2dvh, 22px);
  font-weight: 700;
  white-space: nowrap;
}

/* Stage */
.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr) minmax(0, 1fr);
  gap: clamp(12px, 2vw, 40px);
  align-items: center;
}

.board-area {
  height: 100%;
  min-width: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

.board {
  --size: min(
    calc((100cqh - 4 * var(--gap)) / 5),
    calc((100cqw - (var(--len) - 1) * var(--gap)) / var(--len))
  );
  display: grid;
  gap: var(--gap);
}

.row {
  display: flex;
  gap: var(--gap);
}

.tile {
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 14%;
  background: var(--white);
  border: 3px solid var(--line);
  font-size: calc(var(--size) * 0.56);
  font-weight: 700;
  line-height: 1;
}

.tile.active {
  border-color: #b8aee8;
}

.tile.given {
  color: var(--purple);
}

.tile.correct,
.key.correct {
  background: var(--correct);
  border-color: var(--correct);
}

.tile.present,
.key.present {
  background: var(--present);
  border-color: var(--present);
}

.tile.absent,
.key.absent {
  background: var(--absent);
  border-color: var(--absent);
}

.tile.flip {
  animation: flip 420ms ease-in-out var(--delay, 0ms) both;
}

@keyframes flip {
  0%,
  49% {
    background: var(--white);
    border-color: var(--line);
  }
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

.row.shake {
  animation: shake 360ms ease-in-out;
}

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

/* Side panels */
.side {
  min-width: 0;
}

.how {
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1dvh, 12px);
  align-items: flex-start;
}

.mascot {
  width: min(100%, 15dvh);
  height: auto;
}

.how h1 {
  margin: 0;
  font-size: clamp(20px, 3.2dvh, 36px);
}

.how p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 2dvh, 22px);
}

.legend {
  --size: clamp(30px, 5dvh, 52px);
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: clamp(14px, 2dvh, 22px);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.how .note {
  font-size: clamp(12px, 1.5dvh, 16px);
}

.result {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2dvh, 24px);
}

.message {
  margin: 0;
  font-size: clamp(20px, 3.4dvh, 38px);
  font-weight: 700;
  min-height: 2.6em;
}

.message[data-kind='error'] {
  color: var(--error);
}

.message[data-kind='won'] {
  color: #24794f;
}

.next {
  min-height: clamp(56px, 10dvh, 104px);
  border-radius: 18px;
  background: var(--purple);
  color: var(--white);
  font-size: clamp(22px, 3.6dvh, 40px);
  font-weight: 700;
}

/* Keyboard: full width and low on the screen, so students can reach it. */
.keyboard {
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
  max-width: 1700px;
  margin-inline: auto;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  min-height: 0;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  max-width: calc(100% / 10);
  border-radius: clamp(8px, 1.4dvh, 18px);
  background: var(--key);
  font-size: clamp(20px, 5.2dvh, 56px);
  font-weight: 700;
}

.key.wide {
  flex-grow: 1.7;
  max-width: calc(100% / 6);
  font-size: clamp(16px, 3.6dvh, 40px);
}

.key.enter {
  background: var(--purple);
  color: var(--white);
}

.key:active {
  filter: brightness(0.9);
}

/* Narrow or portrait screens: drop the side text and stack. */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .top {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 6px;
  }

  .brand-name,
  .tools #fullscreen,
  .how {
    display: none;
  }

  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .result {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .message {
    min-height: 0;
    font-size: 18px;
  }

  .next {
    min-height: 44px;
    padding: 0 18px;
    font-size: 18px;
  }

  .length {
    min-width: 40px;
  }

  :root {
    --keyboard: clamp(150px, 27dvh, 240px);
  }

  .key {
    font-size: clamp(16px, 3dvh, 26px);
  }

  .key.wide {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.flip,
  .row.shake {
    animation: none;
  }
}
