/* Hamster Friendship: The Lost Alice. Site and game chrome styles. */

:root {
  /* Primitives: named by hue. Components never use these directly. */
  --bark-950: #1a110b;
  --bark-900: #26180f;
  --bark-800: #352216;
  --bark-700: #563823;
  --bark-600: #7a5233;
  --cream-50: #fbf3e4;
  --cream-200: #e6d3b5;
  --amber-400: #f2a93b;
  --amber-300: #f8c878;
  --amber-200: #fbdba6;
  --berry-400: #e9735f;

  /* Semantic roles. */
  --color-bg: var(--bark-950);
  --color-surface: var(--bark-900);
  --color-surface-raised: var(--bark-800);
  --color-border: var(--bark-700);
  --color-border-strong: var(--bark-600);
  --color-text: var(--cream-50);
  --color-text-muted: var(--cream-200);
  --color-accent: var(--amber-400);
  --color-accent-hover: var(--amber-300);
  --color-on-accent: var(--bark-950);
  --color-focus: var(--amber-200);
  --color-health: var(--berry-400);
  --color-overlay: rgb(26 17 11 / 0.84);

  /* Type: two families, two weights, five sizes (four per breakpoint). */
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.5rem;

  /* Spacing steps. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --stage-max: 960px;
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.5;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.1;
  text-wrap: balance;
  margin: 0;
}

h1 {
  font-size: var(--text-xl);
}

h2 {
  font-size: var(--text-lg);
}

p {
  margin: 0;
}

a {
  color: var(--color-accent);
  text-underline-offset: 0.2em;
  text-decoration-thickness: from-font;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  inset-block-start: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: 700;
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: none;
}

/* Layout primitive: centred column with mobile inline margins. */
.page {
  width: 100%;
  max-width: calc(var(--stage-max) + 2 * var(--space-4));
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.site-header {
  padding-block: var(--space-4) var(--space-3);
}

.lede {
  margin-block-start: var(--space-2);
  max-width: 60ch;
  color: var(--color-text-muted);
  text-wrap: pretty;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-md);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition-property: background-color, color, scale;
  transition-duration: 150ms;
  transition-timing-function: var(--ease-out);
}

.btn:active {
  scale: 0.96;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.btn-secondary {
  background: var(--color-surface-raised);
  color: var(--color-text);
  box-shadow: inset 0 0 0 1px var(--color-border-strong);
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--color-accent-hover);
  }

  .btn-secondary:hover {
    background: var(--color-border);
  }
}

.btn-small {
  min-height: 40px;
  padding: 8px 14px;
}

kbd {
  display: inline-block;
  min-width: 1.9em;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  box-shadow: inset 0 -2px 0 var(--color-border-strong);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
}

/* Game block */
.game {
  display: grid;
  gap: var(--space-2);
  padding-block-end: var(--space-4);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  width: 100%;
  max-width: var(--stage-max);
  margin-inline: auto;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-sm);
}

.hud-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.hud-value {
  color: var(--color-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  flex: none;
}

.hearts {
  display: inline-flex;
  gap: 3px;
}

.heart {
  width: 14px;
  height: 12px;
  fill: var(--color-health);
  opacity: 0.25;
}

.heart.is-full {
  opacity: 1;
}

.hud-bar {
  position: relative;
  display: inline-block;
  width: 96px;
  height: 10px;
  border-radius: 999px;
  background: var(--color-surface-raised);
  overflow: hidden;
}

.hud-bar-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  background: var(--color-health);
  transition-property: width;
  transition-duration: 150ms;
}

.hud-pause {
  margin-inline-start: auto;
}

/* Stage: canvas and screens share one grid cell, so a screen taller than
   the canvas grows the stage instead of being clipped. */
.stage {
  position: relative;
  display: grid;
  width: 100%;
  max-width: var(--stage-max);
  margin-inline: auto;
  border-radius: var(--radius-lg);
  background: #2e2245;
  overflow: hidden;
}

.stage > * {
  grid-area: 1 / 1;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 3;
  align-self: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: manipulation;
}

.overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-overlay);
  text-align: center;
  z-index: 5;
}

.overlay[hidden],
.dialogue[hidden] {
  display: none;
}

.overlay-text {
  max-width: 34ch;
  color: var(--color-text-muted);
  text-wrap: pretty;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin-block-start: var(--space-1);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-5);
  margin: 0;
}

.stats div {
  display: flex;
  gap: var(--space-2);
}

.stats dt {
  color: var(--color-text-muted);
}

.stats dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dialogue {
  align-self: end;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--space-1) var(--space-3);
  margin: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: inset 0 0 0 2px var(--color-border-strong);
}

.dialogue-name {
  grid-column: 1 / -1;
  color: var(--color-accent);
  font-weight: 700;
}

.dialogue-text {
  max-width: 62ch;
  text-wrap: pretty;
}

.dialogue-actions {
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: var(--space-1);
}

.dialogue-hint {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.toast {
  align-self: start;
  justify-self: center;
  z-index: 4;
  margin-block-start: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition-property: opacity;
  transition-duration: 150ms;
}

.toast.is-visible {
  opacity: 1;
}

.toast:empty {
  padding: 0;
}

/* Touch controls: shown on narrow or touch screens. */
.touchpad {
  display: none;
  justify-content: space-between;
  gap: var(--space-4);
  width: 100%;
  max-width: var(--stage-max);
  margin-inline: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pad-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pad-group-actions {
  justify-content: flex-end;
  max-width: 220px;
}

.pad-btn {
  min-width: 52px;
  min-height: 48px;
  padding: 8px 10px;
  touch-action: none;
}

.pad-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.pad-btn.is-pressed {
  background: var(--color-border);
  scale: 0.96;
}

.pad-hint {
  width: 100%;
  max-width: var(--stage-max);
  margin-inline: auto;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.pad-hint-touch {
  display: none;
}

@media (max-width: 52rem), (pointer: coarse) {
  .touchpad {
    display: flex;
  }

  .pad-hint-keys {
    display: none;
  }

  .pad-hint-touch {
    display: block;
  }
}

/* Info section below the game */
.info {
  display: grid;
  gap: var(--space-6);
  padding-block: var(--space-6) var(--space-7);
}

.info h2 {
  margin-block-end: var(--space-3);
}

.info p + p {
  margin-block-start: var(--space-3);
}

.prose {
  max-width: 62ch;
  color: var(--color-text-muted);
}

.controls {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.controls dt {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-weight: 700;
}

.controls dd {
  margin: 0;
  color: var(--color-text-muted);
}

.tips {
  margin: var(--space-4) 0 0;
  padding-inline-start: 1.25em;
  color: var(--color-text-muted);
}

.tips li + li {
  margin-block-start: var(--space-1);
}

.site-footer {
  padding-block: var(--space-5);
  border-block-start: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

@media (min-width: 48rem) {
  h1 {
    font-size: var(--text-2xl);
  }

  .site-header {
    padding-block: var(--space-6) var(--space-4);
  }

  .info {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-7);
  }
}

@media (max-width: 22rem) {
  .controls {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .controls dd {
    margin-block-end: var(--space-2);
  }
}

@media (forced-colors: active) {
  .btn,
  .hud,
  .dialogue {
    border: 1px solid CanvasText;
  }
}
