:root {
  --paper-color: #f7f0de;
  --ink: #4a2f1c;
  --purple: #7b5aa6;
  --purple-dark: #5a3270;
  --gold: #e9b23f;
  --green: #6f9e58;
  --edge: rgba(120, 90, 60, 0.45);
  --font: "Patrick Hand", "Comic Sans MS", cursive;
  --title: "Caveat Brush", "Patrick Hand", cursive;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9dfc6;
  font-family: var(--font);
  color: var(--ink);
}
#game { display: block; position: fixed; inset: 0; }
.hidden { display: none !important; }

/* a hand-painted paper card */
.panel {
  background-color: var(--paper-color);
  background-image: var(--paper);
  border: 2px solid var(--edge);
  border-radius: 18px 26px 16px 28px / 26px 16px 28px 18px;
  box-shadow: 0 6px 24px rgba(90, 60, 30, 0.18), inset 0 0 40px rgba(200, 170, 120, 0.25);
}

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(120, 140, 160, 0.25);
  backdrop-filter: blur(2px);
  padding: 16px;
  z-index: 10;
}

h1, h2 { font-family: var(--title); font-weight: normal; margin: 0; color: var(--purple-dark); }
h1 { font-size: 52px; text-align: center; line-height: 1; }
h2 { font-size: 38px; }
h3 { margin: 14px 0 6px; font-size: 20px; font-weight: normal; color: var(--purple-dark); }
h3 small { font-size: 15px; color: #8a6a4a; }
.sub { text-align: center; margin: 4px 0 10px; font-size: 20px; color: #8a6a4a; }

button {
  font-family: var(--font);
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  border: 2px solid var(--edge);
  background: #fffaf0;
  border-radius: 12px 16px 12px 16px / 16px 12px 16px 12px;
  padding: 6px 12px;
  transition: transform 0.1s, box-shadow 0.1s;
}
button:hover:not(:disabled) { transform: translateY(-2px) rotate(-0.5deg); box-shadow: 0 4px 10px rgba(90, 60, 30, 0.15); }
button:disabled { cursor: default; opacity: 0.75; }
button.big {
  display: block; width: 100%;
  margin-top: 14px;
  font-size: 26px;
  font-family: var(--title);
  background: var(--purple);
  color: #fff;
  border-color: var(--purple-dark);
}

/* ---------- creator ---------- */
.creator-panel { width: min(940px, 100%); max-height: 94vh; overflow: auto; padding: 22px 26px; }
.creator-grid { display: grid; grid-template-columns: 280px 1fr; gap: 22px; }
.preview-col { text-align: center; }
#preview {
  width: 260px; height: 300px;
  background: radial-gradient(ellipse at 50% 60%, rgba(180, 210, 160, 0.45), rgba(255, 255, 255, 0) 70%);
  border-radius: 50%;
}
#perk { font-size: 18px; padding: 8px 6px; }
#perk strong { color: var(--purple-dark); }
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choice { display: flex; flex-direction: column; align-items: center; padding: 3px 8px 5px; font-size: 16px; min-width: 84px; }
.choice canvas { width: 62px; height: 72px; }
.swatch.selected { outline: 3px solid var(--purple); outline-offset: 2px; }
.selected:not(.swatch) { border-color: var(--purple) !important; background: #efe4fa !important; box-shadow: 0 0 0 3px rgba(123, 90, 166, 0.25); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; padding: 0; border-radius: 50% 45% 52% 48%; }
.outfits { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.outfit { display: flex; flex-direction: column; align-items: center; padding: 4px 6px 6px; position: relative; }
.outfit canvas { width: 64px; height: 76px; }
.outfit-name { font-size: 16px; line-height: 1.1; text-align: center; }
.outfit .price { font-size: 15px; margin-top: 2px; color: #a0701c; display: flex; align-items: center; gap: 3px; }
.outfit .price.free { color: #4f8a44; }
.outfit.fancy { background: linear-gradient(160deg, #fffaf0, #fbf0d4); }
.outfit.fancy::after { content: "✦ fancy"; position: absolute; top: 3px; right: 6px; font-size: 12px; color: #b58a2a; }
#nameInput {
  font-family: var(--font); font-size: 22px; color: var(--ink);
  width: 100%; padding: 6px 12px;
  border: 2px solid var(--edge); border-radius: 12px;
  background: #fffaf0;
}
#coinSummary { margin-top: 12px; font-size: 18px; }

/* ---------- coins & gems ---------- */
.coin-icon {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2b0 0 18%, #f6d36b 30%, #e9b23f 70%, #c48a2c 100%);
  vertical-align: -4px; margin-right: 5px;
}
.coin-icon.small { width: 15px; height: 15px; vertical-align: -2px; margin-right: 3px; }
.gem-icon { display: inline-block; width: 13px; height: 13px; transform: rotate(45deg); margin: 0 5px 0 4px; border-radius: 2px; box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.5); }
.muted { color: #9a8a76; font-size: 15px; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 14px; left: 14px; padding: 10px 16px; font-size: 20px; min-width: 190px; z-index: 5; }
.hud-name { font-family: var(--title); font-size: 24px; color: var(--purple-dark); }
.hud-row { display: flex; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.hud-broom { font-size: 16px; color: #6b5a48; }
#objective { position: fixed; top: 14px; right: 14px; max-width: 340px; padding: 10px 16px; font-size: 18px; z-index: 5; }
#objective .label { display: inline-block; background: var(--gold); color: #fff; border-radius: 8px; padding: 0 8px; margin-right: 4px; font-size: 15px; }
#controls {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(255, 250, 236, 0.85); border: 1.5px solid var(--edge); border-radius: 14px;
  padding: 4px 14px; font-size: 16px; white-space: nowrap; z-index: 5;
}
#controls b { background: var(--purple); color: #fff; padding: 0 6px; border-radius: 5px; font-weight: normal; }
#toast {
  position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%);
  max-width: min(620px, calc(100% - 32px)); padding: 12px 20px; font-size: 20px; text-align: center; z-index: 6;
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) translateY(10px) scale(0.96); } }

/* ---------- shop ---------- */
.shop-panel { width: min(680px, 100%); max-height: 94vh; overflow: auto; padding: 22px 26px; position: relative; }
.close { position: absolute; top: 12px; right: 14px; font-size: 18px; padding: 2px 10px; }
.talk { font-size: 19px; margin: 6px 0 10px; }
.talk .who { color: var(--purple-dark); }
.coins-line { font-size: 20px; margin-bottom: 10px; display: flex; align-items: center; gap: 2px; }
.store-row {
  display: grid; grid-template-columns: 56px 1fr 140px; align-items: center; gap: 12px;
  padding: 8px 12px; margin-bottom: 8px;
  border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px 18px 14px 18px;
  background: rgba(255, 252, 244, 0.7);
}
.store-row.equipped { border-color: var(--purple); background: #f3ebfb; }
.store-row canvas { justify-self: center; }
.store-row button { font-size: 17px; line-height: 1.1; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.store-row button.cant { background: #f1e8d8; color: #9a8268; }
.store-row button small { width: 100%; font-size: 13px; }
.row-name { font-family: var(--title); font-size: 22px; color: var(--purple-dark); }
.energy-tag { font-family: var(--font); font-size: 14px; background: #dff0d4; color: #3f7a3a; border-radius: 6px; padding: 0 6px; vertical-align: 3px; }

/* conversations */
#dialog { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); width: min(640px, calc(100% - 32px)); z-index: 12; }
.dialog-panel { padding: 16px 22px; }
.dialog-name { font-family: var(--title); font-size: 26px; color: var(--purple-dark); }
.dialog-text { font-size: 20px; margin: 6px 0 12px; line-height: 1.35; }
.dialog-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.dialog-buttons button:not(:last-child) { background: var(--purple); color: #fff; border-color: var(--purple-dark); }

/* energy + quickbar */
.energy-row { gap: 6px; margin-top: 4px; }
.energy-label { font-size: 15px; color: #6b5a48; }
.energy-bar { flex: 1; min-width: 80px; height: 10px; border-radius: 6px; background: rgba(120, 90, 60, 0.15); overflow: hidden; }
#foodFill, #restFill { height: 100%; width: 100%; background: #6fae5a; border-radius: 6px; transition: width 0.3s, background 0.3s; }
#energyNum { font-size: 15px; min-width: 24px; text-align: right; }
#quickbar { position: fixed; right: 14px; bottom: 12px; display: flex; gap: 6px; z-index: 5; }
.slot {
  position: relative; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 250, 236, 0.9); border: 1.5px solid var(--edge); border-radius: 12px;
}
.slot span { position: absolute; right: 3px; bottom: 0; font-size: 15px; font-weight: bold; color: var(--ink); }
.map-panel { width: auto; max-width: calc(100% - 32px); text-align: center; }
#mapCanvas { border-radius: 12px; border: 2px solid var(--edge); max-width: 100%; }
.broom-card {
  display: grid; grid-template-columns: 120px 1fr 130px; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px 18px 14px 18px;
  background: rgba(255, 252, 244, 0.7);
}
.broom-card.equipped { border-color: var(--purple); background: #f3ebfb; }
.broom-name { font-family: var(--title); font-size: 24px; color: var(--purple-dark); }
.ability { font-size: 16px; color: #6b5a48; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.bar { flex: 1; height: 9px; border-radius: 6px; background: rgba(120, 90, 60, 0.15); overflow: hidden; }
.bar div { height: 100%; background: linear-gradient(90deg, #8fc1d9, var(--purple)); border-radius: 6px; }
.broom-card button { font-size: 18px; line-height: 1.1; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.broom-card button.cant { background: #f1e8d8; color: #9a8268; }
.broom-card button small { width: 100%; font-size: 13px; }
.hint { text-align: center; color: #8a6a4a; margin: 10px 0 0; }
.loading-panel { padding: 22px 34px; font-family: var(--title); font-size: 34px; color: var(--purple-dark); }

@media (max-width: 760px) {
  .creator-grid { grid-template-columns: 1fr; }
  .outfits { grid-template-columns: repeat(2, 1fr); }
  .broom-card { grid-template-columns: 1fr; text-align: center; }
  #controls { white-space: normal; width: calc(100% - 32px); text-align: center; }
  #objective { top: auto; bottom: 100px; right: 16px; left: 16px; max-width: none; }
}

/* ---------- continue, effects, fade ---------- */
.continue-box { text-align: center; margin: 10px auto 4px; padding: 12px; max-width: 520px; border: 2px dashed var(--edge); border-radius: 16px; font-size: 20px; }
.continue-box .big { margin: 8px 0 0; }
#effects { position: fixed; top: 236px; left: 14px; display: flex; flex-direction: column; gap: 4px; z-index: 5; }
.effect { background: rgba(255, 250, 236, 0.92); border: 1.5px solid var(--edge); border-radius: 10px; padding: 2px 10px; font-size: 16px; }
#fade { position: fixed; inset: 0; background: #1a1a30; z-index: 20; animation: fadeout 0.9s ease-in forwards; pointer-events: none; }
@keyframes fadeout { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- tailor ---------- */
.tailor-panel { width: min(900px, 100%); }
.tailor-grid { display: grid; grid-template-columns: 240px 1fr; gap: 18px; }
.tailor-preview { text-align: center; }
#tailorPreview { width: 220px; height: 250px; background: radial-gradient(ellipse at 50% 60%, rgba(230, 210, 240, 0.6), rgba(255, 255, 255, 0) 70%); border-radius: 40%; }
#tailorSelected { font-size: 18px; min-height: 48px; }
#tailorAction { font-size: 22px; padding: 6px; }
#tailorAction.cant { background: #c9b8d8; border-color: #a08ab5; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { font-size: 17px; padding: 4px 12px; }
.cloth-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; max-height: 52vh; overflow: auto; padding: 2px; }
.cloth-card { display: flex; flex-direction: column; align-items: center; padding: 4px 4px 6px; position: relative; }
.cloth-card canvas { width: 80px; height: 96px; }
.cloth-card .price { font-size: 14px; color: #a0701c; display: flex; align-items: center; gap: 3px; }
.cloth-card .price.free { color: #4f8a44; }
.cloth-card.wearing { border-color: #4f8a44; background: #eef7e6; }
.cloth-card.fancy::after { content: "✦"; position: absolute; top: 2px; right: 6px; font-size: 13px; color: #b58a2a; }
.quest-note { margin-top: 10px; padding: 8px; border: 2px dashed var(--edge); border-radius: 12px; font-size: 16px; text-align: left; }
.quest-note button { margin-top: 6px; }
.quest-row { padding: 8px 12px; margin-bottom: 8px; border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px; background: rgba(255, 252, 244, 0.7); }
.quest-row.done { opacity: 0.6; }
.have { color: #3f7a3a; }
.need { color: #b5473a; }
@media (max-width: 760px) { .tailor-grid { grid-template-columns: 1fr; } }
