/* Layout: full-bleed canvas island, floating sticker-style HUD chips, bottom toolbar,
   sheets that slide up above it, Moni néni's dialog box and a centered task card. */
:root {
  --sea: #1b8fb5;
  --ink: #1f2a44;
  --paper: #fffaf0;
  --sun: #ffc23d;
  --coral: #ff6f59;
  --leaf: #3fae5a;
  --muted: #6b7590;
  --line: #e6dcc4;
  --good: #3fae5a;
  --bad: #e5484d;
  --display: "Chewy", "Comic Sans MS", system-ui, sans-serif;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--sea); color: var(--ink); font-family: var(--body); font-size: 15px;
  overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none;
}
input, .task .q, .dialog p, .steps, .hints { -webkit-user-select: text; user-select: text; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 5; pointer-events: none;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.chip {
  pointer-events: auto; background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 999px; padding: 5px 14px 5px 8px;
  font-weight: 900; font-size: 15px; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 0 var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip .dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.chip svg { width: 24px; height: 24px; flex: none; }
.left-hud { display: flex; gap: 8px; flex-wrap: wrap; min-width: 0; }
#coinChip.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.15); } }

.goal {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  top: calc(64px + env(safe-area-inset-top, 0px));
  max-width: calc(100% - 24px); display: flex; align-items: center; gap: 8px;
  background: var(--sun); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink);
  padding: 6px 14px 6px 8px; font-weight: 900; font-size: 14px; line-height: 1.25;
}
.goal svg { width: 22px; height: 22px; flex: none; }

/* ---------- toolbar ---------- */
.toolbar {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 6px; padding: 7px; background: var(--paper);
  border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 5px 0 var(--ink);
}
.tool {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 72px; padding: 6px 8px; border: 0; border-radius: 16px; background: transparent;
  font: 800 13px var(--body); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.tool svg, .tool canvas { width: 30px; height: 30px; }
.tool:hover { background: #f3ead6; }
.tool[aria-pressed="true"] { background: var(--sun); }
.tool .ping {
  position: absolute; top: 4px; right: 12px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--coral); border: 2px solid var(--ink); animation: ping 1s ease-in-out infinite alternate;
}
@keyframes ping { to { transform: scale(1.3); } }
button:focus-visible, input:focus-visible, .card:focus-visible { outline: 3px solid var(--coral); outline-offset: 2px; }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; z-index: 7; left: 50%; transform: translateX(-50%);
  bottom: calc(102px + env(safe-area-inset-bottom, 0px));
  width: min(560px, calc(100% - 24px)); max-height: 48vh; overflow-y: auto;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink); padding: 14px 16px 16px;
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 16px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
h2 { font: 400 26px/1.1 var(--display); letter-spacing: .5px; margin: 0; text-wrap: balance; }
h3 { font: 900 12px var(--body); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 14px 0 6px; }
h3.first { margin-top: 0; }
.hint { margin: 0 0 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.x {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ink); background: var(--paper);
  font: 900 18px/1 var(--body); color: var(--ink); cursor: pointer; flex: none;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 8px;
  border: 3px solid var(--line); border-radius: 16px; background: #fff; cursor: pointer;
  font: 800 13px var(--body); color: var(--ink);
}
.card canvas { width: 64px; height: 64px; }
.card .price { display: flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.card .price svg { width: 14px; height: 14px; flex: none; }
.card[aria-pressed="true"] { border-color: var(--ink); background: #fff3cf; }
.card.poor { opacity: .45; }
.card.locked { opacity: .55; cursor: not-allowed; }
.btn {
  border: 3px solid var(--ink); border-radius: 14px; padding: 9px 16px; background: #fff;
  font: 900 16px var(--body); color: var(--ink); cursor: pointer; box-shadow: 0 3px 0 var(--ink);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--sun); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.avatar-wrap { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.avatar-wrap > div { flex: 1 1 220px; min-width: 0; }
#avatarPreview { width: 140px; height: 140px; background: #e9f7ee; border: 3px solid var(--ink); border-radius: 20px; flex: none; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt {
  border: 3px solid var(--line); background: #fff; border-radius: 12px; padding: 5px 10px;
  font: 800 13px var(--body); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.opt svg { width: 14px; height: 14px; }
.opt[aria-pressed="true"] { border-color: var(--ink); background: #fff3cf; }
.opt:disabled { opacity: .5; cursor: not-allowed; }
.swatch { width: 34px; height: 34px; padding: 0; border-radius: 50%; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
input[type="text"] {
  width: 100%; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px;
  font: 800 17px var(--body); color: var(--ink); background: #fff; min-width: 0;
}

.meter { position: relative; height: 34px; border: 3px solid var(--ink); border-radius: 12px; background: #bfe6f2; overflow: hidden; margin: 6px 0 10px; }
.zone { position: absolute; top: 0; bottom: 0; background: var(--leaf); }
.marker { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: var(--ink); border-radius: 3px; }
#fishMsg { font-weight: 800; margin: 0 0 10px; min-height: 1.4em; }
.catch { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
#fishPic { width: 120px; height: 70px; flex: none; }
.log-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; font-weight: 700; font-size: 14px; }
.log-list li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 2px dotted var(--line); padding: 3px 0; font-variant-numeric: tabular-nums; }
.log-list li.none { color: var(--muted); }

/* journal */
.topic-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-bottom: 2px dotted var(--line); }
.topic-row b { font-weight: 900; }
.topic-row .stars { color: #d39a00; font-size: 18px; letter-spacing: 2px; }
.topic-row small { grid-column: 1 / -1; color: var(--muted); font-weight: 700; }
.chapters { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.chapters li { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; }
.pill { border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 900; background: #fff; }
.pill.kész { background: #c9f0d2; }
.pill.folyamatban { background: var(--sun); }
.pill.zárva { color: var(--muted); border-color: var(--line); }

/* ---------- Moni néni ---------- */
.portrait { width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--ink); background: #ffe6ef; flex: none; }
.portrait.small { width: 54px; height: 54px; }
.dialog {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%);
  bottom: calc(102px + env(safe-area-inset-bottom, 0px));
  width: min(600px, calc(100% - 24px)); display: flex; gap: 14px; align-items: flex-start;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink);
  padding: 14px 16px; animation: rise .22s ease-out;
}
.dlg-body { flex: 1; min-width: 0; }
.dlg-name { font: 400 22px/1 var(--display); color: var(--coral); letter-spacing: .5px; }
.dialog p { margin: 6px 0 10px; font-weight: 700; font-size: 16px; line-height: 1.45; min-height: 3em; }

.modal-bg { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; background: rgba(31, 42, 68, .35); padding: 12px; overflow-y: auto; }
.task {
  width: min(560px, 100%); background: var(--paper); border: 3px solid var(--ink); border-radius: 24px;
  box-shadow: 0 7px 0 var(--ink); padding: 14px 16px 16px; display: grid; gap: 12px; animation: pop .2s ease-out;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.task-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-head h2 { margin-right: auto; }
.topic-chip { background: var(--leaf); color: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px; font-weight: 900; font-size: 12px; }
.lvl { color: #d39a00; font-weight: 900; font-size: 15px; letter-spacing: 1px; }
.moni-row { display: flex; gap: 10px; align-items: center; }
.moni-say {
  position: relative; margin: 0; flex: 1; min-width: 0; background: #fff; border: 2px solid var(--line);
  border-radius: 14px; padding: 8px 12px; font-weight: 700; font-size: 14px; line-height: 1.4;
}
.moni-say::before { content: ""; position: absolute; left: -9px; top: 50%; margin-top: -7px; border: 7px solid transparent; border-right-color: var(--line); border-left: 0; }
.q { font-weight: 800; font-size: 20px; line-height: 1.5; }
.ans { display: flex; gap: 8px; flex-wrap: wrap; }
.ans input { flex: 1 1 140px; font-size: 20px; }
.ans input.good { border-color: var(--good); background: #e9f9ed; }
.ans input.badin { border-color: var(--bad); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.btn.key { width: 46px; padding: 9px 0; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.choices:empty { display: none; }
.choices .btn { font-size: 17px; }
.choices .btn.good { background: #c9f0d2; }
.choices .btn.badin { background: #ffd6d6; }
.hints, .steps { margin: 0; padding: 0; display: grid; gap: 6px; }
.hints:empty { display: none; }
.hints li { list-style: none; background: #fff3cf; border: 2px solid #f0d58a; border-radius: 12px; padding: 7px 12px; font-weight: 700; line-height: 1.45; }
.steps { counter-reset: s; background: #eef8ff; border: 2px solid #b9dcf3; border-radius: 12px; padding: 8px 12px; }
.steps li { list-style: none; counter-increment: s; font-weight: 700; line-height: 1.5; display: flex; gap: 8px; }
.steps li::before { content: counter(s) "."; color: var(--muted); font-weight: 900; }
.steps li.answer { color: #1d7a37; font-weight: 900; }
.task-foot { align-items: center; }

/* ---------- puzzles ---------- */
.task.puzzle { width: min(660px, 100%); }
.pz-goal { margin: 0; font-weight: 800; font-size: 18px; line-height: 1.5; }
.pz-body { display: grid; gap: 10px; min-width: 0; }
.pz-note { margin: 0; color: var(--muted); font-weight: 700; font-size: 13px; }
.pz-readout { margin: 0; font-weight: 700; }
.ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .9; transform: rotate(-3deg) scale(1.05); box-shadow: 0 8px 16px rgba(0,0,0,.25); }
.lifting { opacity: .35; }
.gap-hint { color: var(--muted); font-weight: 800; font-size: 13px; margin: auto; }

.scale-wrap { position: relative; width: min(100%, 420px); margin: 0 auto; }
.scale-wrap svg { display: block; width: 100%; height: auto; }
.sack-label { position: absolute; transform: translate(-50%, -50%); background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 1px 8px; font-weight: 900; font-size: 15px; white-space: nowrap; pointer-events: none; }
.piles { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.pile-row { display: flex; gap: 6px; align-items: center; }
.pile {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; background: #fff; border: 3px solid var(--line);
  border-radius: 14px; cursor: grab; font-weight: 700; touch-action: none;
}
.pile svg { width: 36px; height: 36px; flex: none; }
.pile span { display: grid; line-height: 1.2; }
.pile small { color: var(--muted); font-weight: 800; display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.pile .cnt { font-weight: 900; color: var(--ink); background: #fff3cf; border-radius: 8px; padding: 2px 6px; }

.bridge { display: grid; grid-template-columns: 36px 1fr 36px; align-items: end; height: 84px; background: linear-gradient(transparent 58%, #4fb3d9 58%); border-radius: 12px; overflow: visible; }
.bank { height: 64px; background: #56c271; border: 3px solid var(--ink); border-left: 0; border-radius: 0 12px 0 0; box-shadow: inset 0 -18px 0 #a8754a; }
.bank.r { border-left: 3px solid var(--ink); border-right: 0; border-radius: 12px 0 0 0; }
.gap { position: relative; height: 64px; display: flex; align-items: flex-start; }
.gap::after { content: ""; position: absolute; left: 0; right: 0; top: 2px; border-top: 3px dashed rgba(31,42,68,.35); }
.plank {
  height: 38px; min-width: 44px; display: grid; place-items: center; padding: 0 6px; background: #c08a55;
  border: 3px solid var(--ink); border-radius: 8px; font-weight: 900; color: var(--ink); cursor: grab; touch-action: none;
  background-image: repeating-linear-gradient(90deg, transparent 0 14px, rgba(122,79,42,.25) 14px 16px);
}
.plank.placed { position: absolute; top: 0; min-width: 0; padding: 0; border-radius: 4px; z-index: 1; }
.plank.over { background-color: #ff8a80; }
.tray { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 36px; min-height: 58px; background: #f3ead6; border: 2px dashed var(--line); border-radius: 12px; }

.fence-grid { display: grid; width: min(100%, 460px); margin: 0 auto; background: #8a5a32; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; touch-action: none; }
.cell { aspect-ratio: 1; background: #56c271; border: 1px solid rgba(31,42,68,.18); cursor: crosshair; }
.cell.in { background: #8a5a32; background-image: radial-gradient(circle at 50% 60%, #3fae5a 0 18%, transparent 20%); }
.cell.t { border-top: 4px solid #f0d58a; } .cell.b { border-bottom: 4px solid #f0d58a; }
.cell.l { border-left: 4px solid #f0d58a; } .cell.r { border-right: 4px solid #f0d58a; }
.cell.anchor { outline: 3px solid var(--coral); outline-offset: -3px; }

.map-wrap { width: min(100%, 400px); margin: 0 auto; }
.map { display: block; width: 100%; height: auto; cursor: crosshair; border: 3px solid var(--ink); border-radius: 14px; touch-action: none; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.good {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 4px; background: #fff; border: 3px solid var(--line);
  border-radius: 14px; cursor: grab; font-size: 14px; touch-action: none; text-align: center;
}
.good svg { width: 40px; height: 40px; }
.good .tag { font-weight: 800; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.good .off { position: absolute; top: -8px; right: -6px; background: var(--bad); color: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 0 7px; font-weight: 900; font-size: 12px; transform: rotate(8deg); }
.basket { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 92px; padding: 10px; background: #fbe9cf; border: 3px dashed #c08a55; border-radius: 16px; }
.basket .good { width: 104px; }
.basket-title { display: flex; align-items: center; gap: 6px; font: 400 20px var(--display); width: 100%; }
.basket-title svg { width: 24px; height: 24px; }

.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .85em; line-height: 1.05; margin: 0 .12em; }
.fr > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .2em; }

.chapter-card {
  position: fixed; inset: 0; z-index: 11; display: grid; place-content: center; text-align: center; gap: 6px;
  background: rgba(31, 42, 68, .55); color: var(--paper); pointer-events: none; animation: fade 2.6s ease both;
}
#chapterSmall { font: 900 16px var(--body); text-transform: uppercase; letter-spacing: 3px; }
#chapterBig { font: 400 clamp(40px, 10vw, 76px)/1 var(--display); color: var(--sun); text-shadow: 4px 4px 0 var(--ink); letter-spacing: 1px; }
@keyframes fade { 0% { opacity: 0; } 15%, 80% { opacity: 1; } 100% { opacity: 0; } }

#toast {
  position: fixed; z-index: 12; left: 50%; transform: translateX(-50%);
  top: calc(112px + env(safe-area-inset-top, 0px));
  background: var(--ink); color: var(--paper); font-weight: 800; padding: 8px 16px; border-radius: 999px;
  max-width: calc(100% - 32px); text-align: center; transition: opacity .3s;
}
#toast.hide { opacity: 0; pointer-events: none; }

.intro-bg { position: fixed; inset: 0; z-index: 13; display: grid; place-items: center; background: rgba(31, 42, 68, .4); padding: 16px; overflow-y: auto; }
.intro {
  width: min(440px, 100%); background: var(--paper); border: 3px solid var(--ink); border-radius: 26px;
  box-shadow: 0 8px 0 var(--ink); padding: 22px 22px 20px; display: grid; gap: 12px;
}
.intro h1 { font: 400 46px/1 var(--display); margin: 0; color: var(--coral); letter-spacing: 1px; text-shadow: 3px 3px 0 var(--ink); }
.intro p { margin: 0; font-weight: 600; line-height: 1.45; }
.intro h3 { margin: 0; }
.grades { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grade {
  border: 3px solid var(--line); background: #fff; border-radius: 12px; padding: 6px 0 4px; cursor: pointer;
  font: 400 22px/1 var(--display); color: var(--ink); display: grid; gap: 2px; justify-items: center;
}
.grade small { font: 800 9px var(--body); color: var(--muted); }
.grade[aria-pressed="true"] { border-color: var(--ink); background: var(--sun); }
.grade:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 520px) {
  .tool { min-width: 0; padding: 6px 4px; font-size: 11px; flex: 1; }
  .toolbar { width: calc(100% - 16px); gap: 2px; }
  .sheet, .dialog { bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
  .dialog { gap: 10px; padding: 12px; }
  .portrait { width: 54px; height: 54px; }
  .dialog p { font-size: 15px; }
  .q { font-size: 18px; }
  .chip { font-size: 13px; padding: 4px 10px 4px 6px; }
  .goal { top: calc(58px + env(safe-area-inset-top, 0px)); font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .dialog, .task, #coinChip.bump, .tool .ping, .ans input.badin { animation: none; }
}
