:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sky: #8adcf3;
  --lime: #92df43;
  --lime-dark: #4f9f39;
  --gold: #f5b83a;
  --ink: #503d32;
  --cream: #fff7dc;
  --club-art: none;
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: radial-gradient(circle at top, #67cae7 0%, #2d7fa3 100%); touch-action: manipulation; }
button { font: inherit; cursor: pointer; user-select: none; border: 0; color: inherit; }
button:focus-visible { outline: 3px solid white; outline-offset: 2px; }

#game {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  min-height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background-color: var(--sky);
  background-image: var(--club-art);
  background-size: cover;
  background-position: center;
  isolation: isolate;
}

.lang-pill {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: 12px;
  z-index: 10;
  padding: 5px 12px;
  border: 3px solid white;
  border-radius: 999px;
  background: rgba(80, 61, 50, 0.78);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 0 3px 0 rgba(40, 30, 25, 0.35);
}
.lang-pill:active { transform: translateY(2px); }

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }
.start-screen { flex-direction: column; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 48px) 18px calc(var(--safe-bottom) + 26px); text-align: center; }
.start-vignette { position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgba(18,102,151,.1), transparent 33%, rgba(30,72,100,.24)); }
.title-card { width: min(100%, 410px); padding: 18px 14px 15px; border: 4px solid white; border-radius: 28px; background: rgba(255,247,220,.94); box-shadow: 0 8px 0 rgba(80,61,50,.38), 0 18px 34px rgba(22,74,101,.22); }
.eyebrow { display: inline-flex; align-items: center; min-height: 28px; padding: 0 18px; border: 3px solid white; border-radius: 999px; background: #58d3bf; color: white; box-shadow: 0 4px 0 rgba(80,61,50,.28); font-size: 12px; font-weight: 900; letter-spacing: 1px; }
h1 { margin: 10px 0 7px; line-height: 1.05; letter-spacing: 0; }
h1 span, h1 strong { display: block; text-shadow: 0 4px 0 rgba(80,61,50,.18); }
h1 span { color: var(--ink); font-size: clamp(28px, 8vw, 42px); }
h1 strong { margin-top: 4px; color: #ee658c; font-size: clamp(38px, 11vw, 56px); }
.title-card p { margin: 10px auto 0; max-width: 330px; color: #725a50; font-size: 14px; font-weight: 800; line-height: 1.35; }
.start-actions { width: min(100%, 390px); display: flex; flex-direction: column; align-items: center; gap: 9px; }
.start-actions small { color: white; font-size: 12px; font-weight: 900; letter-spacing: 1px; text-shadow: 0 2px 2px rgba(40,66,85,.6); }

.primary-button { width: 100%; min-height: 56px; padding: 0 20px; border: 4px solid white; border-radius: 22px; background: linear-gradient(#a9ea59, var(--lime)); color: #30424c; box-shadow: 0 8px 0 var(--lime-dark), 0 12px 22px rgba(38,75,64,.25); font-size: 21px; font-weight: 900; letter-spacing: .5px; text-shadow: 0 2px 0 rgba(255,255,255,.72); }
.primary-button:hover:not(:disabled) { filter: brightness(1.04); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--lime-dark); }
.primary-button:disabled { filter: grayscale(.4); opacity: .7; }
.text-button { padding: 7px 16px; background: transparent; color: white; font-size: 14px; font-weight: 900; text-decoration: underline; text-underline-offset: 4px; text-shadow: 0 2px 2px rgba(33,72,91,.5); }

.play-screen { flex-direction: column; gap: 7px; padding: calc(var(--safe-top) + 7px) 8px calc(var(--safe-bottom) + 7px); background: linear-gradient(rgba(126,219,243,.12), rgba(50,155,187,.14)); }
.topbar { flex: 0 0 52px; display: grid; grid-template-columns: 46px 46px 86px 1fr 46px; align-items: center; gap: 5px; }
.round-button { width: 44px; height: 44px; display: grid; place-items: center; border: 4px solid white; border-radius: 16px; background: #5a4c6d; color: white; box-shadow: 0 5px 0 #302942; font-size: 21px; font-weight: 900; }
.round-button:hover { filter: brightness(1.08); }
.round-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #302942; }
.level-chip { height: 44px; display: flex; align-items: center; justify-content: center; gap: 4px; border: 3px solid white; border-radius: 16px; background: rgba(255,247,220,.96); box-shadow: 0 5px 0 rgba(86,74,67,.32); }
.level-chip small { font-size: 11px; font-weight: 900; }
.level-chip b { color: #ec6c91; font-size: 20px; }
.hearts { min-width: 0; height: 44px; display: flex; justify-content: center; align-items: center; gap: 3px; border: 3px solid white; border-radius: 16px; background: rgba(255,247,220,.96); box-shadow: 0 5px 0 rgba(86,74,67,.32); }
.heart { color: #ee658c; font-size: 20px; filter: drop-shadow(0 2px 0 white); transition: .2s; }
.heart.empty { color: #d7c9c5; transform: scale(.82); }

.mission-card { flex: 0 0 42px; display: grid; grid-template-columns: 108px 1fr; align-items: center; padding: 0 12px; border: 3px solid white; border-radius: 17px; background: rgba(255,247,220,.94); box-shadow: 0 5px 0 rgba(86,74,67,.3); }
.mission-card div { display: flex; align-items: baseline; gap: 5px; }
.mission-card b { color: #ee658c; font-size: 21px; }
.mission-card span { color: #715b54; font-size: 11px; font-weight: 900; line-height: 1; }
.mission-card p { margin: 0; color: #5b4d49; font-size: 12px; font-weight: 900; text-align: right; }

.board-shell { position: relative; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; overflow: hidden; border: 4px solid white; border-radius: 28px; background: linear-gradient(145deg, rgba(255,255,255,.86), rgba(255,247,220,.9)); box-shadow: 0 8px 0 rgba(77,67,61,.45), inset 0 0 0 4px rgba(88,211,191,.25); }
.board-shell::before { content: ""; position: absolute; inset: 6px; border-radius: 19px; opacity: .32; background: linear-gradient(45deg, rgba(138,220,243,.45) 25%, transparent 25% 75%, rgba(138,220,243,.45) 75%), linear-gradient(45deg, rgba(138,220,243,.45) 25%, transparent 25% 75%, rgba(138,220,243,.45) 75%); background-position: 0 0, 13px 13px; background-size: 26px 26px; }
.board { --cell: min(calc((min(100vw, 480px) - 50px) / 6), calc((100dvh - 196px) / 8), 56px); position: relative; z-index: 2; display: grid; grid-template-columns: repeat(6, var(--cell)); grid-template-rows: repeat(8, var(--cell)); gap: 3px; padding: 5px; }
.cell { width: var(--cell); height: var(--cell); display: grid; place-items: center; }
.tile { position: relative; width: calc(var(--cell) - 5px); height: calc(var(--cell) - 5px); display: grid; place-items: center; touch-action: manipulation; }
.tile.bubble { border: 4px solid var(--cream); border-radius: 50%; background: radial-gradient(circle at 31% 25%, white 0 8%, rgba(255,255,255,.58) 9% 18%, transparent 20%), linear-gradient(145deg, rgba(255,255,255,.28), rgba(80,61,50,.18)), var(--tile); box-shadow: 0 0 0 3px var(--ink), 0 5px 0 rgba(80,61,50,.35), inset -5px -7px 8px rgba(80,61,50,.12); }
.bubble-face { position: absolute; left: 50%; top: 52%; width: 58%; height: 28%; transform: translate(-50%,-50%); border-bottom: 2px solid rgba(80,61,50,.8); border-radius: 0 0 50% 50%; }
.bubble-face::before, .bubble-face::after { content: ""; position: absolute; top: -2px; width: 4px; height: 5px; border-radius: 50%; background: var(--ink); }
.bubble-face::before { left: 10%; }
.bubble-face::after { right: 10%; }
.tile.arrow { border: 4px solid var(--cream); border-radius: 15px; background: linear-gradient(145deg, rgba(255,255,255,.34), rgba(255,255,255,0) 52%, rgba(80,61,50,.14)), var(--tile); box-shadow: 0 0 0 3px var(--ink), 0 5px 0 rgba(80,61,50,.38), inset 3px 3px 0 rgba(255,255,255,.35); transition: transform .08s; }
.tile.arrow:hover { transform: scale(1.05); }
.tile.arrow:active { transform: translateY(3px) scale(.96); box-shadow: 0 0 0 3px var(--ink), 0 2px 0 rgba(80,61,50,.38); }
.arrow-glyph { position: relative; width: 68%; height: 12px; border-radius: 999px; background: var(--cream); box-shadow: 0 2px 0 rgba(80,61,50,.28); transform: rotate(var(--angle)); }
.arrow-glyph::after { content: ""; position: absolute; right: -5px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%) rotate(45deg); border-top: 8px solid var(--cream); border-right: 8px solid var(--cream); border-radius: 3px; }
.tile.hint { animation: hintPulse .55s ease-in-out 2; z-index: 4; }
.tile.blocked { animation: blocked .32s ease; }
.tile.firing { z-index: 5; animation: firePop .3s ease forwards; }
.tile.popping { animation: bubblePop .38s ease forwards; }
@keyframes hintPulse { 50% { transform: scale(1.18) rotate(-4deg); filter: drop-shadow(0 0 8px white); } }
@keyframes blocked { 25% { transform: translateX(-6px) rotate(-3deg); } 60% { transform: translateX(5px) rotate(3deg); } }
@keyframes firePop { to { transform: scale(.35) rotate(18deg); opacity: 0; } }
@keyframes bubblePop { 55% { transform: scale(1.3); filter: brightness(1.35); } 100% { transform: scale(.15); opacity: 0; } }

.effects { position: absolute; inset: 0; z-index: 6; overflow: hidden; pointer-events: none; }
.shot-beam { position: absolute; z-index: 3; height: 9px; border: 3px solid white; border-radius: 999px; background: var(--tile); box-shadow: 0 3px 0 rgba(80,61,50,.35); transform-origin: left center; animation: beamFlash .3s ease forwards; }
@keyframes beamFlash { from { clip-path: inset(0 100% 0 0); } 65% { clip-path: inset(0); opacity: 1; } to { clip-path: inset(0); opacity: 0; } }
.spark { position: absolute; z-index: 7; width: 11px; height: 11px; background: var(--gold); clip-path: polygon(50% 0,61% 35%,100% 50%,61% 65%,50% 100%,39% 65%,0 50%,39% 35%); animation: sparkFly .65s ease-out forwards; }
@keyframes sparkFly { to { transform: translate(var(--dx),var(--dy)) rotate(180deg) scale(.2); opacity: 0; } }

.actionbar { flex: 0 0 62px; display: grid; grid-template-columns: 76px 1fr 76px; align-items: center; gap: 7px; }
.tool-button { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 3px solid white; border-radius: 17px; background: #5a4c6d; color: white; box-shadow: 0 5px 0 #302942; font-size: 11px; font-weight: 900; }
.tool-button em { font-style: normal; }
.tool-button span { color: #f7cf46; font-size: 18px; line-height: 1; }
.tool-button:hover { filter: brightness(1.08); }
.tool-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #302942; }
.cat-tip { min-width: 0; height: 50px; display: grid; grid-template-columns: 45px 1fr; align-items: center; padding: 0 9px; border: 3px solid white; border-radius: 18px; background: rgba(255,247,220,.96); box-shadow: 0 5px 0 rgba(80,61,50,.35); }
.cat-tip b { color: #ef7f37; font-size: 15px; white-space: nowrap; }
.cat-tip span { color: #5c4e49; font-size: 11px; font-weight: 900; line-height: 1.2; text-align: center; }

.modal-layer { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(28,69,91,.68); backdrop-filter: blur(7px); }
.modal-layer[hidden] { display: none; }
.modal-card { position: relative; width: min(100%, 390px); padding: 23px 18px 19px; border: 5px solid white; border-radius: 30px; background: linear-gradient(160deg,#fff9e7,#ffe8ee); box-shadow: 0 11px 0 #79636a, 0 20px 35px rgba(27,53,71,.4); text-align: center; }
.modal-card h2 { margin: 15px 0 12px; color: #384662; font-size: 25px; line-height: 1.1; }
.lesson-row { display: grid; grid-template-columns: 38px 1fr; gap: 9px; align-items: center; margin: 8px 0; text-align: left; }
.lesson-row b { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 13px; background: #ee658c; color: white; box-shadow: 0 4px 0 #a94967; }
.lesson-row span { color: #5b4d49; font-size: 13px; font-weight: 800; line-height: 1.3; }
.lesson-demo { height: 52px; margin: 11px 0 6px; display: flex; justify-content: center; align-items: center; gap: 6px; border-radius: 16px; background: white; border: 2px solid #eadcca; }
.mini-bow { width: 38px; height: 34px; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 10px; background: #45c9ce; color: white; font-size: 25px; font-style: normal; }
.demo-line { width: 38px; height: 6px; border-radius: 99px; background: #45c9ce; }
.mini-bubble { width: 33px; height: 33px; border: 3px solid white; border-radius: 50%; background: #45c9ce; box-shadow: 0 0 0 3px var(--ink); }
.lesson-demo strong { color: var(--lime-dark); font-size: 12px; }
.tutorial-card > p, .result-card > p { margin: 10px auto 15px; color: #7a625c; font-size: 13px; font-weight: 800; line-height: 1.35; }
.tutorial-card .primary-button, .result-card .primary-button { min-height: 52px; font-size: 18px; }
.result-emblem { width: 72px; height: 72px; margin: -61px auto 0; display: grid; place-items: center; border: 5px solid white; border-radius: 50%; background: var(--gold); color: white; box-shadow: 0 7px 0 #a57527; font-size: 35px; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 13px 0 17px; }
.result-stats div { padding: 10px 6px; border: 2px solid #eadcca; border-radius: 14px; background: white; }
.result-stats b { display: block; color: #ee658c; font-size: 21px; }
.result-stats span { color: #6e5b55; font-size: 11px; font-weight: 900; }
.result-card .text-button { color: #665451; text-shadow: none; }

.toast { position: absolute; z-index: 40; left: 50%; bottom: calc(var(--safe-bottom) + 78px); transform: translate(-50%,18px); opacity: 0; pointer-events: none; padding: 9px 16px; border: 3px solid white; border-radius: 999px; background: #40374f; color: white; box-shadow: 0 5px 0 #272231; font-size: 13px; font-weight: 900; white-space: nowrap; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.screen-flash { animation: screenFlash .25s ease; }
@keyframes screenFlash { 50% { filter: saturate(1.4) brightness(1.16); } }

@media (max-height: 670px) {
  .play-screen { gap: 4px; padding: calc(var(--safe-top) + 4px) 6px calc(var(--safe-bottom) + 4px); }
  .topbar { flex-basis: 43px; grid-template-columns: 38px 38px 74px 1fr 38px; gap: 4px; }
  .round-button { width: 37px; height: 37px; border-radius: 13px; border-width: 3px; font-size: 18px; }
  .level-chip, .hearts { height: 37px; border-radius: 13px; }
  .level-chip b { font-size: 18px; }
  .heart { font-size: 17px; }
  .mission-card { flex-basis: 34px; height: 34px; border-radius: 13px; }
  .mission-card b { font-size: 18px; }
  .board-shell { border-radius: 22px; border-width: 3px; }
  .board { --cell: min(calc((min(100vw, 480px) - 44px) / 6), calc((100dvh - 174px) / 8), 52px); gap: 2px; padding: 3px; }
  .tile { width: calc(var(--cell) - 5px); height: calc(var(--cell) - 5px); }
  .tile.bubble, .tile.arrow { border-width: 3px; box-shadow: 0 0 0 2px var(--ink), 0 4px 0 rgba(80,61,50,.35); }
  .actionbar { flex-basis: 52px; grid-template-columns: 67px 1fr 67px; gap: 5px; }
  .tool-button { min-height: 42px; border-radius: 14px; }
  .cat-tip { height: 43px; grid-template-columns: 39px 1fr; border-radius: 15px; }
  .cat-tip b { font-size: 13px; }
  .modal-layer { padding: 8px; }
  .modal-card { padding: 16px 13px 13px; border-radius: 25px; }
  .modal-card h2 { margin: 10px 0 8px; font-size: 22px; }
  .lesson-row { margin: 6px 0; }
  .lesson-demo { height: 44px; margin: 8px 0 4px; }
  .tutorial-card > p { margin: 7px auto 10px; }
}

@media (min-width: 600px) {
  #game {
    border-left: 4px solid rgba(255,255,255,.35);
    border-right: 4px solid rgba(255,255,255,.35);
    box-shadow: 0 0 45px rgba(10, 42, 62, 0.42);
  }
}
