:root {
  --ink: #2b2a26;
  --ink-soft: #6b665a;
  --paper: #fffaf0;
  --paper-2: #f5ecd6;
  --line: rgba(60, 50, 30, .14);
  --lake: #2f6fa3;
  --accent: #e8743b;
  --accent-ink: #fff;
  --ok: #4f9a3c;
  --gold: #f4b63f;
  --shadow: 0 6px 24px rgba(30, 40, 50, .18);
  --r: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  font-family: var(--font); color: var(--ink); background: #2f6fa3;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; height: 100dvh; display: none; }
.screen.active { display: flex; }

/* --- térkép --- */
#screen-map { flex-direction: column; background: #a6d47c; }
#lake { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-head {
  position: relative; z-index: 2; text-align: center;
  padding: calc(env(safe-area-inset-top) + 18px) 16px 0;
}
.map-head h1 { margin: 0; font-size: 30px; letter-spacing: .5px; color: #fffaf0; text-shadow: 0 2px 0 rgba(40, 70, 30, .35); }
.map-head p { margin: 2px 0 10px; color: #fffaf0; font-weight: 600; opacity: .95; text-shadow: 0 1px 0 rgba(40, 70, 30, .3); }
.pill {
  display: inline-block; padding: 6px 14px; border-radius: 999px; background: rgba(255, 250, 240, .92);
  font-weight: 700; font-size: 14px; box-shadow: var(--shadow);
}
.map-foot {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 18px);
  text-align: center; color: #fffaf0; font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.node { cursor: pointer; }
.node circle.base { stroke: #fffaf0; stroke-width: 3; }
.node text { font-family: var(--font); font-weight: 800; text-anchor: middle; dominant-baseline: central; }
.node .label { font-size: 11px; font-weight: 700; fill: #fffaf0; paint-order: stroke; stroke: rgba(30, 60, 30, .55); stroke-width: 3px; }
.node.open circle.base { fill: var(--accent); }
.node.open .pulse { fill: none; stroke: #fffaf0; stroke-width: 2; animation: pulse 1.6s ease-out infinite; transform-origin: center; transform-box: fill-box; }
.node.done circle.base { fill: var(--ok); }
.node.locked circle.base { fill: #a9a596; }
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(1.9); opacity: 0; } }

/* --- pálya --- */
#screen-game { flex-direction: column; background: linear-gradient(#cfe9f5, #a6d47c); }
.hud {
  background: var(--paper); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, .08); z-index: 3;
}
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
.turn { font-weight: 800; font-size: 16px; }
.wind { font-weight: 700; font-size: 15px; white-space: nowrap; }
.wind small { color: var(--ink-soft); font-weight: 600; }
.stats { justify-content: flex-start; gap: 14px; font-size: 14px; }
.stat { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 9px; height: 9px; border-radius: 50%; background: #e2d9c2; display: inline-block; }
.pips i.on { background: var(--accent); }
#hud-energy i.on { background: #f2c230; }
.intent { font-size: 13px; color: var(--ink-soft); font-weight: 600; min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: var(--paper-2); width: 36px; height: 32px; border-radius: 10px; font-size: 18px; }

#board { position: relative; flex: 1; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.bar {
  display: flex; align-items: center; gap: 10px; background: var(--paper); border-top: 1px solid var(--line);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); z-index: 3;
}
.ap { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 800; }
.ap-label { font-size: 13px; color: var(--ink-soft); }
.ap-pips i { width: 16px; height: 16px; background: #e2d9c2; }
.ap-pips i.on { background: var(--lake); }
.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 800; font-size: 16px; min-height: 46px;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #b9572a; }
.btn.ghost { background: var(--paper-2); min-width: 52px; font-size: 20px; }
.btn.block { width: 100%; }
.btn.ok { background: var(--ok); color: #fff; box-shadow: 0 3px 0 #376e29; }

/* koppintós akciómenü */
.tile-menu {
  position: absolute; z-index: 5; width: min(264px, calc(100% - 24px));
  background: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); padding: 10px;
  border: 1px solid var(--line); animation: pop .12s ease-out;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tile-menu h3 { margin: 2px 4px 2px; font-size: 15px; }
.tile-menu .info { margin: 0 4px 8px; font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.tile-menu .acts { display: flex; flex-direction: column; gap: 6px; }
.act {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  border: 0; border-radius: 12px; padding: 11px 12px; background: var(--paper-2); font-weight: 700; font-size: 15px; text-align: left;
}
.act .cost { font-size: 12px; font-weight: 800; color: var(--lake); white-space: nowrap; }
.act.armed { background: var(--ok); color: #fff; }
.act.armed .cost { color: #fff; }
.act.warn { box-shadow: inset 0 0 0 2px #d9534f; }
.act:disabled { opacity: .5; }
.act small { display: block; font-weight: 600; font-size: 12px; opacity: .85; }
.act.cancel { background: transparent; justify-content: center; color: var(--ink-soft); padding: 8px; }

#toasts {
  position: absolute; z-index: 4; left: 0; right: 0; top: 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; padding: 0 12px;
}
.toast {
  background: rgba(43, 42, 38, .88); color: #fffaf0; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow); animation: toast-in .2s ease-out; max-width: 100%; text-align: center;
}
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* lapok */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(20, 35, 45, .45); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto; background: var(--paper);
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: var(--shadow); animation: slide .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slide { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet .kicker { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.sheet p { line-height: 1.45; margin: 8px 0; }
.sheet .muted { color: var(--ink-soft); font-size: 14px; }
.sheet .facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.sheet .facts span { background: var(--paper-2); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 700; }
.toys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
.toy {
  border: 2px solid transparent; background: var(--paper-2); border-radius: 14px; padding: 10px 6px; text-align: center;
}
.toy.sel { border-color: var(--accent); background: #fff; }
.toy .e { font-size: 30px; display: block; }
.toy b { display: block; font-size: 14px; margin-top: 2px; }
.toy small { display: block; font-size: 11px; color: var(--ink-soft); line-height: 1.3; margin-top: 4px; }
.btns { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.stars { font-size: 42px; letter-spacing: 6px; text-align: center; margin: 6px 0; }
.stars .off { opacity: .2; filter: grayscale(1); }
.help li { margin: 6px 0; line-height: 1.4; }
.help ul { padding-left: 20px; margin: 6px 0; }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 14px; align-items: center; margin: 8px 0; }
.legend i { width: 22px; height: 18px; border-radius: 5px; display: inline-block; }
pre.solve { background: var(--paper-2); padding: 10px; border-radius: 10px; font-size: 12px; white-space: pre-wrap; }

#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; background: var(--lake); color: #fffaf0;
  align-items: center; justify-content: center; text-align: center; font-size: 20px; font-weight: 800; line-height: 1.6; padding: 24px;
}
@media (orientation: landscape) and (max-height: 520px) { #rotate { display: flex; } }
