/* ===== Thunder Farm — the page around the canvas ==============================
   The Finland game's teal and gold: a dark panel colour, a mint accent, the
   gold of the way-arrow for keys and messages. Sizes are in rem, and the base
   size follows the screen (as the game's pixels do). */

:root {
  --bg: #131b1a;
  --panel: #243330;
  --panel-edge: #3b5652;
  --text: #edf5f2;
  --accent: #8ad7bf;
  --gold: #ffd27a;
  --c-r: #e04848;
  --c-o: #f08a30;
  --c-y: #f2d040;
  --c-g: #4cb050;
  --c-b: #3c7ae0;
  --c-v: #9a5ad0;
}

html {
  font-size: clamp(100%, calc(100vmin / 67.5), 200%);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family:
    Inter,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    sans-serif;
  background: radial-gradient(circle at top, #1d2b2a, var(--bg));
  color: var(--text);
}

/* The canvas fills the screen; the HUD, the bubble and the controls float on top. */
.viewport {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0b1010;
  overflow: hidden;
  touch-action: none;
}

.viewport,
.viewport * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

.hidden {
  display: none !important;
}

kbd {
  font: inherit;
}

/* ===== The HUD ================================================================ */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.hud-corner {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 0.625rem);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.hud-top-left {
  left: max(0.625rem, env(safe-area-inset-left));
  max-width: calc(100% - 4rem);
}

.hud-top-right {
  right: max(0.625rem, env(safe-area-inset-right));
  pointer-events: auto;
}

.objective,
.hud-pill {
  border: 0.0625rem solid #4f6f6a;
  background: rgba(15, 24, 23, 0.82);
  border-radius: 62.4375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
  color: var(--text);
}

.objective {
  border-color: #8a6a2c;
  color: var(--gold);
}

.hud-pill {
  pointer-events: auto;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.hud-pill:hover,
.hud-pill:focus-visible,
.hud-btn:hover,
.hud-btn:focus-visible {
  border-color: var(--accent);
}

.hud-btn {
  pointer-events: auto;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 0.5rem;
  border: 0.0625rem solid #4f6f6a;
  background: rgba(15, 24, 23, 0.82);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1;
  cursor: pointer;
}

/* ===== The hint under the avatar's feet (ui/prompt.ts) ====================== */

.prompt {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0.4375rem;
  width: max-content;
  max-width: min(calc(100vw - 1.5rem), 22rem);
  background: var(--panel);
  border: 0.0625rem solid var(--panel-edge);
  border-radius: 0.625rem;
  padding: 0.3125rem 0.6875rem 0.375rem 0.4375rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 0.375rem 1.125rem rgba(0, 0, 0, 0.45);
  z-index: 2;
  pointer-events: none;
}

.prompt:not(.hidden) {
  animation: fade-in 0.25s ease-out;
}

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

.prompt kbd,
.chips-btn kbd,
.card-keys kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.4375rem;
  height: 1.4375rem;
  padding: 0 0.3125rem;
  border-radius: 0.3125rem;
  background: var(--gold);
  color: #2e200e;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0.125rem 0 #a97a2c;
}

/* ===== The Elves' bubble (ui/bubble.ts) ===================================== */

.bubble {
  position: fixed;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(calc(100vw - 1.5rem), 19rem);
  background: #f4f1e6;
  color: #1d2624;
  border: 0.125rem solid #2f4b44;
  border-radius: 0.75rem;
  padding: 0.4375rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 0.375rem 1.125rem rgba(0, 0, 0, 0.4);
  z-index: 3;
  pointer-events: none;
}

.bubble::after {
  content: '';
  position: absolute;
  left: var(--tail, 50%);
  bottom: -0.5rem;
  width: 0.75rem;
  height: 0.75rem;
  margin-left: -0.375rem;
  background: #f4f1e6;
  border-right: 0.125rem solid #2f4b44;
  border-bottom: 0.125rem solid #2f4b44;
  transform: rotate(45deg);
}

.bubble:not(.hidden) {
  animation: pop-in 0.18s ease-out;
}

@keyframes pop-in {
  from {
    opacity: 0;
    scale: 0.9;
  }
}

/* ===== The robot's program, as chips (ui/chips.ts) ========================== */

.chips {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 0.75rem);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: rgba(30, 64, 58, 0.94);
  border: 0.0625rem solid #5a9a8a;
  border-radius: 0.875rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.chips-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.chips-title {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chips-status {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3125rem;
  max-width: min(44rem, calc(100vw - 2.5rem));
}

/* The tutorial's labels over the chips need a line of their own. */
.chips.with-gains .chips-row {
  padding-top: 0.875rem;
  row-gap: 1.125rem;
}

.chip {
  position: relative;
  width: 2.125rem;
  height: 2.375rem;
  border-radius: 0.5rem;
  border: 0.125rem solid rgba(0, 0, 0, 0.35);
  background: var(--chip);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  text-shadow: 0 0.0625rem 0 rgba(0, 0, 0, 0.45);
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    inset 0 -0.1875rem 0 rgba(0, 0, 0, 0.25),
    0 0.125rem 0 rgba(0, 0, 0, 0.3);
  transition:
    transform 0.08s,
    opacity 0.2s;
  touch-action: manipulation;
}

.chip:hover,
.chip:focus-visible {
  transform: translateY(-0.125rem);
  outline: 0.125rem solid #fff;
  outline-offset: 0.0625rem;
}

.chip:active {
  transform: translateY(0.0625rem);
}

.chip:disabled {
  opacity: 0.18;
  cursor: default;
  transform: none;
  outline: none;
}

.chip[data-c='r'] {
  --chip: var(--c-r);
}
.chip[data-c='o'] {
  --chip: var(--c-o);
}
.chip[data-c='y'] {
  --chip: var(--c-y);
  color: #3a2a00;
  text-shadow: none;
}
.chip[data-c='g'] {
  --chip: var(--c-g);
}
.chip[data-c='b'] {
  --chip: var(--c-b);
}
.chip[data-c='v'] {
  --chip: var(--c-v);
}

/* How far it goes (the tutorial shows it). */
.chip-gain {
  position: absolute;
  left: 50%;
  top: -0.875rem;
  transform: translateX(-50%);
  padding: 0 0.25rem;
  border-radius: 0.25rem;
  background: #10201c;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  text-shadow: none;
  line-height: 1.2;
}

/* The tutorial's best chip glows; in the main round it wiggles after a while. */
.chip.best {
  box-shadow:
    0 0 0 0.1875rem var(--gold),
    0 0 0.875rem var(--gold);
}

.chip.wiggle {
  animation: wiggle 0.9s ease-in-out infinite;
}

@keyframes wiggle {
  0%,
  100% {
    rotate: 0deg;
  }
  20% {
    rotate: -9deg;
  }
  40% {
    rotate: 8deg;
  }
  60% {
    rotate: -5deg;
  }
  80% {
    rotate: 3deg;
  }
}

.chips-actions {
  display: flex;
  justify-content: center;
  gap: 0.625rem;
}

.chips-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  padding: 0.3125rem 0.75rem;
  border-radius: 62.4375rem;
  border: 0.0625rem solid #5a9a8a;
  background: rgba(15, 24, 23, 0.7);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.chips-retry {
  border-color: var(--gold);
  color: var(--gold);
}

.chips-btn:hover,
.chips-btn:focus-visible {
  border-color: var(--accent);
}

/* ===== The toast ============================================================== */

.toast {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 3.25rem);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19, 27, 26, 0.94);
  border: 0.0625rem solid #51706a;
  border-radius: 62.4375rem;
  padding: 0.5rem 1.125rem;
  font-size: 0.92rem;
  max-width: min(92vw, 35rem);
  width: max-content;
  text-align: center;
  z-index: 9;
  color: var(--gold);
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.toast-show {
  opacity: 1;
}

/* ===== The start and end cards ================================================ */

.card-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 10;
  background: rgba(8, 13, 13, 0.55);
}

.card {
  max-width: 28.75rem;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 0.0625rem solid var(--panel-edge);
  border-radius: 0.75rem;
  box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: fade-in 0.3s ease-out;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  padding: 1.375rem 1.375rem 1rem;
  overflow: auto;
}

.card p {
  margin: 0;
  line-height: 1.5;
}

.card-eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.card-title {
  margin: -0.375rem 0 0;
  font-size: 1.6rem;
  line-height: 1.2;
  color: var(--gold);
}

.card-keys {
  display: grid;
  gap: 0.4375rem;
  padding: 0.5625rem 0.75rem;
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.82rem;
  line-height: 1.7;
}

.card-keys kbd {
  height: 1.25rem;
  font-size: 0.72rem;
}

.card-keys .t {
  display: none;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem 0.875rem;
  flex-wrap: wrap;
  padding: 0.875rem 1.375rem 1.125rem;
  border-top: 0.0625rem solid #33504b;
}

.card-btn {
  padding: 0.625rem 1.5rem;
  border: 0.0625rem solid var(--accent);
  border-radius: 62.4375rem;
  background: var(--accent);
  color: #0f1817;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.card-btn:hover,
.card-btn:focus-visible {
  background: #a5e6d1;
}

.card-btn:focus-visible {
  outline: 0.125rem solid var(--text);
  outline-offset: 0.125rem;
}

.card-small {
  font-size: 0.82rem;
  opacity: 0.75;
}

/* ===== Touch: the thumbstick and the A button (input/touchControls.ts) ======= */

.touch-ui {
  position: fixed;
  left: max(0.625rem, env(safe-area-inset-left));
  right: max(0.625rem, env(safe-area-inset-right));
  bottom: max(0.625rem, env(safe-area-inset-bottom));
  z-index: 4;
  touch-action: none;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.stick {
  position: relative;
  width: 7.5rem;
  height: 7.5rem;
  border-radius: 50%;
  pointer-events: auto;
  border: 0.0625rem solid rgba(91, 133, 128, 0.9);
  background: radial-gradient(circle, rgba(36, 51, 48, 0.35) 0 34%, rgba(36, 51, 48, 0.72) 35% 100%);
  touch-action: none;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3.5rem;
  height: 3.5rem;
  margin: -1.75rem 0 0 -1.75rem;
  border-radius: 50%;
  border: 0.0625rem solid var(--accent);
  background: radial-gradient(circle at 36% 30%, #7aa59d, #2f4542 72%);
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.45);
  pointer-events: none;
  will-change: transform;
  transition: transform 0.12s ease-out;
}

.stick.is-active .stick-knob {
  transition: none;
  border-color: #c9f3e6;
}

.action-btn {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  border: 0.0625rem solid #5b8580;
  background: rgba(36, 51, 48, 0.9);
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
}

@media (hover: none), (pointer: coarse) {
  .touch-ui {
    display: flex;
  }

  .card-keys .k {
    display: none;
  }

  .card-keys .t {
    display: block;
  }

  /* At the console the chips are the controls: the stick steps aside. */
  body.at-console .touch-ui {
    display: none;
  }

  .chip {
    width: 2.375rem;
    height: 2.625rem;
  }
}

@media (max-width: 30rem) {
  .chip {
    width: 1.875rem;
    height: 2.25rem;
    font-size: 0.85rem;
  }
}

.noscript-note {
  padding: 1rem;
  color: #e8f0ee;
  font: 1rem system-ui;
}
