:root {
  --ink: #1f2a33; --paper: #fffaf0; --water: #3fa7d6; --grass: #6dbb4a; --accent: #ff8a3d; --bad: #e5484d; --ok: #2fa86b;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e1a20; color: var(--ink);
  font: 600 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
/* the game lives in a portrait frame, centred, dark backdrop either side on wide screens */
#frame { position: relative; margin: 0 auto; height: 100vh; height: 100dvh; width: min(100vw, calc(100vh * 0.62), 560px); width: min(100vw, calc(100dvh * 0.62), 560px);
  overflow: hidden; background: #8fd3ee; box-shadow: 0 0 60px rgba(0,0,0,.6); }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

#top { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-t)) 10px 6px; display: flex; align-items: center; gap: 8px; pointer-events: none; }
#top > * { pointer-events: auto; }
.icon { width: 42px; height: 42px; border-radius: 12px; background: var(--paper); box-shadow: 0 3px 0 rgba(0,0,0,.18); font-size: 20px; }
#title { flex: 1; text-align: center; background: rgba(255,250,240,.92); border-radius: 12px; padding: 5px 8px; box-shadow: 0 3px 0 rgba(0,0,0,.12); }
#title b { display: block; font-size: 16px; }
#title span { font-size: 12px; opacity: .75; }

#rules { position: absolute; left: 8px; right: 8px; top: calc(62px + var(--safe-t)); display: flex; flex-wrap: wrap; justify-content: center;
  gap: 5px; margin: 0 auto; max-width: 560px; pointer-events: none; }
.rule { display: flex; align-items: center; gap: 3px; background: rgba(255,250,240,.94); border-radius: 10px; padding: 3px 6px; box-shadow: 0 2px 0 rgba(0,0,0,.12);
  transition: opacity .15s, transform .15s; }
.rule img { width: 28px; height: 28px; border-radius: 7px; background: #e9f4fa; }
.rule .sym { font-size: 15px; min-width: 16px; text-align: center; }
.rule.eats .sym, .rule.fights .sym { color: var(--bad); }
.rule.guards .sym { color: var(--ok); }
#rules.focus .rule { opacity: .25; }
#rules.focus .rule.hit { opacity: 1; transform: scale(1.06); }

#bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(10px + var(--safe-b)); display: flex; gap: 8px; align-items: stretch; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#bottom button { border-radius: 16px; box-shadow: 0 4px 0 rgba(0,0,0,.2); display: flex; flex-direction: column; align-items: center; justify-content: center; }
#bottom button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.side { width: 68px; background: var(--paper); font-size: 22px; padding: 6px 0; }
.side small { font-size: 11px; }
#row { flex: 1; background: var(--accent); color: #fff; font-size: 22px; padding: 8px 0; text-shadow: 0 1px 0 rgba(0,0,0,.2); }
#row small { font-size: 12px; opacity: .95; }
#row:disabled, .side:disabled { opacity: .45; }

#toast { position: absolute; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--ink); color: #fff;
  padding: 9px 14px; border-radius: 12px; max-width: 90%; text-align: center; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,40,60,.45); padding: 16px; }
.overlay[hidden] { display: none; }
.card { background: var(--paper); border-radius: 20px; padding: 18px; width: min(92%, 420px); max-height: 88%; overflow: auto; text-align: center; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.card h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.5px; }
.card p { margin: 6px 0 12px; font-weight: 500; }
#panelStars { font-size: 34px; letter-spacing: 4px; color: #f2b01e; min-height: 0; }
#levelGrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0; }
#levelGrid button { aspect-ratio: 1; border-radius: 14px; background: #e3f2fa; font-size: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 0 rgba(0,0,0,.12); }
#levelGrid button small { font-size: 10px; color: #f2b01e; letter-spacing: 1px; }
#levelGrid button.locked { opacity: .4; }
#panelButtons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#panelButtons button { padding: 11px 18px; border-radius: 14px; background: #e3f2fa; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
#panelButtons button.primary { background: var(--accent); color: #fff; }
.help { text-align: left; font-weight: 500; }
.help li { margin: 4px 0; }

/* trouble: a centre card over the dimmed scene, the faces involved, Undo / Restart */
#alert { z-index: 20; animation: fade .25s ease-out; }
#alert .card.fail { border: 4px solid var(--bad); animation: pop .3s cubic-bezier(.2, 1.4, .4, 1); }
#alert h1 { color: var(--bad); font-size: 34px; }
#alertFaces { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 10px 0 6px; }
#alertFaces img { width: 84px; height: 84px; border-radius: 18px; background: #e9f4fa; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
#alertFaces img:last-child { transform: rotate(-12deg); filter: saturate(.6); }
#alertFaces img:only-child { transform: none; }
#alertFaces span { font-size: 30px; color: var(--bad); font-weight: 900; }
#alertText { font-size: 20px; font-weight: 800; margin: 8px 0 16px; }
.failButtons { display: flex; gap: 10px; justify-content: center; }
.failButtons button { padding: 13px 20px; border-radius: 14px; font-size: 17px; background: #e3f2fa; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.failButtons button.primary { background: var(--accent); color: #fff; }
.rule.alarm { opacity: 1 !important; background: #ffe1e1; box-shadow: 0 0 0 2px var(--bad); animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
#bottom button[hidden], .failButtons button[hidden] { display: none; }
.rule img, #alertFaces img { filter: saturate(1.25) contrast(1.05); }
#alertFaces img:last-child { filter: saturate(.75); }
#alertFaces img:only-child { filter: saturate(1.25) contrast(1.05); }
/* a fight has no loser: both faces level and coloured, crossed swords between */
#alertFaces.fights img:last-child { transform: none; filter: saturate(1.25) contrast(1.05); }
