:root {
  --ink: #173326;
  --ink2: #0F2419;
  --cream: #FFF3DE;
  --leaf: #3FAF5A;
  --leaf2: #8BE06A;
  --berry: #E8423A;
  --berry2: #B42A24;
  --amber: #FFC23D;
  --amber2: #C98A0B;
  --outline: #1F1A2B;
  --pixel: "Press Start 2P", monospace;
  --display: "Titan One", "Rubik", sans-serif;
  --body: "Rubik", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #0E1A14; color: var(--cream); font-family: var(--body);
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
#stage { position: fixed; inset: 0; }
#game { display: block; width: 100%; height: 100%; }
svg { width: 1em; height: 1em; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------------------------------------------------------- HUD */
.hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: flex-start; gap: clamp(10px, 3vw, 44px);
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  font-family: var(--pixel); font-size: clamp(10px, 1.35vw, 15px); letter-spacing: .04em;
  pointer-events: none; text-shadow: 2px 2px 0 rgba(15, 20, 30, .75);
}
.hud[hidden] { display: none; }
.hc { display: flex; flex-direction: column; gap: 5px; }
.hc small { font-size: .72em; opacity: .85; }
.hc b { font-weight: 400; }
.hc:has(.ico) { flex-direction: row; align-items: center; gap: 6px; margin-top: .55em; }
.hc .ico { width: 1.5em; height: 1.5em; filter: drop-shadow(2px 2px 0 rgba(15, 20, 30, .6)); }
.hc.low b { color: #FFB0A0; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.hbtns { margin-left: auto; display: flex; gap: 8px; pointer-events: auto; }

.ib {
  width: 42px; height: 42px; border-radius: 14px; border: 2.5px solid var(--outline);
  background: var(--cream); color: var(--ink); display: grid; place-items: center; padding: 0;
  box-shadow: 0 3px 0 var(--outline);
}
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--outline); }
.ib.small { width: 36px; height: 36px; border-radius: 12px; }
.mute .offi { display: none; }
.mute.off .on { display: none; }
.mute.off .offi { display: block; }

/* ---------------------------------------------------------- panels */
.panel {
  position: fixed; z-index: 10; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 440px); max-height: 92vh; overflow: auto;
  background: linear-gradient(#20443A, var(--ink)); border: 3px solid var(--outline); border-radius: 26px;
  padding: 26px 24px 22px; text-align: center;
  box-shadow: 0 6px 0 var(--outline), 0 24px 60px rgba(0, 0, 0, .45), inset 0 2px 0 rgba(255, 255, 255, .12);
}
.panel[hidden] { display: none; }
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 34px; margin: 0 0 14px; color: var(--cream); letter-spacing: .01em; text-shadow: 0 3px 0 var(--outline); }
.note { font-size: 14px; opacity: .72; margin: 14px 0 0; line-height: 1.45; }
.big { font-family: var(--pixel); font-size: 20px; margin: 4px 0 20px; color: var(--amber); }
.kick { font-family: var(--pixel); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--leaf2); margin: 0 0 10px; }
.say { font-size: 16px; line-height: 1.5; margin: 0 0 20px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  font-family: var(--display); font-size: 21px; letter-spacing: .02em;
  padding: 13px 18px 12px; margin: 0 0 12px; border-radius: 18px;
  border: 3px solid var(--outline); background: var(--berry); color: #FFF;
  box-shadow: 0 5px 0 var(--outline), inset 0 -5px 0 var(--berry2), inset 0 3px 0 rgba(255, 255, 255, .25);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--outline), inset 0 -3px 0 var(--berry2); }
.btn.alt { background: var(--amber); color: var(--ink2); box-shadow: 0 5px 0 var(--outline), inset 0 -5px 0 var(--amber2), inset 0 3px 0 rgba(255, 255, 255, .35); text-shadow: none; }
.btn.ghost { background: var(--cream); color: var(--ink); box-shadow: 0 5px 0 var(--outline), inset 0 -5px 0 #E3CFA8; text-shadow: none; }
.btn:focus-visible, .ib:focus-visible, .cell:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

/* title */
.panel.title { top: auto; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(23, 51, 38, .9); backdrop-filter: blur(4px); padding-top: 18px; }
.logo { position: relative; margin: 0 0 6px; font-family: var(--display); font-weight: 400; font-size: clamp(56px, 12vw, 78px); line-height: 1; letter-spacing: .01em; display: flex; justify-content: center; }
.logo span { color: var(--amber); -webkit-text-stroke: 3px var(--outline); paint-order: stroke fill; text-shadow: 0 5px 0 var(--outline); display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo span:nth-child(2) { color: var(--leaf2); animation-delay: .1s; }
.logo span:nth-child(3) { color: #FF8A6A; animation-delay: .2s; }
.logo span:nth-child(4) { color: var(--cream); animation-delay: .3s; }
.logo span:nth-child(5) { color: var(--leaf2); animation-delay: .4s; }
.logo span:nth-child(6) { color: var(--amber); animation-delay: .5s; }
.logo .leaf { position: absolute; width: 44px; height: 34px; left: calc(50% + 72px); top: -18px; transform: rotate(12deg); }
@keyframes bob { 50% { transform: translateY(-5px); } }
.tag { margin: 4px 0 18px; font-size: 16px; opacity: .9; }
.menu .btn { margin-bottom: 10px; }
.top { font-size: 13px; margin: 12px 0 8px; opacity: .8; }
.top b { font-family: var(--pixel); font-weight: 400; font-size: 12px; color: var(--amber); margin-left: 6px; }
.keys { font-size: 13px; opacity: .72; margin: 0 0 10px; line-height: 2; }
kbd { font-family: var(--pixel); font-size: 9px; background: rgba(255, 255, 255, .12); border: 1.5px solid rgba(255, 255, 255, .25); border-radius: 6px; padding: 3px 6px; margin: 0 2px 0 8px; }
kbd:first-child { margin-left: 0; }
.foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.foot a { color: var(--leaf2); font-weight: 600; font-size: 14px; }
body.touch .keys { display: none; }

/* level select */
.panel.levels { width: min(94vw, 560px); }
.phead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.phead h2 { margin: 0; }
.lgrid { display: grid; gap: 14px; }
.wrow h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 19px; text-align: left; }
.wrow h3 b { font-family: var(--pixel); font-weight: 400; font-size: 12px; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--cream); color: var(--ink); border: 2px solid var(--outline); }
.cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.cell {
  border: 2.5px solid var(--outline); border-radius: 14px; padding: 10px 4px 8px; min-height: 64px;
  background: #3E7E54; color: var(--cream); box-shadow: 0 4px 0 var(--outline), inset 0 -4px 0 rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.cell.w1 { background: #B8703A; } .cell.w2 { background: #4E6AA8; } .cell.w3 { background: #8C3A30; }
.cell b { font-family: var(--pixel); font-weight: 400; font-size: 13px; }
.cell small { font-size: 11px; opacity: .85; line-height: 1.15; }
.cell svg { width: 22px; height: 22px; opacity: .6; }
.cell:disabled { filter: grayscale(.6) brightness(.7); cursor: default; }
.cell.done { box-shadow: 0 4px 0 var(--outline), inset 0 -4px 0 rgba(0, 0, 0, .18), inset 0 0 0 3px var(--amber); }

/* world card */
.panel.card { inset: 0; left: 0; top: 0; transform: none; width: auto; max-height: none; border: 0; border-radius: 0; background: #0E1A14; box-shadow: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.panel.card[hidden] { display: none; }
.cw { font-family: var(--pixel); font-size: clamp(18px, 3vw, 28px); margin: 0; }
.cn { font-family: var(--display); font-size: clamp(26px, 4.4vw, 42px); color: var(--amber); margin: 0; text-shadow: 0 3px 0 var(--outline); }
.cl { display: flex; align-items: center; gap: 12px; font-family: var(--pixel); font-size: 18px; margin: 10px 0 0; }
.cl svg { width: 38px; height: 38px; }
.cl b { font-weight: 400; }

.turn { display: none; font-size: 14px; opacity: .7; margin: 18px 0 0; }
@media (orientation: portrait) { body.touch .turn { display: block; } }
.panel.small { width: min(90vw, 380px); }
.rescue h2 { color: var(--amber); }

/* ---------------------------------------------------------- touch */
.touch { display: none; }
body.touch[data-screen="play"] .touch { display: flex; }
.touch {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; justify-content: space-between; align-items: flex-end;
  padding: 0 max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  pointer-events: none;
}
.tpad { pointer-events: auto; width: 168px; height: 118px; position: relative; touch-action: none; }
.tpad i { position: absolute; border-radius: 20px; background: rgba(255, 243, 222, .22); border: 2.5px solid rgba(255, 243, 222, .45); }
.tpad .al { left: 0; top: 0; width: 78px; height: 74px; }
.tpad .ar { right: 0; top: 0; width: 78px; height: 74px; }
.tpad .ad { left: 50%; bottom: 0; width: 58px; height: 38px; transform: translateX(-50%); }
.tpad .al::after, .tpad .ar::after, .tpad .ad::after { content: ""; position: absolute; left: 50%; top: 50%; width: 0; height: 0; border: 11px solid transparent; transform: translate(-50%, -50%); }
.tpad .al::after { border-right-color: rgba(255, 255, 255, .85); margin-left: -6px; }
.tpad .ar::after { border-left-color: rgba(255, 255, 255, .85); margin-left: 6px; }
.tpad .ad::after { border-top-color: rgba(255, 255, 255, .85); border-width: 9px; margin-top: 4px; }
.tpad[data-dir="l"] .al, .tpad[data-dir="r"] .ar, .tpad[data-dir="d"] .ad { background: rgba(255, 243, 222, .5); }
.tbtns { pointer-events: auto; display: flex; gap: 14px; align-items: flex-end; }
.tb {
  width: 76px; height: 76px; border-radius: 50%; border: 3px solid rgba(31, 26, 43, .8);
  font-family: var(--pixel); font-size: 18px; color: #FFF; touch-action: none;
  box-shadow: 0 4px 0 rgba(31, 26, 43, .8);
}
.tb.a { background: rgba(232, 66, 58, .82); margin-bottom: 30px; }
.tb.b { background: rgba(255, 194, 61, .78); color: var(--ink2); }
.tb.on { transform: translateY(3px); box-shadow: 0 1px 0 rgba(31, 26, 43, .8); filter: brightness(1.15); }
@media (orientation: portrait) {
  body.touch[data-screen="play"] #stage, body.touch[data-screen="card"] #stage { bottom: 190px; }
  body.touch[data-screen="play"] .touch { height: 190px; align-items: center; background: #122219; }
}

/* ---------------------------------------------------------- share image (?demo&og) */
.ogmark { display: none; }
body.og .ogmark { display: flex; flex-direction: column; align-items: flex-start; position: fixed; left: 5%; top: 7%; z-index: 8; }
body.og .ogmark .logo { font-size: 104px; }
body.og .ogmark .logo span { animation: none; }
body.og .ogmark p { font-family: var(--display); font-size: 30px; color: #FFF; margin: 14px 0 0 6px; text-shadow: 0 3px 0 var(--outline); -webkit-text-stroke: 1.5px var(--outline); paint-order: stroke fill; }

/* ---------------------------------------------------------- demo (hub iframe): canvas only */
body.demo .panel, body.demo .hud, body.demo .touch { display: none !important; }
@media (max-width: 560px) {
  .hud { gap: 12px; font-size: 9px; }
  .hc:nth-child(3) { display: none; }
  .ib { width: 36px; height: 36px; border-radius: 12px; }
  .panel { padding: 20px 16px 16px; }
  .btn { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) { .logo span { animation: none; } }
