@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Kalam:wght@400;700&display=swap');

:root {
  color-scheme: only light;
  --ink: #24354a;
  --paper: #fff4dc;
  --red: #c74434;
  --cream: #f9e6bc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #b96643;
  font-family: "Baloo 2", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 500px;
  overflow: hidden;
  isolation: isolate;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#game:active { cursor: grabbing; }

.hud {
  position: absolute;
  z-index: 3;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: grid;
  color: var(--paper);
  filter: drop-shadow(0 2px 0 rgba(67, 37, 29, .3));
  line-height: .8;
  transform: rotate(-2deg);
}

.brand-hi { font-size: clamp(26px, 5vw, 38px); font-weight: 700; }
.brand-en { font: 700 11px/1 "Kalam", cursive; letter-spacing: .42em; margin: 8px 0 0 3px; }

.round-card {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) rotate(1deg);
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding: 7px 15px 5px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid rgba(36, 53, 74, .8);
  box-shadow: 3px 4px 0 rgba(67, 37, 29, .25);
  font: 700 13px/1 "Kalam", cursive;
}

.round-card strong { color: var(--red); font-size: 20px; }

.icon-button {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255,255,255,.65);
  border-radius: 50%;
  color: white;
  background: rgba(36, 53, 74, .25);
  backdrop-filter: blur(4px);
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(45, 22, 18, .18);
}

.icon-button.muted { opacity: .55; text-decoration: line-through; }

.hud-actions { display: flex; gap: 9px; pointer-events: auto; }
.practice-button { font: 700 20px/1 "Kalam", cursive; }

.message-card {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(430px, calc(100% - 40px));
  transform: translate(-50%, -48%) rotate(-.7deg);
  padding: 28px 28px 24px;
  text-align: center;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, transparent 0 25px, rgba(72, 133, 171, .13) 25px 26px),
    var(--paper);
  border: 1px solid rgba(84, 61, 45, .25);
  box-shadow: 8px 13px 0 rgba(72, 38, 29, .2), 0 25px 70px rgba(50, 23, 16, .32);
  transition: opacity .25s, transform .35s;
}

.message-card::before,
.message-card::after {
  content: "";
  position: absolute;
  width: 55px;
  height: 17px;
  top: -9px;
  background: rgba(245, 218, 164, .72);
  border: 1px solid rgba(110, 80, 49, .15);
}
.message-card::before { left: 25px; transform: rotate(-6deg); }
.message-card::after { right: 25px; transform: rotate(5deg); }

.message-card.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -43%) scale(.96);
}

.eyebrow { margin: 0 0 8px; color: var(--red); font: 700 12px/1 "Kalam", cursive; letter-spacing: .17em; }
.message-card h1 { margin: 0; font: 700 clamp(30px, 8vw, 46px)/1.05 "Kalam", cursive; }
.message-card p:not(.eyebrow) { margin: 13px auto 21px; max-width: 330px; font-size: 17px; line-height: 1.25; }

.primary-button {
  border: 2px solid #7e2d27;
  padding: 12px 27px 9px;
  color: white;
  background: var(--red);
  box-shadow: 4px 5px 0 #7e2d27;
  font: 700 17px/1 "Kalam", cursive;
  letter-spacing: .04em;
  transform: rotate(.4deg);
  cursor: pointer;
}
.primary-button:active { transform: translate(3px, 4px); box-shadow: 1px 1px 0 #7e2d27; }

.text-button {
  display: block;
  margin: 19px auto 0;
  border: 0;
  padding: 4px 8px;
  color: var(--ink);
  background: transparent;
  border-bottom: 2px solid rgba(36,53,74,.35);
  font: 700 13px/1.2 "Kalam", cursive;
  letter-spacing: .06em;
  cursor: pointer;
}

.tutorial-panel {
  position: absolute;
  z-index: 4;
  left: max(18px, env(safe-area-inset-left));
  top: 105px;
  width: min(290px, calc(100% - 36px));
  padding: 20px 20px 17px;
  color: var(--ink);
  background: rgba(255,244,220,.94);
  border: 2px solid rgba(36,53,74,.7);
  box-shadow: 6px 8px 0 rgba(67,37,29,.2);
  transform: rotate(-.5deg);
  transition: opacity .2s, transform .25s;
}
.tutorial-panel.hidden { opacity: 0; pointer-events: none; transform: translateX(-15px) rotate(-.5deg); }
.tutorial-panel h2 { margin: 0 0 5px; font: 700 24px/1.05 "Kalam", cursive; }
.tutorial-panel > p:not(.eyebrow) { margin: 0 0 13px; font-size: 15px; line-height: 1.2; }
.tutorial-panel .text-button { margin: 15px 0 0; }

.key-guide { display: grid; grid-template-columns: repeat(3, 39px); gap: 6px; align-items: center; }
.key-guide span {
  display: grid; place-items: center; height: 30px;
  border: 1px solid #7c6a55; border-radius: 5px;
  background: #fffaf0; box-shadow: 0 3px 0 #cbb99a;
  font: 700 12px/1 system-ui, sans-serif;
}
.key-guide .wide { width: 88px; margin-left: 5px; }
.tutorial-progress { display: flex; gap: 6px; margin-top: 16px; }
.tutorial-progress i { width: 28px; height: 4px; border-radius: 3px; background: #cebfa5; }
.tutorial-progress i.active { background: var(--red); }

.hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(58px, calc(env(safe-area-inset-bottom) + 42px));
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 9px 17px 7px;
  border-radius: 30px;
  color: white;
  background: rgba(31, 42, 51, .68);
  backdrop-filter: blur(6px);
  font: 600 15px/1.1 "Kalam", cursive;
  text-align: center;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
}
.hint.show { opacity: 1; transform: translate(-50%, -5px); }
.hint.controls { top: max(70px, calc(env(safe-area-inset-top) + 58px)); bottom: auto; }

.toast {
  position: absolute;
  z-index: 5;
  top: 24%;
  left: 50%;
  color: var(--paper);
  font: 700 clamp(30px, 9vw, 58px)/1 "Kalam", cursive;
  text-shadow: 0 3px 0 rgba(97, 43, 31, .5);
  opacity: 0;
  transform: translate(-50%, 14px) rotate(-4deg) scale(.8);
  pointer-events: none;
}
.toast.pop { animation: toast-pop .85s ease-out; }

@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, 20px) rotate(-5deg) scale(.65); }
  22% { opacity: 1; transform: translate(-50%, 0) rotate(-2deg) scale(1.08); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -22px) rotate(2deg) scale(1); }
}

footer {
  position: absolute;
  z-index: 3;
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,.8);
  font: 600 12px/1 "Kalam", cursive;
  letter-spacing: .06em;
  pointer-events: none;
}
.footer-rule { flex: 1; height: 1px; background: rgba(255,255,255,.25); }

@media (max-height: 650px) {
  .hud { top: 10px; }
  .brand-hi { font-size: 25px; }
  .brand-en { display: none; }
  footer { bottom: 8px; }
  .hint { bottom: 39px; }
}

@media (max-width: 600px) {
  .tutorial-panel { top: auto; bottom: 73px; width: calc(100% - 36px); }
}

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