:root {
  --paper: #f7e7d4;
  --peach: #f6d8d3;
  --rose: #e9aab7;
  --mint: #b9dfd4;
  --aqua: #b7dff0;
  --violet: #4d355e;
  --ink: #2f2b35;
  --softInk: rgba(47, 43, 53, 0.72);
  --theme-bg-a: #f9ded7;
  --theme-bg-b: #f4e6c9;
  --theme-bg-c: #d9eee3;
  --theme-aura-a: rgba(183, 223, 240, 0.50);
  --theme-aura-b: rgba(233, 170, 183, 0.42);
  --theme-aura-c: rgba(185, 223, 212, 0.40);
  --theme-primary: #4d355e;
  --theme-primary-soft: rgba(77, 53, 94, 0.72);
  --theme-primary-faint: rgba(77, 53, 94, 0.18);
  --theme-secondary: #78b8b1;
  --theme-secondary-soft: rgba(120, 184, 177, 0.32);
  --theme-panel: rgba(255, 245, 232, 0.46);
  --theme-panel-strong: rgba(255, 245, 232, 0.78);
  --theme-button-mid: rgba(233, 170, 183, 0.78);
  --theme-button-end: rgba(185, 223, 212, 0.80);
  --theme-glow: rgba(255, 213, 108, 0.42);
  --theme-beam: #2d1d36;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.62), transparent 28%),
    radial-gradient(circle at 82% 18%, var(--theme-aura-a), transparent 27%),
    radial-gradient(circle at 18% 86%, var(--theme-aura-b), transparent 32%),
    radial-gradient(circle at 84% 84%, var(--theme-aura-c), transparent 30%),
    linear-gradient(135deg, var(--theme-bg-a) 0%, var(--theme-bg-b) 45%, var(--theme-bg-c) 100%);
  color: var(--ink);
  transition: background 520ms ease;
  font-family: "Marcellus", Georgia, serif;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
}

#appShell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  isolation: isolate;
  transition: filter 380ms ease;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.gameStart {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  text-align: center;
  overflow: hidden;
}

.gameStart::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.24) 34%, transparent 64%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(246, 216, 211, 0.28) 48%, rgba(214, 237, 232, 0.24));
  backdrop-filter: blur(22px) saturate(1.22);
  -webkit-backdrop-filter: blur(22px) saturate(1.22);
}

.gameStart::after {
  content: "";
  position: absolute;
  inset: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  z-index: -1;
  border: 1px solid rgba(77, 53, 94, 0.16);
  border-radius: clamp(30px, 7vw, 72px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.16) 42%, rgba(222, 244, 238, 0.20)),
    radial-gradient(circle at 50% 38%, rgba(255, 255, 255, 0.38), transparent 54%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.58),
    inset 0 -1px 0 rgba(77, 53, 94, 0.06),
    0 28px 72px rgba(77, 53, 94, 0.13);
}

.gameStart > * {
  position: relative;
  z-index: 1;
}

.startMark,
.resultKicker,
.statusText {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: clamp(10px, 2.5vw, 13px);
  font-weight: 400;
  color: var(--theme-primary-soft);
}

.startTitle {
  margin: 0;
  font-family: "Ole", cursive;
  font-size: clamp(96px, 25vw, 220px);
  line-height: 0.80;
  letter-spacing: -0.058em;
  font-weight: 400;
  color: var(--theme-primary);
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.82),
    0 18px 42px rgba(109, 74, 102, 0.20);
}

.startSubtitle {
  margin: clamp(4px, 1.5vw, 10px) 0 clamp(24px, 5vw, 38px);
  font-family: "Marcellus", Georgia, serif;
  font-size: clamp(12px, 3.2vw, 18px);
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: var(--theme-primary-soft);
}


.gameButton {
  cursor: pointer;
  border: 2px solid var(--theme-primary-faint);
  border-radius: 999px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), var(--theme-button-mid) 52%, var(--theme-button-end));
  box-shadow:
    0 16px 0 rgba(47, 43, 53, 0.10),
    0 18px 34px rgba(94, 73, 95, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.80);
  color: var(--theme-primary);
  font-weight: 400;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  transform: translateY(0);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.gameButton:active {
  transform: translateY(5px);
  box-shadow:
    0 9px 0 rgba(47, 43, 53, 0.10),
    0 10px 22px rgba(94, 73, 95, 0.16),
    inset 0 2px 0 rgba(255, 255, 255, 0.80);
}

.bigButton {
  min-width: min(76vw, 270px);
  height: clamp(52px, 9vw, 64px);
  padding: 0 28px;
  font-size: clamp(13px, 3.4vw, 17px);
}

.smallButton {
  min-height: 46px;
  padding: 0 18px;
  font-size: 13px;
}

.soundButton {
  min-width: 104px;
  padding-inline: 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.90), var(--theme-button-end) 48%, var(--theme-button-mid));
}

.soundButton.isMuted {
  opacity: 0.66;
}

.bottomControls {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.iconButton {
  min-height: 46px;
  min-width: 78px;
  padding: 0 14px;
  font-size: 11px;
  letter-spacing: 0.09em;
}

.soundOff {
  opacity: 0.62;
}

.gameHud {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  min-height: clamp(188px, 32vh, 320px);
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 28px max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  overflow: hidden;
  animation: hudRevealIn 720ms cubic-bezier(0.18, 0.82, 0.22, 1) both;
}

.gameHud::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), var(--theme-panel-strong) 46%, var(--theme-secondary-soft) 76%, rgba(255, 255, 255, 0.06)),
    radial-gradient(circle at 50% 26%, rgba(255, 255, 255, 0.68), var(--theme-glow) 46%, transparent 72%);
  border-bottom: 1px solid var(--theme-primary-faint);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.66),
    inset 0 -1px 0 rgba(77, 53, 94, 0.08),
    0 22px 58px var(--theme-primary-faint);
  backdrop-filter: blur(24px) saturate(1.24);
  -webkit-backdrop-filter: blur(24px) saturate(1.24);
  transform: translateZ(0);
}

.gameHud::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 10px;
  width: min(42vw, 320px);
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--theme-primary-soft), transparent);
  transform: translateX(-50%);
}

.gameHud > * {
  position: relative;
  z-index: 1;
}

.levelStamp::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 760px);
  height: 1.68em;
  border-radius: 999px;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.16) 45%, transparent 72%);
  transform: translate(-50%, -50%);
  z-index: -1;
  pointer-events: none;
}

.gameHud.hudPulse {
  animation: hudRevealIn 720ms cubic-bezier(0.18, 0.82, 0.22, 1) both;
}

@keyframes hudRevealIn {
  from {
    opacity: 0;
    transform: translateY(-26px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.levelStamp {
  margin: 0;
  font-family: "Marcellus", Georgia, serif;
  font-size: clamp(38px, 11vw, 92px);
  line-height: 0.88;
  letter-spacing: -0.055em;
  font-weight: 800;
  color: var(--theme-primary);
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.88),
    0 0 28px rgba(255, 255, 255, 0.62),
    0 18px 34px rgba(77, 53, 94, 0.20);
}

.levelTitle {
  margin: 2px 0 0;
  font-family: "Ole", cursive;
  font-size: clamp(42px, 13vw, 110px);
  line-height: 0.82;
  letter-spacing: -0.05em;
  font-weight: 400;
  color: var(--theme-primary);
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.88),
    0 0 30px rgba(255, 255, 255, 0.56),
    0 14px 30px rgba(77, 53, 94, 0.18);
}

.levelMood {
  margin: clamp(6px, 1.2vw, 10px) 0 0;
  font-size: clamp(10px, 2.4vw, 13px);
  line-height: 1.1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 400;
  color: var(--theme-primary-soft);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.76);
}

.objective {
  margin: clamp(7px, 1.3vw, 12px) 0 0;
  max-width: min(86vw, 560px);
  font-size: clamp(11px, 2.9vw, 15px);
  line-height: 1.28;
  color: var(--theme-primary-soft);
}

.bottomBar {
  position: absolute;
  z-index: 9;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.bottomBar > * {
  pointer-events: auto;
}

.statusText {
  color: var(--theme-primary-soft);
  text-align: right;
  max-width: 40vw;
  margin-left: auto;
}

.resultOverlay {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  overflow: hidden;
}

.resultOverlay::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 50% 48%, var(--theme-glow), rgba(255, 255, 255, 0.18) 38%, transparent 66%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.30), var(--theme-panel));
  backdrop-filter: blur(18px) saturate(1.20);
  -webkit-backdrop-filter: blur(18px) saturate(1.20);
}

.resultOverlay > * {
  pointer-events: auto;
}

.resultKicker {
  color: var(--theme-primary-soft);
}

.resultTitle {
  margin: 0 0 28px;
  font-family: "Ole", cursive;
  font-size: clamp(82px, 22vw, 190px);
  line-height: 0.78;
  letter-spacing: -0.055em;
  font-weight: 400;
  color: var(--theme-primary);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.78), 0 24px 44px rgba(77, 53, 94, 0.20);
}

.hidden {
  display: none !important;
}

@media (orientation: landscape) and (min-width: 760px) {
  .gameStart {
    justify-content: center;
  }

  .startTitle {
    font-size: clamp(128px, 18vw, 260px);
  }

  .gameHud {
    min-height: clamp(170px, 32vh, 270px);
    align-items: center;
    text-align: center;
  }

  .objective {
    max-width: min(54vw, 640px);
  }
}


@media (max-width: 520px) {

  .startMechanic {
    max-width: 82vw;
  }
}

@media (max-width: 380px) {
  .levelStamp {
    font-size: clamp(34px, 10vw, 48px);
  }

  .levelTitle {
    font-size: clamp(38px, 12vw, 54px);
  }

  .objective {
    max-width: 86vw;
  }

  .smallButton {
    min-height: 42px;
    padding-inline: 12px;
    font-size: 12px;
  }

  .soundButton {
    min-width: 90px;
    padding-inline: 10px;
  }

  .statusText {
    max-width: 33vw;
    font-size: 9px;
    letter-spacing: 0.14em;
  }
}


@media (max-width: 420px) {
  .bottomBar {
    gap: 8px;
  }

  .bottomControls {
    gap: 8px;
  }

  .smallButton,
  .iconButton {
    min-height: 42px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .iconButton {
    min-width: 70px;
    font-size: 10px;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  .gameStart {
    padding-left: 7vw;
    padding-right: 7vw;
  }

  .gameStart::after {
    inset: clamp(24px, 3vw, 42px);
    border-radius: clamp(38px, 4vw, 68px);
  }

  .startTitle {
    font-size: clamp(130px, 16vw, 230px);
  }

  .startMechanic {
    font-size: clamp(15px, 1.45vw, 19px);
    max-width: 560px;
  }

  .gameHud {
    top: clamp(14px, 2vw, 28px);
    left: 50%;
    right: auto;
    width: min(760px, 74vw);
    min-height: auto;
    padding: 14px 26px 18px;
    border-radius: 34px;
    transform: translateX(-50%);
  }

  .gameHud::before {
    border: 1px solid var(--theme-primary-faint);
    border-radius: inherit;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.66),
      inset 0 -1px 0 rgba(77, 53, 94, 0.08),
      0 18px 46px rgba(77, 53, 94, 0.13);
  }

  .gameHud::after {
    bottom: 9px;
    width: min(250px, 34vw);
  }

  .levelStamp {
    font-size: clamp(30px, 3.8vw, 54px);
    line-height: 0.9;
  }

  .levelTitle {
    margin-top: 0;
    font-size: clamp(42px, 5vw, 74px);
  }

  .levelMood {
    margin-top: 3px;
    font-size: 11px;
  }

  .objective {
    margin-top: 5px;
    max-width: 650px;
    font-size: 13px;
  }

  .bottomBar {
    left: 50%;
    right: auto;
    bottom: clamp(18px, 2.4vw, 34px);
    width: min(760px, 74vw);
    transform: translateX(-50%);
  }

  .statusText {
    max-width: none;
  }
}


/* Final safe-view layout patch: keep the whole playground centered and visible on desktop, landscape, tablet, and mobile. */
@media (orientation: landscape) {
  .gameHud {
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    right: auto;
    width: min(720px, calc(100vw - 32px));
    min-height: auto;
    padding: 8px 18px 12px;
    border-radius: 26px;
    text-align: center;
    translate: -50% 0;
    transform: none;
  }

  .levelStamp {
    font-size: clamp(22px, 4.2vh, 38px);
    line-height: 0.88;
  }

  .levelTitle {
    margin-top: -1px;
    font-size: clamp(34px, 7.8vh, 58px);
    line-height: 0.80;
  }

  .levelMood {
    margin-top: 2px;
    font-size: clamp(9px, 1.7vh, 11px);
  }

  .objective {
    margin-top: 4px;
    max-width: min(620px, 78vw);
    font-size: clamp(10px, 1.9vh, 12px);
    line-height: 1.15;
  }

  .bottomBar {
    left: 50%;
    right: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(720px, calc(100vw - 32px));
    translate: -50% 0;
    transform: none;
  }

  .smallButton,
  .iconButton {
    min-height: 38px;
  }

  .statusText {
    max-width: none;
    white-space: nowrap;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .gameHud {
    padding: 6px 14px 8px;
    border-radius: 22px;
  }

  .levelStamp {
    font-size: clamp(18px, 4.8vh, 28px);
  }

  .levelTitle {
    font-size: clamp(28px, 8.5vh, 42px);
  }

  .levelMood,
  .objective {
    display: none;
  }

  .bottomBar {
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  .smallButton,
  .iconButton {
    min-height: 34px;
    padding-left: 12px;
    padding-right: 12px;
    font-size: 10px;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  .gameHud {
    width: min(780px, calc(100vw - 72px));
    padding: 10px 24px 14px;
    border-radius: 30px;
  }

  .bottomBar {
    width: min(780px, calc(100vw - 72px));
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (orientation: portrait) {
  .gameHud {
    min-height: clamp(150px, 25vh, 236px);
  }

  .bottomBar {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}
