:root {
  --cream: #fff7e8;
  --warm: #ffdf9a;
  --brown: #3b2110;
  --brown-soft: rgba(37, 20, 8, .76);
  --glass: rgba(255, 250, 235, .89);
  --glass-left: rgba(255, 247, 226, .91);
  --glass-right: rgba(255, 226, 154, .93);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Georgia, "Times New Roman", serif; background: #160d07; }
body { display: grid; place-items: center; }

.game {
  position: relative;
  width: min(100vw, 1200px);
  height: min(100vh, 760px);
  min-height: 620px;
  overflow: hidden;
  background: #000;
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  isolation: isolate;
}

.background {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.03);
  animation: slowFloat 24s ease-in-out infinite alternate;
  z-index: -3;
}

.shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.05), rgba(0,0,0,.18) 55%, rgba(0,0,0,.46));
  z-index: -2;
}

.chat {
  position: absolute;
  inset: 24px 24px 94px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  padding: 16px 16px 120px;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0, black 8%, black 90%, transparent 100%);
}

.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: rgba(255,255,255,.35); border-radius: 999px; }

.message {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  max-width: 82%;
  animation: appear .22s ease-out both;
}
.message.left { align-self: flex-start; }
.message.right { align-self: flex-end; }

.avatar {
  width: 82px;
  height: 82px;
  object-fit: cover;
  object-position: center 34%;
  border-radius: 50%;
  background: #050505;
  border: 3px solid rgba(255, 232, 176, .9);
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  flex: 0 0 auto;
}

.bubble {
  position: relative;
  padding: 12px 16px 14px;
  border-radius: 20px;
  color: var(--brown);
  line-height: 1.32;
  font-size: clamp(18px, 2.1vw, 24px);
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
  border: 1px solid rgba(255,255,255,.55);
  backdrop-filter: blur(8px);
}

.left .bubble { background: var(--glass-left); border-bottom-left-radius: 6px; }
.right .bubble { background: var(--glass-right); border-bottom-right-radius: 6px; }

.speaker {
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: rgba(75, 36, 8, .75);
  margin-bottom: 4px;
}
.text { text-wrap: pretty; }

.controls {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.btn {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffe7a9, #ffb840);
  color: #321a06;
  padding: 13px 24px;
  font: 800 16px system-ui, -apple-system, Segoe UI, sans-serif;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.3);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: rgba(255, 247, 226, .78); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.end {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  background: rgba(12, 8, 4, .72);
  color: var(--cream);
  z-index: 10;
}
.end h1 { margin: 0; font-size: clamp(32px, 5vw, 64px); }
.end p { margin: 0 0 12px; font-size: 22px; }
.hidden { display: none; }

@keyframes appear {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slowFloat {
  from { transform: scale(1.03) translate3d(-8px, -4px, 0); }
  to { transform: scale(1.08) translate3d(8px, 4px, 0); }
}

@media (max-width: 700px) {
  .game { height: 100vh; min-height: 100vh; border-radius: 0; }
  .chat { inset: 12px 10px 86px; padding: 8px 6px 100px; gap: 10px; }
  .message { max-width: 94%; gap: 8px; }
  .avatar { width: 58px; height: 58px; border-width: 2px; }
  .bubble { font-size: 17px; padding: 10px 12px; border-radius: 16px; }
  .speaker { font-size: 11px; }
  .controls { left: 12px; right: 12px; bottom: 14px; }
  .btn { padding: 11px 18px; }
}

.butterfly-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
}

.flying-butterfly {
  position: absolute;
  width: clamp(120px, 17vw, 220px);
  top: 26%;
  left: -240px;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.45));
  animation: butterflyFly 2.05s ease-in-out forwards;
}

.memory {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 8, 3, .42);
  z-index: 8;
}

.memory.hidden { display: none; }

.memory-panel {
  width: min(92vw, 560px);
  padding: 22px;
  border-radius: 28px;
  background: rgba(255, 247, 226, .92);
  border: 1px solid rgba(255,255,255,.75);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  text-align: center;
  color: var(--brown);
  backdrop-filter: blur(8px);
}

.memory-panel h1 {
  margin: 0 0 6px;
  font-size: clamp(26px, 4vw, 42px);
}

.memory-panel p {
  margin: 0 0 18px;
  font-size: clamp(16px, 2vw, 20px);
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.memory-card {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 20px;
  cursor: pointer;
  background: linear-gradient(135deg, #523114, #1d1008);
  box-shadow: 0 8px 20px rgba(0,0,0,.28);
  transform-style: preserve-3d;
  transition: transform .32s ease, box-shadow .2s ease;
  font: inherit;
}

.memory-card:hover { transform: translateY(-2px); }
.memory-card.open,
.memory-card.matched { transform: rotateY(180deg); }
.memory-card.matched { box-shadow: 0 0 0 4px rgba(255, 207, 80, .85), 0 12px 26px rgba(0,0,0,.34); }

.card-back,
.card-front {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 20px;
  backface-visibility: hidden;
}

.card-back {
  color: #ffe7a9;
  font-size: clamp(34px, 7vw, 56px);
  font-weight: 900;
  background: radial-gradient(circle at 30% 25%, rgba(255, 220, 145, .36), transparent 34%), linear-gradient(135deg, #6b431d, #211106);
}

.card-front {
  transform: rotateY(180deg);
  background: rgba(255, 252, 239, .96);
  overflow: hidden;
}

.card-front img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.22));
}

.flower-card {
  display: grid;
  place-items: center;
  width: 82%;
  height: 82%;
  font-size: clamp(36px, 8vw, 70px);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.18));
}

.memory.solved .memory-panel {
  animation: solvedPulse .42s ease both;
}

@keyframes butterflyFly {
  0% { transform: translate3d(0, 24px, 0) rotate(-8deg) scale(.82); opacity: 0; }
  12% { opacity: 1; }
  42% { transform: translate3d(48vw, -22px, 0) rotate(9deg) scale(1.04); }
  72% { transform: translate3d(74vw, 18px, 0) rotate(-5deg) scale(.96); opacity: 1; }
  100% { transform: translate3d(122vw, -14px, 0) rotate(12deg) scale(.78); opacity: 0; }
}

@keyframes solvedPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.025); }
  100% { transform: scale(1); }
}


.mini {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 8, 3, .45);
  z-index: 8;
}
.mini.hidden { display: none; }
.mini-panel {
  width: min(92vw, 660px);
  padding: 22px;
  border-radius: 28px;
  background: rgba(255, 247, 226, .92);
  border: 1px solid rgba(255,255,255,.75);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  text-align: center;
  color: var(--brown);
  backdrop-filter: blur(8px);
}
.mini-panel h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 42px); }
.mini-panel p { margin: 0 0 18px; font-size: clamp(16px, 2vw, 20px); }
.log-field, .water-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.log-btn, .water-btn {
  border: 0;
  border-radius: 18px;
  min-height: 86px;
  background: linear-gradient(135deg, #6b431d, #2e1909);
  color: #ffe7a9;
  cursor: pointer;
  font-size: clamp(34px, 6vw, 58px);
  box-shadow: 0 8px 20px rgba(0,0,0,.28);
  transition: transform .18s ease, opacity .18s ease;
}
.log-btn:hover, .water-btn:hover { transform: translateY(-2px); }
.log-btn.cleared { opacity: 0; transform: scale(.78); pointer-events: none; }
.water-btn.good { background: linear-gradient(135deg, #4aa3aa, #174e62); color: #fff; }
.water-btn.bad { animation: badShake .32s ease; }
.maze-board { width: min(74vw, 460px); height: min(74vw, 460px); margin: 14px auto 0; border-radius: 18px; background: #1e3218; position: relative; overflow: hidden; box-shadow: inset 0 0 0 5px rgba(59,33,16,.35); touch-action: none; }
.maze-board svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.maze-line { fill: none; stroke: rgba(255, 230, 157, .95); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }
.maze-wall { fill: none; stroke: rgba(255,255,255,.82); stroke-width: 16; stroke-linecap: round; }
.maze-start, .maze-end { position: absolute; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font: 900 14px system-ui; color: #321a06; background: #ffdf9a; box-shadow: 0 4px 12px rgba(0,0,0,.28); }
.maze-start { left: 16px; bottom: 16px; }
.maze-end { right: 16px; top: 16px; }
@keyframes badShake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
@media (max-width: 700px) {
  .log-field, .water-grid { gap: 8px; }
  .log-btn, .water-btn { min-height: 70px; }
}
