:root {
  color-scheme: light;
  font-family: Georgia, "Times New Roman", serif;
  background: #eec99b;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(circle at 50% 16%, #f6e3b6 0, #eebd8b 45%, #c67464 130%);
}

button { font: inherit; }

.game-shell {
  position: relative;
  width: min(100vw, 1180px);
  height: min(100dvh, 760px);
  min-height: 500px;
  overflow: hidden;
  isolation: isolate;
  border: 8px solid #f8e6c2;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(90, 47, 43, 0.38), inset 0 0 0 2px #b64f59;
  background: #9bcbd1;
}

.game-shell::after {
  position: absolute;
  z-index: 8;
  inset: 0;
  border: 2px solid rgba(106, 61, 67, 0.34);
  content: "";
  pointer-events: none;
}

canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.preloader {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: #f7e4b7;
  background: #a9504b;
  transition: opacity 360ms ease, visibility 360ms ease;
}

.loading-cup {
  position: relative;
  width: clamp(150px, 30vw, 245px);
  height: clamp(170px, 31vw, 275px);
  overflow: visible;
  border: clamp(7px, 1.4vw, 12px) solid #f6e6c0;
  border-top: 0;
  border-radius: 10px 10px 30% 30%;
  background: #ead3a4;
  box-shadow: inset 0 0 0 5px rgba(169, 80, 75, 0.25), 9px 12px 0 rgba(78, 42, 49, 0.22);
}

.loading-rim {
  position: absolute;
  top: -14px;
  right: -8px;
  left: -8px;
  height: 29px;
  border: 7px solid #f7e9c7;
  border-radius: 50%;
  background: #6e3c38;
  box-shadow: inset 0 7px 0 rgba(238, 183, 112, 0.4);
}

.loading-coffee {
  position: absolute;
  right: 10%;
  bottom: 10%;
  left: 10%;
  height: 0;
  border-radius: 4px 4px 20% 20%;
  background: linear-gradient(180deg, #d58a57, #7d3d32);
  box-shadow: inset 0 7px 0 rgba(255, 226, 164, 0.22);
  transition: height 180ms ease;
}

.loading-handle {
  position: absolute;
  top: 27%;
  right: -30%;
  width: 42%;
  height: 42%;
  border: clamp(7px, 1.4vw, 12px) solid #f6e6c0;
  border-left: 0;
  border-radius: 0 50% 50% 0;
}

.loading-percent {
  margin: 0;
  color: #ffe8b5;
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.menu-screen,
.end-screen,
.pause-screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  color: #50333c;
  background: rgba(246, 225, 184, 0.56);
  transition: opacity 260ms ease, visibility 260ms ease;
}

.menu-title-block {
  position: absolute;
  z-index: 1;
  top: clamp(34px, 10vh, 76px);
  left: 50%;
  width: min(76%, 790px);
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 1px #f9edcd;
}

.eyebrow {
  margin: 0 0 8px;
  color: #ab4b55;
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

h1,
h2 {
  margin: 0;
  color: #9d3e4b;
  font-size: clamp(42px, 7vw, 82px);
  font-weight: 700;
  line-height: 0.84;
  letter-spacing: -0.065em;
}

.menu-subtitle {
  max-width: 435px;
  margin: 18px auto 0;
  font-size: clamp(17px, 2.2vw, 23px);
  font-style: italic;
  line-height: 1.25;
}

.play-button {
  position: absolute;
  z-index: 2;
  top: 58%;
  left: 50%;
  min-width: 162px;
  padding: 13px 32px 14px;
  transform: translate(-50%, -50%);
  border: 3px solid #733440;
  border-radius: 0;
  color: #fff4cf;
  background: #b84e58;
  box-shadow: 5px 5px 0 #efb771;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.play-button:hover,
.play-button:focus-visible {
  outline: none;
  transform: translate(-50%, -50%) translate(-2px, -2px);
  box-shadow: 7px 7px 0 #efb771;
}

.play-button:active {
  transform: translate(-50%, -50%) translate(3px, 3px);
  box-shadow: 2px 2px 0 #efb771;
}

.cup-counter {
  position: absolute;
  z-index: 2;
  top: clamp(42px, 13vh, 98px);
  left: clamp(21px, 5.5vw, 68px);
  width: 98px;
  height: 67px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 3px solid #81404c;
  color: #783d48;
  background: #f8e7bb;
  box-shadow: 4px 4px 0 #c16a61;
  font-family: Arial, sans-serif;
  font-size: 24px;
  font-weight: 900;
}

.mini-cup {
  position: relative;
  width: 20px;
  height: 27px;
  border: 2px solid #82414a;
  border-radius: 2px 2px 6px 6px;
  background: #f8e7bb;
}

.mini-cup::before {
  position: absolute;
  top: -5px;
  left: -2px;
  width: 20px;
  height: 5px;
  border: 2px solid #82414a;
  background: #b75858;
  content: "";
}

.mini-cup::after {
  position: absolute;
  top: 7px;
  right: -10px;
  width: 8px;
  height: 11px;
  border: 2px solid #82414a;
  border-left: 0;
  border-radius: 0 8px 8px 0;
  content: "";
}

.sprinkls-card {
  position: absolute;
  z-index: 2;
  right: clamp(22px, 7vw, 92px);
  bottom: clamp(32px, 5vh, 54px);
  width: clamp(166px, 25vw, 295px);
  height: clamp(300px, 57vh, 445px);
}

.character-button {
  position: absolute;
  inset: 0 0 32px;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.click-label {
  position: absolute;
  z-index: 2;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: #70404a;
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.character-button:focus-visible {
  outline: 3px dashed #8b3d4a;
  outline-offset: 6px;
}

.menu-character {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(5px 7px 0 rgba(92, 58, 59, 0.26));
  transition: transform 180ms ease;
}

.character-button:active .menu-character {
  transform: translateY(4px) scale(0.98);
}

.name-platform {
  position: absolute;
  right: -11px;
  bottom: 9px;
  left: -11px;
  padding: 7px 4px;
  border: 3px solid #633642;
  color: #fee9bd;
  background: linear-gradient(90deg, #b44b56, #d77a5e, #b44b56);
  box-shadow: 3px 3px 0 #6d3641;
  font-family: "Comic Sans MS", "Bradley Hand", cursive;
  font-size: clamp(15px, 2.5vw, 24px);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
  text-shadow: 1px 1px #733440;
  transform: rotate(-2deg) skewX(-8deg);
}

.menu-controls {
  position: absolute;
  z-index: 2;
  bottom: 16px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: #694249;
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  white-space: nowrap;
}

.end-screen {
  display: grid;
  place-content: center;
  text-align: center;
  background: rgba(245, 226, 187, 0.78);
}

.end-screen h2 { font-size: clamp(40px, 6vw, 68px); }

.end-score {
  margin: 22px 0 84px;
  font-size: clamp(17px, 2.2vw, 23px);
  font-style: italic;
}

.end-screen .play-button { top: auto; bottom: 15%; }

.pause-screen {
  z-index: 6;
  display: grid;
  place-content: center;
  color: #f8e6bd;
  background: rgba(52, 45, 53, 0.64);
  text-align: center;
}

.pause-screen p {
  margin: 0;
  font-size: clamp(46px, 7vw, 78px);
  font-weight: 700;
}

.pause-screen span {
  margin-top: 15px;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.menu-return-button {
  margin-top: 26px;
  padding: 10px 18px;
  border: 2px solid #f3d9a5;
  color: #f8e5bd;
  background: rgba(125, 61, 63, 0.86);
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

.menu-return-button:hover,
.menu-return-button:focus-visible {
  outline: none;
  background: #b84e58;
}

.memory-screen {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  color: #f6e7c1;
  background: rgba(62, 48, 56, 0.84);
}

.memory-bonus {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  padding: 10px 14px;
  border: 2px solid #f4dca8;
  color: #fff3c8;
  background: rgba(131, 63, 58, 0.84);
  font-family: Arial, sans-serif;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.memory-card {
  width: min(78vw, 430px);
  text-align: center;
}

.memory-kicker {
  margin: 0 0 14px;
  color: #f2c77f;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.3em;
}

.memory-button {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.memory-button:focus-visible {
  outline: 3px dashed #f2c77f;
  outline-offset: 8px;
}

.memory-frame {
  position: relative;
  display: block;
  width: min(60vw, 300px);
  height: min(57vh, 370px);
  margin: 0 auto;
  padding: 14px;
  border: 8px solid #e7bd73;
  outline: 3px solid #fff0c8;
  outline-offset: -14px;
  background: #81534e;
  box-shadow: 0 0 0 12px #5d3e47, 0 16px 0 rgba(18, 21, 31, 0.28);
  overflow: hidden;
}

.memory-frame::before,
.memory-frame::after {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid #fff0c8;
  content: "";
  pointer-events: none;
}

.memory-frame::before { top: 7px; left: 7px; border-right: 0; border-bottom: 0; }
.memory-frame::after { right: 7px; bottom: 7px; border-top: 0; border-left: 0; }

.memory-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: saturate(0.92) contrast(1.04);
}

.memory-button:active .memory-frame {
  transform: translateY(4px) scale(0.98);
}

.memory-count {
  margin: 26px 0 0;
  color: #f7dfaa;
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.coffee-flood {
  position: absolute;
  z-index: 12;
  inset: 0;
  overflow: hidden;
  background: #9a4b3b;
  transform: translateY(100%);
  pointer-events: none;
}

.coffee-flood::before,
.coffee-flood::after {
  position: absolute;
  bottom: -18%;
  width: 70vw;
  height: 70vw;
  border-radius: 50%;
  background: rgba(222, 149, 93, 0.6);
  content: "";
}

.coffee-flood::before { left: -18%; }
.coffee-flood::after { right: -18%; bottom: -28%; background: rgba(255, 219, 157, 0.28); }

.coffee-flood.is-flooding {
  animation: coffee-rise 1.1s cubic-bezier(0.22, 0.8, 0.32, 1) forwards;
}

@keyframes coffee-rise {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.is-hidden { visibility: hidden; opacity: 0; pointer-events: none; }

.hint {
  position: absolute;
  z-index: 4;
  bottom: 13px;
  left: 50%;
  margin: 0;
  padding: 7px 13px;
  transform: translateX(-50%);
  border: 1px solid rgba(247, 229, 193, 0.7);
  color: #fbeaca;
  background: rgba(82, 56, 60, 0.62);
  font-family: Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
}

.mobile-controls {
  display: none;
  position: absolute;
  z-index: 7;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  user-select: none;
}

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.touch-button {
  width: 56px;
  height: 56px;
  padding: 0;
  border: 2px solid rgba(255, 243, 207, 0.9);
  border-radius: 50%;
  color: #fff0c4;
  background: rgba(103, 58, 65, 0.78);
  box-shadow: 0 4px 0 rgba(56, 36, 43, 0.42), inset 0 0 0 2px rgba(166, 76, 81, 0.72);
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 23px;
  font-weight: 900;
  line-height: 1;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.touch-button:active,
.touch-button.is-pressed {
  transform: translateY(3px) scale(0.96);
  background: rgba(184, 78, 88, 0.95);
  box-shadow: 0 1px 0 rgba(56, 36, 43, 0.42), inset 0 0 0 2px rgba(255, 224, 164, 0.75);
}

.touch-actions { gap: 7px; }
.touch-boost { font-size: 27px; }
.touch-jump { width: 64px; height: 64px; color: #ffe2a0; font-size: 27px; }
.touch-pause { font-size: 19px; }

@media (pointer: coarse), (max-width: 700px) {
  .mobile-controls:not(.is-hidden) { display: flex; }
  .hint { display: none; }
}

@media (max-width: 700px) {
  .game-shell { height: 100dvh; min-height: 0; border: 0; border-radius: 0; }
  h1 { font-size: clamp(37px, 11vw, 56px); }
  .cup-counter { top: 35px; left: 18px; width: 77px; height: 54px; font-size: 20px; }
  .mini-cup { transform: scale(0.8); }
  .sprinkls-card { right: 2%; bottom: 7%; width: 143px; height: 290px; }
  .menu-subtitle { max-width: 290px; }
  .menu-controls { bottom: 15px; width: 100%; padding: 0 14px; font-size: 9px; white-space: normal; }
  .hint { max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
}
