:root {
  --bg: #17121f;
  --bg2: #221a30;
  --card: #2b2140;
  --line: #4a3b6b;
  --ink: #0b0710;
  --text: #f1ebff;
  --muted: #a99cc8;
  --gold: #ffcc4d;
  --gold-dark: #b8862b;
  --xp: #5ee08f;
  --xp-dark: #2c8a52;
  --accent: #8a5cff;
  --accent-dark: #5a35b8;
  --danger: #ff5a6a;
  --pixel: 'Press Start 2P', monospace;
  --body: 'VT323', monospace;
  /* parchment */
  --paper: #f1deb0;
  --paper-dark: #dcc28a;
  --brown: #3b2414;
  --wood: #6b4424;
  /* pixel-rounded outline: corners cut in two 4px steps */
  --pill: polygon(0 8px, 4px 8px, 4px 4px, 8px 4px, 8px 0, calc(100% - 8px) 0, calc(100% - 8px) 4px, calc(100% - 4px) 4px, calc(100% - 4px) 8px, 100% 8px,
    100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) calc(100% - 4px), calc(100% - 8px) calc(100% - 4px), calc(100% - 8px) 100%,
    8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px));
  /* a pixel "circle" */
  --round: polygon(30% 0, 70% 0, 70% 10%, 90% 10%, 90% 30%, 100% 30%, 100% 70%, 90% 70%, 90% 90%, 70% 90%, 70% 100%, 30% 100%, 30% 90%, 10% 90%, 10% 70%, 0 70%, 0 30%, 10% 30%, 10% 10%, 30% 10%);
  --outline: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 2px 2px 0 var(--ink);
}

* { box-sizing: border-box; border-radius: 0 !important; }
[hidden] { display: none !important; }
html { image-rendering: pixelated; }
body {
  margin: 0; color: var(--text); font: 22px/1.15 var(--body); min-height: 100vh;
  background: radial-gradient(ellipse at 50% 30%, #2a2140 0, var(--bg) 70%) fixed, var(--bg);
}
a { color: var(--gold); }
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
button { font-family: inherit; }

/* ---------- Layout ---------- */
.game { max-width: 1000px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }

/* ---------- HUD: floating, no frame ---------- */
.hud { display: flex; align-items: center; gap: 16px; padding: 0 4px; }
.portrait {
  flex: none; width: 72px; height: 72px; padding: 0; border: none; cursor: pointer; display: grid; place-items: center;
  background: radial-gradient(circle, #ffcc4d55 0 45%, transparent 46%), radial-gradient(circle, #3a2f63 0 62%, transparent 63%);
}
.portrait canvas { width: 60px; height: 66px; display: block; margin-top: -6px; }
.portrait:hover { filter: brightness(1.2); }
.hud-main { flex: 1; min-width: 0; display: grid; gap: 8px; }
.hud-name { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hud-bars { display: flex; align-items: center; gap: 10px; }
.hud-stats { display: flex; align-items: center; gap: 14px; }
.stat { display: inline-flex; align-items: center; gap: 6px; font: 12px var(--pixel); text-shadow: var(--outline); }
.stat img { width: 24px; height: 24px; }
.icon-btn { border: none; background: transparent; color: inherit; cursor: pointer; padding: 4px; line-height: 0; font: 14px var(--pixel); }
.icon-btn img { width: 24px; height: 24px; }
.install-btn { font: 7px var(--pixel); color: var(--ink); background: var(--gold); padding: 6px 8px 5px; clip-path: var(--round); line-height: 1; }
.install-btn[hidden] { display: none; }

.hero-name { font: 14px var(--pixel); cursor: pointer; text-shadow: var(--outline); }
.hero-name:hover { color: var(--gold); }
.hero-title { color: var(--gold); font-size: 21px; }
.job-tag { font: 8px var(--pixel); color: var(--ink); background: var(--xp); padding: 5px 8px; clip-path: var(--pill); }
.level-badge { font: 9px var(--pixel); background: var(--accent); padding: 8px 10px; white-space: nowrap; clip-path: var(--pill); }
.xpbar { flex: 1; height: 14px; background: var(--ink); clip-path: var(--pill); padding: 3px; }
.xpfill {
  height: 100%; width: 0; transition: width .6s steps(10);
  background: linear-gradient(#ffffff60 0 3px, transparent 3px), var(--xp);
}
.xp-text { color: var(--muted); font-size: 18px; white-space: nowrap; }
.portrait.bump canvas { animation: bump .4s steps(4); }
@keyframes bump { 25% { transform: translateY(-8px); } 50% { transform: translateY(-4px); } 75% { transform: translateY(-8px); } }
.gold-stat b { color: var(--gold); }
.pop { animation: pop-num .5s steps(3); display: inline-block; }
@keyframes pop-num { 40% { transform: scale(1.5); color: #fff3c4; } }

.day-line { margin: 0 4px; color: var(--muted); font-size: 19px; }
.day-line #todayTitle { text-transform: capitalize; }
.day-line #dayXp { color: var(--xp); }
.hp-line { margin: 0 4px; text-align: center; color: #ff9aa8; font-size: 19px; }
.house-hint { text-align: center; color: var(--muted); margin: 0; }

/* =================================================================
   The world: one pixel-art scene
   ================================================================= */
.world { position: relative; width: 100%; --tile: 22px; margin-top: 4px; }
.world-bg {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  /* edges dissolve into the night instead of ending on a hard rectangle */
  -webkit-mask: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent), linear-gradient(transparent, #000 4%, #000 96%, transparent);
  -webkit-mask-composite: source-in;
  mask: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent) intersect, linear-gradient(transparent, #000 4%, #000 96%, transparent);
}
/* time of day */
.world::after { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 8; transition: background 2s; }
.world.dawn::after { background: #ff9a6a1c; }
.world.dusk::after { background: #ff6a3a26; }
.world.night::after { background: radial-gradient(ellipse at var(--hx, 50%) var(--hy, 50%), transparent 0, #0a1040 70%); opacity: .55; }

/* rooms: floors inside the walls drawn on the canvas */
.room {
  position: absolute; padding: 0; border: none; cursor: pointer; overflow: hidden; z-index: 1;
  transition: filter .3s; box-shadow: inset 0 4px 0 #00000040;
}
.room:hover { filter: brightness(1.15); }
.room:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; }
.r-cuisine { background: repeating-conic-gradient(#d9d0bc 0 25%, #b3a88f 0 50%) 0 0 / 20px 20px; }
.r-sdb { background: repeating-conic-gradient(#9fd2e2 0 25%, #82bccf 0 50%) 0 0 / 14px 14px; }
.r-chambre { background: repeating-linear-gradient(90deg, #8a5a3a 0 26px, #6e4428 26px 30px), #8a5a3a; }
.r-salon { background: radial-gradient(ellipse at 50% 55%, #b04a5a 0 34%, transparent 35%), repeating-linear-gradient(90deg, #9a6a44 0 26px, #7e5232 26px 30px); }
.r-buanderie { background: repeating-conic-gradient(#8f8f9c 0 25%, #85858f 0 50%) 0 0 / 6px 6px; }
.r-entree { background: repeating-linear-gradient(0deg, #9a7a50 0 6px, #87683f 6px 12px); }
/* the garden is an oval drawn on the canvas: only its hit area is here */
.r-jardin { background: transparent; box-shadow: none; clip-path: ellipse(50% 50%); overflow: visible; }
.r-jardin:hover { background: #ffffff18; filter: none; }

.room::after { content: ''; position: absolute; inset: 0; pointer-events: none; transition: background .5s; }
.room.infested::after { background: #1a102866; }
.room.calm::after { background: #1a102840; }
.room.cleared::after { background: radial-gradient(ellipse, #fff3c430 0, transparent 70%); }
.r-jardin.infested::after, .r-jardin.calm::after { background: transparent; }

.room-name {
  position: absolute; top: 4px; left: 0; right: 0; z-index: 3; text-align: center; white-space: nowrap;
  font: 8px/1.6 var(--pixel); color: #fff; text-shadow: var(--outline);
}
.r-jardin .room-name { top: 12%; }
.room-badge {
  display: inline-block; min-width: 18px; padding: 3px 4px 2px; margin-left: 2px; font-style: normal; text-shadow: none;
  background: #ff4d5e; color: #fff; clip-path: var(--round); text-align: center;
}
.room-badge.ok { background: var(--gold); color: var(--ink); }
.decor { position: absolute; width: calc(var(--tile) * 1.6); height: calc(var(--tile) * 1.6); z-index: 1; }
.decor.d0 { left: 6%; bottom: 8%; }
.decor.d1 { right: 6%; top: 28%; }
.minion {
  position: absolute; width: calc(var(--tile) * 1.5); height: calc(var(--tile) * 1.5); z-index: 2; translate: -50% -50%;
  animation: hop .9s steps(2) infinite; transform-origin: bottom center;
  filter: drop-shadow(0 3px 0 #00000050);
}
@keyframes hop { 50% { transform: translateY(-5px) scale(1.05, .95); } }
.sparkle { position: absolute; width: calc(var(--tile) * 0.9); height: calc(var(--tile) * 0.9); z-index: 2; animation: twinkle 1.4s steps(2) infinite; }
@keyframes twinkle { 50% { opacity: .2; transform: scale(.7); } }
/* dirt of neglected rooms (sprites from world.js) */
.dirt { position: absolute; z-index: 1; pointer-events: none; translate: -50% -50%; filter: drop-shadow(0 2px 0 #00000040); }
.dirt.dust { width: calc(var(--tile) * 1.2); animation: dust-wobble 1.8s steps(2) infinite; }
.dirt.stain { width: calc(var(--tile) * 1.7); filter: none; opacity: .9; }
.dirt.weed { width: calc(var(--tile) * 1.1); animation: sway 2.2s steps(2) infinite; transform-origin: bottom center; }
.dirt.mush { width: calc(var(--tile) * 0.9); }
.dirt.web { width: calc(var(--tile) * 2.2); translate: 0 0; filter: none; opacity: .85; }
.dirt.web.flip { translate: -100% 0; scale: -1 1; }
@keyframes dust-wobble { 50% { transform: translateX(1px) scale(1.06, .94); } }
@keyframes sway { 50% { transform: rotate(-6deg); } }
.room.dirty-2:not(:hover) { filter: saturate(.8) brightness(.95); }
.room.dirty-3:not(:hover) { filter: saturate(.6) brightness(.88) sepia(.15); }
.r-jardin.dirty-2:not(:hover), .r-jardin.dirty-3:not(:hover) { filter: none; }
.room.flash { animation: room-flash .8s steps(4); }
@keyframes room-flash { 0%, 50% { filter: brightness(2); } }

/* the walking hero */
.map-hero {
  position: absolute; z-index: 6; width: calc(var(--tile) * 2); height: calc(var(--tile) * 2.2); pointer-events: none;
  transition: left .8s steps(8), top .8s steps(8); filter: drop-shadow(0 3px 0 #00000060);
}
.map-hero.left { transform: scaleX(-1); }
.map-hero.walking { animation: walk .2s steps(2) infinite; }
.map-hero.left.walking { animation: walk-left .2s steps(2) infinite; }
@keyframes walk { 50% { transform: translateY(-3px); } }
@keyframes walk-left { 0%, 100% { transform: scaleX(-1); } 50% { transform: scaleX(-1) translateY(-3px); } }

/* the companion trots a little behind the hero */
.map-pet {
  position: absolute; z-index: 6; width: calc(var(--tile) * 1.4); height: calc(var(--tile) * 1.3); pointer-events: none;
  transition: left .8s steps(8) .25s, top .8s steps(8) .25s; filter: drop-shadow(0 2px 0 #00000050);
}
.map-pet.left { transform: scaleX(-1); }
.map-pet.fly { animation: hover 1.2s steps(2) infinite; }
.map-pet.fly.left { animation: hover-left 1.2s steps(2) infinite; }
@keyframes hover { 50% { translate: 0 -4px; } }
@keyframes hover-left { 0%, 100% { transform: scaleX(-1); } 50% { transform: scaleX(-1); translate: 0 -4px; } }

/* ---------- The boss stands in the scene ---------- */
.boss {
  position: absolute; z-index: 5; padding: 0; border: none; background: none; cursor: pointer; color: inherit;
  display: grid; justify-items: center; align-content: end;
}
.boss canvas {
  width: 100%; height: auto; aspect-ratio: 1; transform-origin: bottom center; animation: squish 1.1s steps(2) infinite;
  filter: drop-shadow(0 4px 0 #00000060);
}
@keyframes squish { 50% { transform: scale(1.1, .9); } }
.boss-tag { position: absolute; bottom: 100%; left: 50%; translate: -50% 0; display: grid; justify-items: center; gap: 4px; width: max-content; }
.monster-name { font: 7px/1.4 var(--pixel); color: #ffb0bc; text-shadow: var(--outline); white-space: nowrap; }
.hpbar { display: block; width: calc(var(--tile) * 3.4); height: 10px; background: var(--ink); clip-path: var(--pill); padding: 2px 3px; }
.hpfill { display: block; height: 100%; transition: width .5s steps(8); background: linear-gradient(#ffffff50 0 2px, transparent 2px), #ff4d5e; }
.boss:hover canvas { filter: drop-shadow(0 4px 0 #00000060) brightness(1.2); }
.boss.hit canvas { animation: shake .4s steps(4); }
@keyframes shake { 25% { transform: translateX(-8px); filter: brightness(3); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); filter: brightness(3); } }
.boss.defeated canvas { animation: none; transform: scale(1, .7); filter: grayscale(.7); }
.boss.defeated .monster-name { color: var(--gold); text-decoration: line-through; }
.boss.defeated .hpbar { display: none; }
.boss.defeat canvas { animation: defeat .8s steps(6); }
@keyframes defeat { 0% { transform: scale(1.2, .8); filter: brightness(4); } 100% { transform: scale(1, .7); } }

/* ---------- Village buildings: pixel art drawn in world.js ---------- */
.building {
  position: absolute; z-index: 4; padding: 0; border: none; background: none; cursor: pointer; color: var(--text);
  filter: drop-shadow(0 3px 0 #00000040);
}
.building:hover { filter: drop-shadow(0 3px 0 #00000040) brightness(1.15); }
.building:hover .b-art { translate: -50% -3px; } /* keep the -50% centring while lifting */
.building:active .b-art { translate: -50% 1px; }
.b-art { position: absolute; left: 50%; bottom: 0; translate: -50% 0; width: calc(var(--tile) * var(--art-tiles, 6)); height: auto; aspect-ratio: 1; transition: translate .15s steps(2); }
.building b {
  position: absolute; top: 100%; left: 50%; translate: -50% 4px; width: max-content; max-width: 160%;
  font: 7px/1.5 var(--pixel); text-align: center; text-shadow: var(--outline);
}
.quest-mark {
  position: absolute; z-index: 1; left: 50%; bottom: calc(var(--tile) * var(--art-tiles, 6)); translate: -50% 0;
  font: calc(var(--tile) * .9) var(--pixel); color: var(--gold); text-shadow: var(--outline);
  animation: mark-bob 1s steps(2) infinite;
}
@keyframes mark-bob { 50% { transform: translateY(-4px); } }

/* ---------- Speech bubble ---------- */
.bubble { position: absolute; z-index: 20; animation: bubble-in .25s steps(3); }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px); } }
.bubble.below { animation-name: bubble-in-down; }
@keyframes bubble-in-down { from { opacity: 0; transform: translateY(-10px); } }
.bubble-body {
  position: relative; color: var(--brown); padding: 14px 16px 16px; max-height: 58vh; overflow-y: auto;
  background: var(--paper); clip-path: var(--pill);
  box-shadow: inset 0 0 0 4px var(--brown), inset 0 -8px 0 4px var(--paper-dark);
}
.bubble-tail { position: absolute; left: var(--tail, 50%); top: 100%; translate: -50% -4px; width: 22px; height: 14px; background: var(--brown); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.bubble-tail::after { content: ''; position: absolute; left: 4px; top: 0; width: 14px; height: 8px; background: var(--paper-dark); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.bubble.below .bubble-tail { top: auto; bottom: 100%; translate: -50% 4px; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.bubble.below .bubble-tail::after { top: auto; bottom: 0; background: var(--paper); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.bubble-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font: 10px var(--pixel); color: #9a2f1c; }
.bubble-text { font-size: 21px; min-height: 24px; margin: 8px 0 10px; }
.bubble-text::after { content: '▼'; font-size: 12px; margin-left: 6px; animation: blink-cursor .8s steps(2) infinite; color: #9a2f1c; }
@keyframes blink-cursor { 50% { opacity: 0; } }

/* quest rows: a checklist written on the bubble */
.quest-list, .board-list, .log, .shop-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.quest {
  display: flex; align-items: center; gap: 10px; padding: 7px 4px; cursor: pointer; user-select: none;
  border-bottom: 2px dashed #c9a878;
}
.quest:last-child { border-bottom: none; }
.quest:hover { background: #00000010; }
.quest:active { translate: 0 2px; }
.quest .check { width: 24px; height: 24px; flex: none; background: var(--brown); clip-path: var(--round); position: relative; }
.quest .check::after { content: ''; position: absolute; inset: 4px; background: #fff4d6; clip-path: var(--round); }
.picon { width: 28px; height: 28px; flex: none; }
.quest .qname { flex: 1; min-width: 0; font-size: 22px; }
.qreward { display: grid; justify-items: end; gap: 4px; }
.quest .qxp { font: 9px var(--pixel); color: #2f7a3e; white-space: nowrap; }
.qgold { font: 8px var(--pixel); color: #a8701a; white-space: nowrap; }
.quest.done .check::after {
  background: var(--xp) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath fill='%233b2414' d='M1 3h1v1H1zM2 4h1v1H2zM3 5h1v1H3zM4 4h1v1H4zM5 3h1v1H5zM6 2h1v1H6zM5 2h1v1H5zM4 3h1v1H4zM2 3h1v1H2z'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.quest.done .qname { text-decoration: line-through; text-decoration-thickness: 2px; color: #8a6a48; }
.quest.done .picon { filter: grayscale(.6); }
.quest.later { opacity: .55; cursor: default; }
.quest.later .check { visibility: hidden; }
.quest.later .qreward { font: 7px var(--pixel); color: #8a6a48; }

/* ---------- Buttons & inputs ---------- */
.btn {
  font: 9px var(--pixel); padding: 11px 14px; cursor: pointer; border: none; color: #fff4d6;
  background: var(--wood); clip-path: var(--pill); box-shadow: inset 0 -4px 0 #00000040;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { filter: brightness(1.2); }
.btn:active { translate: 0 2px; box-shadow: none; }
.btn.primary { background: #a8321e; }
.btn.danger { background: #5a1a22; color: #ffb0b8; }
.btn.icon { padding: 8px 10px; }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

input[type=text], input[type=number], select {
  border: none; min-width: 0; padding: 7px 10px; font: 22px var(--body);
  background: #fff4d6; color: var(--brown); box-shadow: inset 0 0 0 3px #b8955e; clip-path: var(--pill);
}
input:focus, select:focus { outline: none; box-shadow: inset 0 0 0 3px #9a2f1c; }
.icon-input { text-align: center; }
.quest-form { display: grid; grid-template-columns: 56px 1fr 84px auto; gap: 10px; align-items: center; }
.custom-form { grid-template-columns: 56px 1fr auto auto; }

.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.wd {
  font: 8px var(--pixel); width: 40px; height: 40px; cursor: pointer; border: none; padding: 0;
  background: #e6cf9c; color: #86643e; clip-path: var(--round);
}
.wd.on { background: #9a2f1c; color: #fff4d6; }

/* ---------- Screens: parchment scroll and open book ---------- */
.screen {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto; padding: 16px 12px 60px;
  background: radial-gradient(ellipse at 50% 20%, #2a2140ee 0, #0b0710f5 70%);
  animation: screen-in .25s steps(3);
}
@keyframes screen-in { from { opacity: 0; transform: translateY(20px); } }
.back {
  position: sticky; top: 0; z-index: 3; display: block; margin: 0 auto 10px; border: none; cursor: pointer;
  font: 9px var(--pixel); color: var(--gold); background: none; text-shadow: var(--outline); padding: 8px;
}
.back:hover { color: #fff3c4; }

.scroll { max-width: 780px; margin: 0 auto; display: grid; justify-items: center; }
.rod {
  width: calc(100% + 24px); height: 22px; position: relative; z-index: 1;
  background: linear-gradient(#a8743e 0 4px, #8a5a2a 4px 14px, #5e3a18 14px);
  clip-path: polygon(0 20%, 3% 20%, 3% 0, 6% 0, 6% 20%, 94% 20%, 94% 0, 97% 0, 97% 20%, 100% 20%, 100% 80%, 97% 80%, 97% 100%, 94% 100%, 94% 80%, 6% 80%, 6% 100%, 3% 100%, 3% 80%, 0 80%);
}
.paper {
  --text: var(--brown); --muted: #86643e; --bg2: #e6cf9c; --line: #b8955e; --ink: var(--brown);
  --gold: #a8701a; --gold-dark: #7a4f10; --xp: #2f8a4e; --xp-dark: #1e6a38; --accent: #6a3cc8; --danger: #b8323e;
  width: 100%; color: var(--text); padding: 26px 28px 30px; margin: -6px 0;
  background:
    radial-gradient(ellipse at 20% 10%, #fff0c840 0, transparent 50%),
    repeating-linear-gradient(0deg, transparent 0 22px, #00000008 22px 24px),
    var(--paper);
  box-shadow: inset 10px 0 0 #00000010, inset -10px 0 0 #00000010;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px;
}
.paper h1 { margin: 0 0 6px; text-align: center; font: 16px/1.4 var(--pixel); color: #9a2f1c; }
.card { padding: 6px 0 4px; }
.card + .card::before, .paper h1 + .card::before {
  content: '~ ◆ ~'; display: block; text-align: center; color: #b8955e; font-size: 22px; margin: 0 0 12px;
}
.card h2 { font: 11px/1.6 var(--pixel); margin: 0 0 12px; color: #9a2f1c; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.day-xp { font: 9px var(--pixel); color: var(--xp); }
.hint { color: var(--muted); }
.hint.small { font-size: 19px; margin: 0 0 12px; }

.book {
  max-width: 1040px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); position: relative;
  padding: 10px; background: #5a2a1a; clip-path: var(--pill); box-shadow: inset 0 -8px 0 #3a1a10;
}
.book .page { margin: 0; align-content: start; }
.book .page:first-child { box-shadow: inset -14px 0 0 -4px #00000020; }
.book .page:last-child { box-shadow: inset 14px 0 0 -4px #00000020; }

/* catalog */
.days-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cat-title { font: 9px var(--pixel); color: var(--muted); margin: 16px 0 8px; }
.chore-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.chore-pick {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; cursor: pointer; border: none; text-align: left;
  background: #e6cf9c; color: var(--text); font: 19px/1 var(--body); clip-path: var(--pill);
}
.chore-pick:hover:not(:disabled) { background: #f8e6bc; box-shadow: inset 0 0 0 3px #9a2f1c; }
.chore-pick:active:not(:disabled) { translate: 0 2px; }
.chore-pick .picon { width: 24px; height: 24px; }
.chore-pick span { flex: 1; min-width: 0; }
.chore-pick b { font: 8px var(--pixel); color: var(--gold); white-space: nowrap; }
.chore-pick.owned { cursor: default; opacity: .5; }
.chore-pick.owned b { color: var(--xp); font-size: 12px; }

/* ledger rows (board, shop, log) */
.board-item, .shop-item, .log li { border-bottom: 2px dashed #c9a878; }
.board-item { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto auto; gap: 6px 12px; align-items: center; padding: 10px 2px; }
.board-item .qname { font-size: 22px; }
.board-item .qxp { font: 9px var(--pixel); color: var(--gold); white-space: nowrap; }
.board-item .weekdays { grid-column: 1 / -1; }
.board-item .wd { width: 34px; height: 34px; font-size: 7px; }
.tag { font: 7px var(--pixel); color: var(--accent); vertical-align: middle; }

.purse { display: inline-flex; align-items: center; gap: 8px; font: 12px var(--pixel); color: var(--gold); }
.purse img { width: 28px; height: 28px; }
.shop-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; }
.shop-item .qname { flex: 1; font-size: 23px; min-width: 0; }
.shop-item .price {
  font: 9px var(--pixel); color: var(--brown); white-space: nowrap; background: #ffcc4d; padding: 6px 10px 6px 14px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
}
.shop-item .buy { min-width: 108px; }
.shop-item .buy:disabled { font-size: 8px; }
.shop-item.locked .picon { filter: grayscale(1) brightness(.8); }
.shop-item .del { opacity: .7; }
.pet-item .pet-icon { width: 56px; height: 52px; flex: none; }
.town-item .town-icon { width: 56px; height: 56px; flex: none; }
.town-item .qname em { font: 7px var(--pixel); color: #9a2f1c; font-style: normal; white-space: nowrap; }
.town-item .qname small { display: block; font-size: 17px; color: var(--muted); line-height: 1.1; margin-top: 2px; }
.town-item.locked .town-icon { filter: saturate(.55) brightness(.9); }
.town-item.built .price { background: #5ec46a; }
/* lots of the town on the map: construction sites look a little faded */
.plot.lot .b-art { opacity: .9; }
.plot b { font-size: 6px; }
/* actions offered by a building, in the speech bubble */
.quest.town-act { cursor: default; }
.quest.town-act:hover { background: none; }
.quest.town-act:active { translate: none; }
.quest.town-act .qname { font-size: 20px; }
.quest.town-act .qname small { font-size: 16px; color: #8a6a48; }
.quest.town-act .btn { flex: none; padding: 8px 10px; font-size: 8px; }
/* household */
.house-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-top: 10px; }
.house-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 24px; }
.house-status { font: 7px var(--pixel); color: #8a6a48; white-space: nowrap; }
.house-status.ok { color: #2f7a3e; }
.house-status.offline { color: #9a2f1c; }
.house-invite { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.house-code { font: 12px var(--pixel); letter-spacing: 2px; color: #9a2f1c; background: #fff4d6; border: 2px solid var(--brown); padding: 6px 8px; cursor: pointer; }
.member { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 2px dashed #c9a878; }
.member:last-child { border-bottom: none; }
.member canvas { width: 40px; height: 44px; }
.member .qname { font-size: 22px; }
.member .qname small:not(.tag) { display: block; font-size: 17px; color: #8a6a48; }
.member .qxp { font: 7px var(--pixel); color: #2f7a3e; text-align: right; }
.town-item .qname small.funds { color: #a8701a; }
.qby { font: 7px var(--pixel); font-style: normal; color: #fff; background: #3a6ea8; padding: 2px 4px; white-space: nowrap; vertical-align: middle; }
.quest.other { cursor: default; }
/* the other heroes of the household, on the map */
.map-mate {
  position: absolute; z-index: 5; width: calc(var(--tile) * 2); pointer-events: none; display: grid; justify-items: center;
  transition: left .8s steps(8), top .8s steps(8);
}
.map-mate canvas { width: 100%; height: calc(var(--tile) * 2.2); filter: drop-shadow(0 3px 0 #00000060) saturate(.85); }
.map-mate b { margin-top: -2px; font: 6px var(--pixel); color: #fff; background: #3a6ea8cc; padding: 2px 3px; white-space: nowrap; }
.qtag { font: 7px var(--pixel); font-style: normal; color: #fff; background: #a8321e; padding: 2px 4px; white-space: nowrap; vertical-align: middle; }
.pet-item .qname small { display: block; font-size: 17px; color: var(--muted); line-height: 1.1; margin-top: 2px; }
.pet-item.locked .pet-icon { filter: saturate(.55) brightness(.9); }
.pet-item.active .pet-icon { background: radial-gradient(ellipse 46% 12% at 50% 94%, #ffcc4d 0 98%, transparent 100%); }

/* achievements: medals in a row */
.achievements { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 12px; }
.ach { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.ach .picon { padding: 4px; width: 36px; height: 36px; background: #ffcc4d; clip-path: var(--round); }
.ach > div { flex: 1; min-width: 0; display: grid; }
.ach b { font: 8px/1.6 var(--pixel); color: var(--text); }
.ach span { font-size: 17px; color: var(--muted); line-height: 1; }
.ach em { font: 7px var(--pixel); color: var(--gold); font-style: normal; white-space: nowrap; }
.ach.locked { opacity: .5; }
.ach.locked .picon { background: #d4bc88; filter: grayscale(1); }

/* collection: objects resting on little shadows */
.collection { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 12px 6px; }
.item { position: relative; display: grid; justify-items: center; gap: 4px; text-align: center; }
.item .picon {
  width: 44px; height: 44px; padding-bottom: 4px;
  background: radial-gradient(ellipse 50% 14% at 50% 92%, var(--rar, #00000030) 0 98%, transparent 100%);
  filter: drop-shadow(0 0 3px var(--rar, transparent));
}
.item span { font-size: 16px; line-height: 1; }
.item i { position: absolute; top: 0; right: 10px; font: 8px var(--pixel); color: var(--gold); font-style: normal; }
.item.unknown .picon { filter: brightness(0) opacity(.3); }
.item.unknown span { color: var(--muted); }

/* equipment: the hero and four slots */
.gear { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; }
#gearHero { width: 120px; height: 132px; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot {
  display: grid; justify-items: center; align-content: start; gap: 2px; min-height: 84px; padding: 6px 4px;
  background: #00000014; clip-path: var(--round); border: none; color: inherit; font: inherit; text-align: center;
}
.slot em { font: 7px var(--pixel); color: #9a2f1c; font-style: normal; }
.slot span { color: var(--muted); font-size: 16px; margin-top: 12px; }
.slot.full { cursor: pointer; background: color-mix(in srgb, var(--rar) 22%, transparent); }
.slot.full:hover { filter: brightness(1.1); }
.slot .picon { width: 32px; height: 32px; }
.slot b { font-size: 16px; line-height: 1; font-weight: normal; }
.slot small, .item small { font: 6px/1.5 var(--pixel); color: #2f7a3e; }
.item.equip { background: none; border: none; color: inherit; font: inherit; padding: 0; cursor: pointer; }
.item.equip:hover .picon { translate: 0 -3px; }
.item.worn .picon { background: radial-gradient(ellipse 50% 14% at 50% 92%, var(--rar) 0 98%, transparent 100%), radial-gradient(circle, #ffcc4d55 0 55%, transparent 60%); }
.item.worn span::before { content: '✓ '; color: #2f7a3e; }
.item.unknown small { color: var(--muted); }
@media (max-width: 420px) { .gear { grid-template-columns: 1fr; justify-items: center; } }

/* calendar: ink dots */
.heatmap { display: grid; grid-template-columns: repeat(7, 36px); gap: 6px; }
.heat { height: 36px; display: grid; place-items: center; font: 8px var(--pixel); color: var(--muted); background: #e6cf9c; clip-path: var(--round); }
.heat.l1 { background: #a8d8a0; color: var(--brown); }
.heat.l2 { background: #5aaa62; color: #fff; }
.heat.l3 { background: #2f8a4e; color: #fff; }
.heat.perfect-sq { background: #ffcc4d; color: var(--brown); }
.heat.today { box-shadow: inset 0 0 0 3px #9a2f1c; }
.heat-head { font: 8px var(--pixel); color: var(--muted); text-align: center; padding-bottom: 4px; }
.legend { display: flex; gap: 6px; align-items: center; margin-top: 12px; font-size: 18px; color: var(--muted); }
.legend .sq { width: 14px; height: 14px; display: inline-block; background: #e6cf9c; clip-path: var(--round); margin-left: 10px; }
.legend .sq.l2 { background: #5aaa62; }
.legend .sq.perfect-sq { background: #ffcc4d; }

/* ranks: heroes on pedestals */
.ranks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.rank { text-align: center; display: grid; justify-items: center; gap: 2px; }
.rank canvas { width: 80px; height: 88px; background: radial-gradient(ellipse 45% 10% at 50% 94%, #00000030 0 98%, transparent 100%); }
.rank b { font: 7px var(--pixel); color: var(--gold); }
.rank span { font-size: 17px; line-height: 1; }
.rank.locked { opacity: .55; }

.log li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 2px; font-size: 20px; }
.log .what { display: flex; align-items: center; gap: 10px; min-width: 0; }
.log .picon { width: 24px; height: 24px; }
.log .meta { display: grid; justify-items: end; gap: 2px; }
.log .when { color: var(--muted); }
.log .gain { color: var(--xp); font: 8px var(--pixel); white-space: nowrap; }
.log .gain.spend { color: var(--gold); }

/* ---------- Toasts: little floating banners ---------- */
.toast-zone { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: grid; gap: 14px; z-index: 95; pointer-events: none; justify-items: center; }
.toast {
  font: 10px var(--pixel); padding: 12px 18px; background: var(--ink); color: var(--xp); clip-path: var(--pill);
  box-shadow: inset 0 0 0 3px currentColor; animation: rise 1.8s steps(12) forwards; text-align: center; white-space: nowrap;
  display: flex; align-items: center; gap: 10px;
}
.toast.minus { color: var(--danger); }
.toast.gold { color: var(--gold); }
.toast.achievement { color: var(--gold); background: #2a2010; text-align: left; line-height: 1.6; font-size: 9px; }
.toast.achievement span { color: var(--text); }
.toast.achievement img { width: 32px; height: 32px; }
.toast.achievement small { display: block; color: var(--gold); font-size: 8px; }
.toast img { vertical-align: middle; width: 22px; height: 22px; }
@keyframes rise { 0% { opacity: 0; transform: translateY(12px); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-16px); } }

/* ---------- Popups: content floats in a halo, no box ---------- */
.levelup { position: fixed; inset: 0; background: #000d; display: grid; place-items: center; z-index: 100; padding: 16px; }
.levelup-box {
  text-align: center; padding: 28px 30px; max-width: 100%;
  background: radial-gradient(ellipse at 50% 45%, #4a3a7a 0, #2a2050aa 40%, transparent 70%);
  animation: pop .4s steps(4);
}
@keyframes pop { from { transform: scale(.3); } }
.levelup-title { font: 20px/1.4 var(--pixel); color: var(--gold); text-shadow: 4px 4px 0 var(--ink); animation: shine .6s steps(2) infinite; }
@keyframes shine { 50% { color: #fff3c4; } }
.levelup-avatar { width: 160px; height: 176px; margin: 18px auto 10px; display: block; }
.levelup-level { font: 14px var(--pixel); }
.levelup-sub { color: var(--muted); margin: 12px 0 20px; font-size: 22px; }
.levelup .btn { margin: 4px; }

.job-box { max-width: 760px; width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; }
.job-box .levelup-title { font-size: 16px; }
.gender-pick { display: flex; justify-content: center; gap: 8px; margin: -8px 0 16px; }
.jobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin: 0 0 20px; }
.job {
  background: none; color: var(--text); padding: 6px; cursor: pointer; border: none;
  display: grid; justify-items: center; gap: 6px; font: 18px/1.1 var(--body);
}
.job canvas {
  width: 120px; height: 132px;
  background: radial-gradient(ellipse 48% 10% at 50% 94%, #8a5cff66 0 98%, transparent 100%);
}
.job:hover canvas { background: radial-gradient(ellipse 48% 10% at 50% 94%, #ffcc4d 0 98%, transparent 100%); }
.job:hover { filter: brightness(1.15); }
.job.current canvas { background: radial-gradient(ellipse 48% 10% at 50% 94%, var(--xp) 0 98%, transparent 100%); }
.job b { font: 11px var(--pixel); color: var(--gold); margin-top: 4px; }
.job .job-desc { color: var(--muted); font-size: 17px; }
.job .job-final { font: 7px/1.6 var(--pixel); color: #b49cff; }

/* ---------- Chest ---------- */
.chest-box { min-width: 300px; }
.chest-stage { width: 128px; height: 128px; margin: 20px auto 12px; display: grid; place-items: center; position: relative; }
.chest-stage img { width: 96px; height: 96px; position: relative; z-index: 1; }
.chest-stage.closed img { animation: wiggle 1.2s steps(2) infinite; }
@keyframes wiggle { 0%, 60% { transform: none; } 70% { transform: rotate(-8deg); } 80% { transform: rotate(8deg); } 90% { transform: rotate(-4deg); } }
.chest-stage.opening img { animation: rattle .65s steps(8) forwards; }
@keyframes rattle { 25% { transform: translateX(-6px) rotate(-10deg); } 50% { transform: translateX(6px) rotate(10deg) scale(1.1); } 75% { transform: translateY(-10px) scale(1.25); filter: brightness(3); } 100% { transform: scale(.2); opacity: 0; } }
.chest-stage.open img { animation: reveal .5s steps(5); }
@keyframes reveal { from { transform: scale(.2); } 60% { transform: scale(1.3); } }
.chest-stage.open::before {
  content: ''; position: absolute; inset: -12px;
  background: repeating-conic-gradient(var(--rar) 0 15deg, transparent 15deg 30deg);
  opacity: .35; animation: spin 4s steps(24) infinite;
  -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%); mask: radial-gradient(circle, #000 30%, transparent 70%);
}
@keyframes spin { to { transform: rotate(360deg); } }
.chest-rarity { font: 10px var(--pixel); min-height: 14px; }
.chest-name { font-size: 26px; margin: 8px 0 4px; }
.chest-gold { font: 10px var(--pixel); color: var(--gold); min-height: 14px; margin-bottom: 18px; }

/* ---------- Effects ---------- */
.particle { position: fixed; z-index: 200; pointer-events: none; }
.float-text {
  position: fixed; z-index: 90; pointer-events: none; white-space: nowrap; /* below popups */
  font: 11px var(--pixel); text-shadow: 2px 2px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
}

/* ---------- Phone ---------- */
@media (max-width: 700px) {
  .book { grid-template-columns: minmax(0, 1fr); }
  .book .page { box-shadow: none !important; }
}
@media (max-width: 600px) {
  body { font-size: 20px; }
  .game { padding: 10px 8px 32px; }
  .hud { flex-wrap: wrap; gap: 8px 12px; }
  .portrait { width: 60px; height: 60px; }
  .hud-main { flex-basis: calc(100% - 84px); }
  .room-name { white-space: normal; font-size: 7px; padding: 0 2px; }
  .hud-stats { width: 100%; justify-content: flex-end; }
  .building b { font-size: 6px; }
  .quest-mark { font-size: 12px; }
  .monster-name { font-size: 6px; }
  .paper { padding: 20px 14px 24px; }
  .quest-form { grid-template-columns: 56px 1fr 74px; }
  .quest-form button[type=submit] { grid-column: 1 / -1; }
  .custom-form { grid-template-columns: 52px 1fr; }
  .custom-form select, .custom-form button[type=submit] { grid-column: 1 / -1; }
  .chore-grid, .achievements { grid-template-columns: minmax(0, 1fr); }
  .wd { width: 34px; height: 34px; font-size: 7px; }
  .heatmap { grid-template-columns: repeat(7, 1fr); }
  .heat { height: auto; aspect-ratio: 1; }
  .shop-item { flex-wrap: wrap; }
  .shop-item .qname { flex-basis: calc(100% - 60px); }
  .shop-item .price { margin-right: auto; }
  .collection { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
