:root {
  color-scheme: light;
  --ink: #342c31;
  --muted: #756a70;
  --cream: #fff8ec;
  --paper: rgba(255, 252, 246, .94);
  --orange: #f27638;
  --orange-dark: #d94e24;
  --pink: #ed438f;
  --blue: #20aee8;
  --green: #8fcf40;
  --shadow: 0 24px 70px rgba(93, 33, 18, .2);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #e96f38 url("assets/swf-image-14.jpg") center / cover fixed;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(31, 167, 229, .38); outline-offset: 3px; }

.game-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100dvh;
  margin: auto;
  padding: max(22px, env(safe-area-inset-top)) 0 max(26px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0 22px;
}

.brand, .level-pill {
  border: 0;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 8px 26px rgba(91, 37, 20, .13);
  cursor: pointer;
}

.brand {
  min-height: 58px;
  padding: 8px 22px 8px 9px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(1rem, 2vw, 1.28rem);
  font-weight: 850;
  letter-spacing: -.02em;
}

.brand-mark {
  width: 42px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #ffad3d, #f05235);
  box-shadow: inset 0 -4px 8px rgba(170, 44, 14, .25);
  font-size: 1.35rem;
}

.level-pill {
  min-height: 58px;
  padding: 8px 20px;
  border-radius: 18px;
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.level-pill span { color: var(--muted); font-size: .82rem; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; }
.level-pill strong { font-size: 1.45rem; }
.level-pill svg { width: 12px; fill: none; stroke: currentColor; stroke-width: 2; }

.play-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 720px);
  justify-content: center;
  align-items: center;
  gap: clamp(24px, 5vw, 68px);
}

.info-card {
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(15px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--orange-dark);
  font-size: .73rem;
  font-weight: 900;
  letter-spacing: .17em;
  text-transform: uppercase;
}

.info-card h1 {
  margin: 0 0 12px;
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  line-height: 1.02;
  letter-spacing: -.045em;
}

.info-card > p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .97rem; line-height: 1.55; }

.stats {
  margin: 26px 0 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats div { padding: 13px; border-radius: 16px; background: #fff3e6; }
.stats span { display: block; color: var(--muted); font-size: .72rem; font-weight: 750; }
.stats strong { display: block; margin-top: 2px; font-size: 1.45rem; }

.desktop-help { display: grid; gap: 10px; color: var(--muted); font-size: .82rem; }
.desktop-help span { display: flex; align-items: center; gap: 5px; }
kbd { min-width: 24px; height: 24px; padding: 2px 5px; border: 1px solid #decfc5; border-bottom-width: 3px; border-radius: 7px; display: inline-grid; place-items: center; color: var(--ink); background: white; font: 700 .72rem inherit; }

.actions { margin-top: 22px; display: flex; gap: 9px; }
.text-button { flex: 1; border: 1px solid #e8d9cc; border-radius: 12px; padding: 10px; color: var(--ink); background: white; font-weight: 800; cursor: pointer; }
.text-button:disabled { opacity: .38; cursor: default; }

.board-wrap {
  position: relative;
  width: min(100%, calc(100dvh - 138px));
  max-width: 720px;
  aspect-ratio: 1;
  padding: clamp(9px, 1.5vw, 15px);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: clamp(23px, 4vw, 38px);
  background: rgba(255, 251, 243, .88);
  box-shadow: 0 28px 80px rgba(100, 36, 20, .24), inset 0 0 0 1px rgba(213, 124, 73, .12);
  touch-action: none;
  user-select: none;
}

.board-wrap.bump { animation: board-bump .18s ease; }

canvas { width: 100%; height: 100%; display: block; border-radius: clamp(16px, 3vw, 28px); }

.toast {
  position: absolute;
  left: 50%;
  top: 22px;
  z-index: 2;
  transform: translate(-50%, -14px);
  padding: 10px 16px;
  border-radius: 999px;
  color: white;
  background: rgba(52, 44, 49, .9);
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  font-size: .82rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.touch-controls { display: none; }

.modal {
  width: min(92vw, 680px);
  max-height: min(88dvh, 760px);
  padding: 0;
  overflow: hidden auto;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 32px;
  color: var(--ink);
  background: #fffaf1;
  box-shadow: 0 40px 100px rgba(68, 25, 17, .38);
}
.modal::backdrop { background: rgba(58, 27, 25, .58); backdrop-filter: blur(8px); }

.intro-modal { display: none; grid-template-columns: .86fr 1.15fr; width: min(92vw, 780px); }
.intro-modal[open] { display: grid; animation: modal-in .35s cubic-bezier(.2,.8,.2,1); }

.intro-art {
  min-height: 390px;
  position: relative;
  overflow: hidden;
  background: var(--orange) url("assets/swf-image-14.jpg") center / cover;
}
.intro-art::after { content: ""; position: absolute; inset: auto -20% -22% -20%; height: 58%; border-radius: 50% 50% 0 0; background: rgba(255, 246, 223, .21); transform: rotate(-8deg); }

.sun { position: absolute; width: 150px; aspect-ratio: 1; border: 28px solid rgba(255,255,255,.13); border-radius: 50%; }
.sun-one { top: -70px; left: -65px; }.sun-two { right: -75px; bottom: -58px; }

.mascot {
  position: absolute;
  left: 50%; top: 49%;
  z-index: 1;
  width: 148px; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid; place-items: center;
  border: 8px solid #3f3539;
  border-radius: 48% 48% 44% 44%;
  color: white;
  background: linear-gradient(#ffb22f 0 38%, #fff 39% 100%);
  box-shadow: 0 18px 40px rgba(98, 34, 15, .25), inset 0 -10px 0 #eee3dd;
}
.mascot b { margin-top: 67px; width: 52px; height: 37px; display: grid; place-items: center; border-radius: 16px 16px 24px 24px; color: white; background: #3f3539; font-size: 1.35rem; }
.eye { position: absolute; top: 42px; width: 15px; height: 23px; border-radius: 50%; background: #3f3539; }.left-eye { left: 42px; }.right-eye { right: 42px; }
.smile { position: absolute; top: 70px; width: 58px; height: 28px; border-bottom: 6px solid #3f3539; border-radius: 50%; }

.modal-body { padding: clamp(28px, 5vw, 48px); align-self: center; }
.modal-body h2, .modal-heading h2 { margin: 0 0 14px; font-size: clamp(2.1rem, 6vw, 3.6rem); line-height: .95; letter-spacing: -.06em; }
.modal-body h2 span { color: var(--orange); }
.modal-body > p:not(.eyebrow) { margin: 0; color: var(--muted); line-height: 1.55; }
.intro-actions { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 10px; }
.primary-button, .secondary-button { min-height: 50px; padding: 0 20px; border-radius: 14px; font-weight: 850; cursor: pointer; }
.primary-button { flex: 1; border: 0; color: white; background: linear-gradient(135deg, #f59039, #eb5933); box-shadow: 0 10px 24px rgba(224, 78, 38, .25); }
.primary-button span { margin-left: 12px; }
.secondary-button { border: 1px solid #e4d5c8; color: var(--ink); background: white; }
.gesture-hint { margin-top: 20px !important; font-size: .77rem; }

.level-modal { width: min(92vw, 640px); }
.level-modal form { padding: clamp(24px, 4vw, 38px); }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.modal-heading h2 { font-size: clamp(2rem, 5vw, 3rem); }
.close-button { width: 42px; aspect-ratio: 1; border: 0; border-radius: 50%; color: var(--ink); background: #f4e8db; font-size: 1.7rem; cursor: pointer; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-choice { aspect-ratio: 1; border: 1px solid #eadbcf; border-radius: 15px; color: var(--ink); background: white; font-size: 1rem; font-weight: 850; cursor: pointer; }
.level-choice.current { color: white; border-color: transparent; background: linear-gradient(145deg, #f7973b, #ed5832); }
.level-choice.completed::after { content: "✓"; display: block; margin-top: -2px; color: #67ae37; font-size: .68rem; }
.level-choice.current::after { color: white; }

.win-modal { width: min(90vw, 480px); text-align: center; }
.win-modal[open] { animation: modal-in .28s cubic-bezier(.2,.8,.2,1); }
.win-body h2 { font-size: clamp(2rem, 7vw, 3rem); }
.win-icon { width: 72px; aspect-ratio: 1; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--green); box-shadow: 0 12px 28px rgba(101, 165, 48, .3); font-size: 2.3rem; font-weight: 900; }
.win-body .intro-actions { justify-content: center; }

@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }
@keyframes board-bump { 40% { transform: scale(.992); } }

@media (max-width: 850px) {
  .game-shell { width: min(100% - 22px, 650px); padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar { padding-bottom: 12px; }
  .brand { min-height: 48px; padding: 6px 14px 6px 7px; border-radius: 15px; }
  .brand-mark { width: 36px; border-radius: 10px; }
  .level-pill { min-height: 48px; padding: 7px 14px; border-radius: 15px; }
  .play-layout { display: flex; flex-direction: column; gap: 14px; }
  .info-card { width: 100%; padding: 14px 16px; border-radius: 20px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px 18px; }
  .info-card .eyebrow, .info-card h1, .info-card > p, .desktop-help, .actions { display: none; }
  .stats { margin: 0; display: contents; }
  .stats div { min-width: 94px; padding: 8px 12px; }
  .board-wrap { width: min(100%, calc(100dvh - 255px)); min-width: 280px; }
  .touch-controls { width: min(330px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-areas: ". up ." "left center right" ". down ."; gap: 7px; }
  .move-button { min-height: 48px; border: 1px solid rgba(255,255,255,.7); border-radius: 15px; color: var(--ink); background: rgba(255, 250, 242, .94); box-shadow: 0 6px 18px rgba(82,33,20,.13); font-size: 1.28rem; font-weight: 900; cursor: pointer; touch-action: manipulation; }
  .move-button:active { transform: translateY(2px); box-shadow: 0 2px 8px rgba(82,33,20,.12); }
  .move-button.up { grid-area: up; }.move-button.left { grid-area: left; }.move-button.center { grid-area: center; color: var(--orange-dark); }.move-button.right { grid-area: right; }.move-button.down { grid-area: down; }
}

@media (max-width: 600px) {
  .intro-modal[open] { display: block; }
  .intro-art { min-height: 210px; }
  .mascot { width: 112px; border-width: 6px; }
  .eye { top: 31px; }.left-eye { left: 31px; }.right-eye { right: 31px; }.smile { top: 55px; }.mascot b { margin-top: 55px; width: 42px; height: 30px; }
  .modal-body { padding: 27px; }
  .level-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-height: 700px) and (max-width: 850px) {
  .info-card { display: none; }
  .board-wrap { width: min(100%, calc(100dvh - 190px)); }
  .touch-controls { grid-template-columns: repeat(5, 1fr); grid-template-areas: "left up center down right"; }
}

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