/* Raffe på rymmen – huvudstil */
/* Senast uppdaterad: 2026-07-30 21:15 | av: KlⒶssⓔ & Ⓐberg */

:root {
  --ink: #172319;
  --paper: #fffaf0;
  --grass-dark: #244f32;
  --leaf: #3f7f4f;
  --sun: #ffd166;
  --tomato: #d64b3f;
  --sky: #dff2ff;
  --panel: rgba(255, 250, 240, 0.96);
  --shadow: 0 18px 50px rgba(17, 38, 23, 0.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #173923;
  overscroll-behavior: none;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: ui-rounded, "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, rgba(255, 209, 102, 0.22), transparent 28rem),
    linear-gradient(155deg, #173923, #2f6841 52%, #163822);
  touch-action: manipulation;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 4px solid #0c69bf; outline-offset: 3px; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 1600px);
  margin: 0 auto;
  padding: clamp(8px, 1.5vw, 22px);
}

.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 30px);
  margin: 0 auto;
  overflow: hidden;
  border: clamp(4px, 0.7vw, 10px) solid rgba(255,255,255,.7);
  border-radius: clamp(18px, 2.4vw, 34px);
  background: #73b85b;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(25, 69, 35, .28);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #70b45a;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: clamp(12px, 3vw, 42px);
  background: linear-gradient(135deg, rgba(15, 43, 24, .78), rgba(26, 69, 36, .58));
  backdrop-filter: blur(5px);
}
.screen--visible { display: grid; }

/* Hjälpklass för rubriker som ska läsas av skärmläsare men inte synas. */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}


/*
 * Två rena gränssnittslägen:
 * - device-mobile: pekstyrning och mobil layout
 * - device-desktop: tangentbord och desktop layout
 * Klassen sätts i <head> innan CSS-filen laddas.
 */
.mobile-only,
.desktop-only { display: none; }
html.device-mobile .mobile-only { display: revert; }
html.device-desktop .desktop-only { display: revert; }

html.device-mobile,
html.device-mobile body {
  width: 100%;
  min-height: 100%;
  overflow: hidden;
}

html.device-desktop .mobile-controls,
html.device-desktop .orientation-hint {
  display: none !important;
}

/* Startskärmen använder den färdiga 16:9-bilden som heltäckande huvudmotiv. */
.start-screen {
  padding: 0;
  place-items: stretch;
  overflow: hidden;
  background: #142f1c;
  backdrop-filter: none;
}

.start-screen__image {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
}

/* Mjuk mörkning längst ned gör knapparna tydliga utan att gömma motivet. */
.start-screen__shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(to bottom, transparent 52%, rgba(7, 18, 10, .15) 68%, rgba(7, 18, 10, .84) 100%);
  pointer-events: none;
}

.start-screen__controls {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: clamp(12px, 2.4vw, 28px);
  width: min(760px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: clamp(10px, 1.7vw, 18px) clamp(12px, 2.4vw, 24px);
  border: 2px solid rgba(255, 255, 255, .45);
  border-radius: 22px;
  background: rgba(20, 43, 25, .72);
  box-shadow: 0 16px 36px rgba(0, 0, 0, .36);
  backdrop-filter: blur(8px);
  text-align: center;
}

.start-screen__tagline {
  margin: 0;
  color: #fff;
  font-size: clamp(.82rem, 1.6vw, 1.12rem);
  font-weight: 900;
  text-shadow: 0 2px 5px rgba(0, 0, 0, .55);
}

.start-screen__buttons,
.start-screen__settings {
  justify-content: center;
}

.start-screen__buttons {
  margin-top: clamp(8px, 1.2vw, 12px);
}

.start-screen__settings {
  margin-top: 10px;
}

.start-screen__controls .toggle-button {
  min-height: 38px;
  padding: 6px 11px;
  background: rgba(255, 255, 255, .94);
}

.panel {
  width: min(1050px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(22px, 4vw, 52px);
  border: 3px solid rgba(255,255,255,.76);
  border-radius: clamp(20px, 3vw, 38px);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel--small { width: min(520px, 100%); text-align: center; }

.menu-panel,
.instructions-panel,
.result-panel {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  align-items: center;
  gap: clamp(22px, 4vw, 56px);
}

.eyebrow {
  margin: 0 0 .35rem;
  color: #376343;
  font-size: clamp(.76rem, 1.4vw, 1rem);
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: .97; letter-spacing: -.04em; }
h1 { font-size: clamp(2.15rem, 6.3vw, 5.4rem); }
h2 { font-size: clamp(2rem, 4.5vw, 4.2rem); }
.subtitle { margin: .25rem 0 1rem; color: var(--tomato); font-size: clamp(1.35rem, 3vw, 2.7rem); font-weight: 950; }
.lead, .result-message { font-size: clamp(1rem, 1.9vw, 1.35rem); line-height: 1.48; }

.hero-art { position: relative; align-self: end; text-align: center; }
.hero-art img { display: block; width: 100%; max-height: 48vh; object-fit: contain; filter: drop-shadow(0 14px 12px rgba(26, 33, 20, .25)); }
.hero-caption { display: inline-block; margin-top: -4px; padding: 8px 15px; border-radius: 999px; background: #233d2a; color: #fff; font-weight: 800; transform: rotate(-2deg); }
.instructions-art, #result-art { width: 100%; max-height: 44vh; object-fit: contain; filter: drop-shadow(0 12px 10px rgba(30, 35, 20, .2)); }

.button-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.4rem; }
.button, .toggle-button, .icon-button, .snore-button {
  border: 0;
  cursor: pointer;
  font-weight: 900;
}
.button {
  min-height: 50px;
  padding: 12px 22px;
  border-radius: 15px;
  box-shadow: 0 6px 0 rgba(33, 54, 37, .24);
  transition: transform .12s ease, box-shadow .12s ease;
}
.button:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(33, 54, 37, .2); }
.button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(33, 54, 37, .2); }
.button--primary { background: var(--sun); color: #332500; }
.button--secondary { background: #e8eee7; color: #213927; }

.settings-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.toggle-button {
  min-height: 44px;
  padding: 9px 13px;
  border: 2px solid #b7c9b9;
  border-radius: 999px;
  background: #fff;
  color: #213927;
}

.instruction-list { padding-left: 1.25rem; line-height: 1.5; }
.instruction-list li { margin: .72rem 0; }
kbd { padding: 2px 7px; border: 1px solid #94a79a; border-bottom-width: 3px; border-radius: 6px; background: #fff; font-weight: 800; }
.keyboard-tip { color: #3e5544; }
.stacked-buttons { display: grid; gap: 12px; margin-top: 22px; }

.loader { width: 58px; height: 58px; margin: 0 auto 16px; border: 8px solid rgba(44, 96, 57, .2); border-top-color: #2c6039; border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hud {
  position: absolute;
  inset: 12px 12px auto;
  z-index: 14;
  display: none;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  pointer-events: none;
}
.hud--visible { display: grid; }
.hud-group { display: flex; flex-wrap: wrap; gap: 7px; }
.hud-group--right { justify-content: flex-end; }
.hud-pill, .snacks-hud {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border: 2px solid rgba(255,255,255,.82);
  border-radius: 999px;
  background: rgba(21, 51, 28, .88);
  color: #fff;
  box-shadow: 0 5px 14px rgba(0,0,0,.16);
  font-weight: 900;
  font-size: clamp(.72rem, 1.35vw, 1rem);
  white-space: nowrap;
}
.hud-pill--ability.is-cooling { background: rgba(109, 49, 42, .9); }
.hud-level { color: #ffe49a; }
.snacks-hud { justify-self: center; font-size: clamp(1rem, 2vw, 1.35rem); }
.snacks-hud span { transition: opacity .18s ease, transform .18s ease; }
.snacks-hud span.is-collected { opacity: .28; filter: grayscale(1); transform: scale(.78); }
.icon-button {
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255,255,255,.82);
  border-radius: 50%;
  background: rgba(21, 51, 28, .92);
  color: #fff;
  pointer-events: auto;
}

.result-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin: 18px 0 0; }
.result-stats div { padding: 11px; border-radius: 14px; background: #eef3e9; }
.result-stats dt { color: #55715c; font-size: .82rem; font-weight: 800; text-transform: uppercase; }
.result-stats dd { margin: 3px 0 0; font-size: 1.3rem; font-weight: 950; }

.mobile-controls {
  position: absolute;
  right: 12px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 18;
  display: none;
  align-items: end;
  pointer-events: none;
}

.touch-stick {
  position: absolute;
  z-index: 19;
  display: none;
  width: 76px;
  height: 76px;
  margin: -38px 0 0 -38px;
  place-items: center;
  border: 2px solid rgba(255,255,255,.82);
  border-radius: 50%;
  background: rgba(19, 49, 27, .35);
  box-shadow: 0 4px 18px rgba(0,0,0,.2);
  pointer-events: none;
}
.touch-stick.is-active { display: grid; }
.touch-stick__knob {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 50%;
  background: rgba(214, 75, 63, .94);
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.snore-button {
  width: 94px;
  height: 94px;
  display: grid;
  place-content: center;
  border: 4px solid rgba(255,255,255,.86);
  border-radius: 50%;
  background: rgba(255, 209, 102, .92);
  color: #372b0b;
  box-shadow: 0 7px 0 rgba(74, 54, 13, .35);
  pointer-events: auto;
  touch-action: none;
}
.snore-button span { font-size: 1.4rem; font-weight: 950; }
.snore-button small { font-size: .62rem; }
.snore-button:active, .snore-button.is-active { transform: translateY(5px); box-shadow: 0 2px 0 rgba(74, 54, 13, .35); }
.snore-button.is-cooling { background: rgba(214, 224, 209, .9); color: #4b5c4e; }

.orientation-hint {
  position: absolute;
  z-index: 17;
  left: 50%;
  bottom: 8px;
  display: none;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(20, 47, 27, .88);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  white-space: nowrap;
}

.text-instructions {
  margin: 14px auto 0;
  padding: 16px 20px;
  border-radius: 18px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 10px 24px rgba(8, 31, 15, .18);
}
.text-instructions h2 { font-size: 1.2rem; letter-spacing: -.01em; }
.text-instructions p { margin: 7px 0 0; line-height: 1.55; }

/* Mobilkontroller visas endast när enheten faktiskt klassats som mobil. */
html.device-mobile .mobile-controls.mobile-controls--visible { display: flex; }
html.device-mobile .game-frame { max-height: none; }
html.device-mobile .text-instructions { display: none; }

/* Mobil i stående läge använder hela skärmen; rörelsen sker direkt på Canvas. */
@media (orientation: portrait) {
  html.device-mobile .app-shell {
    width: 100vw;
    height: 100dvh;
    padding: 4px;
  }

  html.device-mobile .game-frame {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    border-width: 4px;
    border-radius: 18px;
    background: #173923;
  }

  html.device-mobile #game-canvas {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    transform: translateY(-50%);
  }

  html.device-mobile .start-screen__image {
    object-fit: contain;
    object-position: center 12%;
  }

  html.device-mobile .start-screen__shade {
    background: linear-gradient(to bottom, transparent 33%, rgba(7, 18, 10, .18) 54%, rgba(7, 18, 10, .92) 100%);
  }

  html.device-mobile .start-screen__controls {
    bottom: calc(12px + var(--safe-bottom));
    width: calc(100% - 16px);
    padding: 12px 10px;
    border-radius: 17px;
  }

  html.device-mobile .start-screen__tagline { font-size: .78rem; }

  html.device-mobile .start-screen__buttons,
  html.device-mobile .start-screen__settings { gap: 7px; }

  html.device-mobile .start-screen__controls .button {
    min-height: 43px;
    padding: 9px 13px;
  }

  html.device-mobile .start-screen__controls .toggle-button {
    min-height: 34px;
    padding: 5px 9px;
    font-size: .76rem;
  }

  html.device-mobile .orientation-hint.orientation-hint--visible {
    display: block;
    bottom: calc(164px + var(--safe-bottom));
  }

  html.device-mobile .menu-panel,
  html.device-mobile .instructions-panel,
  html.device-mobile .result-panel {
    grid-template-columns: 1fr;
    text-align: center;
  }

  html.device-mobile .hero-art img,
  html.device-mobile .instructions-art,
  html.device-mobile #result-art { max-height: 23vh; }

  html.device-mobile .button-row,
  html.device-mobile .settings-row { justify-content: center; }

  html.device-mobile .panel { padding: 20px; }
  html.device-mobile .hud { inset: 7px 7px auto; grid-template-columns: 1fr auto; }
  html.device-mobile .hud-group--left { max-width: 75%; }
  html.device-mobile .hud-group--right { grid-column: 2; grid-row: 1; }
  html.device-mobile .snacks-hud { grid-column: 1 / -1; grid-row: 2; }
  html.device-mobile .hud-pill { min-height: 32px; padding: 5px 8px; }
  html.device-mobile .hud-level #level-name { display: none; }
  html.device-mobile .snore-button { width: 84px; height: 84px; }
}

/* Mobil i liggande läge använder hela skärmens bredd och kompakta kontroller. */
@media (max-height: 700px) and (orientation: landscape) {
  html.device-mobile .app-shell { padding: 4px; }
  html.device-mobile .game-frame { max-height: calc(100vh - 8px); width: auto; }
  html.device-mobile .panel { padding: 16px 22px; }
  html.device-mobile .hero-art img,
  html.device-mobile .instructions-art,
  html.device-mobile #result-art { max-height: 38vh; }
  html.device-mobile .lead { margin: .45rem 0; font-size: .92rem; }
  html.device-mobile .button-row { margin-top: .65rem; }
  html.device-mobile .settings-row { margin-top: 9px; }
  html.device-mobile .snore-button { width: 76px; height: 76px; }

  html.device-mobile .start-screen__controls {
    bottom: 7px;
    width: min(720px, calc(100% - 16px));
    padding: 7px 12px;
    border-radius: 16px;
  }

  html.device-mobile .start-screen__tagline { display: none; }
  html.device-mobile .start-screen__buttons { margin-top: 0; }
  html.device-mobile .start-screen__settings { margin-top: 6px; }
  html.device-mobile .start-screen__controls .button { min-height: 40px; padding: 8px 14px; }
  html.device-mobile .start-screen__controls .toggle-button { min-height: 32px; padding: 4px 9px; font-size: .74rem; }
}

/* Desktop behåller alltid desktopgränssnittet, även i ett smalt webbläsarfönster. */
html.device-desktop .game-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
}

@media (max-height: 560px) and (orientation: landscape) {
  html.device-desktop .app-shell { padding: 4px; }
  html.device-desktop .game-frame { max-height: calc(100vh - 8px); width: auto; }
  html.device-desktop .panel { padding: 16px 22px; }
  html.device-desktop .start-screen__controls {
    bottom: 7px;
    width: min(720px, calc(100% - 16px));
    padding: 7px 12px;
    border-radius: 16px;
  }
  html.device-desktop .start-screen__tagline { display: none; }
  html.device-desktop .start-screen__buttons { margin-top: 0; }
  html.device-desktop .start-screen__settings { margin-top: 6px; }
  html.device-desktop .start-screen__controls .button { min-height: 40px; padding: 8px 14px; }
  html.device-desktop .start-screen__controls .toggle-button { min-height: 32px; padding: 4px 9px; font-size: .74rem; }
  html.device-desktop .text-instructions { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}


/* Dynamisk viewport-höjd ger bättre passform när mobilens adressfält visas/döljs. */
@supports (height: 100dvh) {
  html.device-mobile,
  html.device-mobile body { min-height: 100dvh; }

  @media (max-height: 700px) and (orientation: landscape) {
    html.device-mobile .game-frame { max-height: calc(100dvh - 8px); }
  }
}
