:root {
  --cream: #fff8ec;
  --cream2: #fff1db;
  --brown: #6b4a33;
  --brown2: #a8774f;
  --pink: #ff8fb1;
  --pink2: #ff6b9a;
  --mint: #7fd8b4;
  --sky: #bfe6ff;
  --gold: #ffcf4d;
  --shadow: 0 6px 0 rgba(120, 80, 50, 0.18), 0 10px 24px rgba(80, 50, 30, 0.18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6ff; font-family: Fredoka, 'Baloo 2', system-ui, sans-serif; color: var(--brown); user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }

.card { background: var(--cream); border: 3px solid #f0d9b5; border-radius: 22px; box-shadow: var(--shadow); }

.btn { font-family: inherit; font-weight: 600; font-size: 18px; color: #fff; background: linear-gradient(#ff9fc0, var(--pink2)); border: none; border-radius: 999px; padding: 10px 22px; cursor: pointer; box-shadow: 0 5px 0 #d94f7f, 0 8px 16px rgba(200, 60, 110, 0.25); transition: transform .08s, box-shadow .08s; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #d94f7f; }
.btn.big { font-size: 24px; padding: 14px 34px; }
.btn.small { font-size: 15px; padding: 7px 16px; }
.btn.green { background: linear-gradient(#9be6b8, #4cc285); box-shadow: 0 5px 0 #2f9a63, 0 8px 16px rgba(40, 140, 90, 0.25); }
.btn.blue { background: linear-gradient(#a8d8ff, #5aa8ee); box-shadow: 0 5px 0 #3b82c4, 0 8px 16px rgba(40, 100, 160, 0.25); }
.btn.gold { background: linear-gradient(#ffe08a, #f2b632); box-shadow: 0 5px 0 #c98d12, 0 8px 16px rgba(200, 140, 20, 0.25); color: #6b4a10; }
.btn.ghost { background: transparent; color: var(--brown2); box-shadow: none; text-decoration: underline; }
.btn:disabled { filter: grayscale(0.8); opacity: 0.55; cursor: default; transform: none; }
.round { font-family: inherit; width: 52px; height: 52px; border-radius: 50%; border: 3px solid #f0d9b5; background: var(--cream); font-size: 24px; cursor: pointer; box-shadow: var(--shadow); display: grid; place-items: center; padding: 0; transition: transform .1s; }
.round:hover { transform: scale(1.08) rotate(-4deg); }
.round.small { width: 38px; height: 38px; font-size: 16px; }

/* screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
#loading { background: linear-gradient(#bfe6ff, #fde8d0); flex-direction: column; }
.loader-horse { font-size: 80px; animation: bounce 0.6s infinite alternate ease-in-out; text-align: center; }
.loader-text { font-size: 22px; font-weight: 600; text-align: center; margin-top: 10px; }
@keyframes bounce { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-24px) rotate(6deg); } }

#title { background: radial-gradient(ellipse at center, rgba(255,248,236,0) 30%, rgba(255,230,240,0.35) 100%); overflow-y: auto; padding: 16px; }
.title-card { background: rgba(255, 248, 236, 0.93); border: 4px solid #f0d9b5; border-radius: 34px; box-shadow: var(--shadow); padding: 26px 34px; max-width: 520px; width: 100%; text-align: center; animation: popIn .5s cubic-bezier(.3,1.6,.5,1); }
.logo { font-size: 58px; margin: 0; line-height: 1; font-weight: 700; color: var(--pink2); text-shadow: 0 4px 0 #fff, 0 7px 0 #f0c3d2; letter-spacing: 1px; }
.logo span:nth-child(2) { color: #5fb87e; text-shadow: 0 4px 0 #fff, 0 7px 0 #bfe3c9; }
.tagline { font-size: 18px; margin: 12px 0 18px; }
.field { display: block; margin: 12px 0; text-align: left; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 16px; }
.field input { width: 100%; font-family: inherit; font-size: 20px; padding: 10px 16px; border-radius: 16px; border: 3px solid #f0d9b5; background: #fff; color: var(--brown); outline: none; user-select: text; -webkit-user-select: text; }
.field input:focus { border-color: var(--pink); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #f0d9b5; cursor: pointer; transition: transform .1s; }
.swatch.sel { box-shadow: 0 0 0 4px var(--pink2); transform: scale(1.12); }
#titleNew .btn, #titleContinue .btn { margin-top: 12px; }
#titleContinue { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 8px; }
.controls-hint { font-size: 13px; opacity: 0.75; margin-top: 18px; line-height: 1.6; }
@keyframes popIn { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .card { pointer-events: auto; }
#goal { position: absolute; left: 16px; top: 16px; max-width: 300px; padding: 10px 16px; font-size: 16px; line-height: 1.35; }
.goal-label { font-size: 13px; font-weight: 600; color: var(--pink2); margin-bottom: 2px; }
#goalText { font-weight: 500; }
#compass { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); width: min(440px, 40vw); height: 46px; background: var(--cream); border: 3px solid #f0d9b5; border-radius: 999px; overflow: hidden; box-shadow: var(--shadow); }
#compassStrip { position: absolute; inset: 0; }
.cmark { position: absolute; top: 50%; transform: translate(-50%, -50%); font-weight: 700; font-size: 15px; white-space: nowrap; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.cmark.dir { color: var(--brown2); }
.cmark .ic { font-size: 22px; }
.cmark .dist { font-size: 10px; font-weight: 600; opacity: 0.8; }
.cmark.target .ic { animation: wiggle 1s infinite; filter: drop-shadow(0 0 4px #ffcf4d); }
.cmark.unknown .ic { filter: grayscale(0.2); }
.compass-needle { position: absolute; left: 50%; top: 0; width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--pink2); transform: translateX(-50%); }
@keyframes wiggle { 0%,100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.2) rotate(8deg); } }
#topRight { position: absolute; right: 16px; top: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
#inv { display: flex; gap: 12px; padding: 8px 14px; font-size: 18px; font-weight: 600; align-items: center; }
#inv .it { display: flex; align-items: center; gap: 3px; }
#inv .it.bump { animation: bump .4s; }
@keyframes bump { 50% { transform: scale(1.5); } }
.hud-buttons { display: flex; gap: 8px; }
#rideInfo { position: absolute; left: 16px; bottom: 16px; display: flex; gap: 10px; padding: 8px 16px 10px 8px; align-items: center; }
#ridePortrait { width: 64px; height: 64px; border-radius: 50%; background: #e7f6ff; overflow: hidden; border: 3px solid #f0d9b5; }
#ridePortrait svg { width: 100%; height: 100%; }
#rideName { font-weight: 700; font-size: 18px; }
#rideHearts { font-size: 13px; letter-spacing: 1px; }
.bar { width: 150px; height: 12px; background: #f0e2cc; border-radius: 999px; overflow: hidden; margin-top: 4px; }
#staminaBar { height: 100%; width: 100%; background: linear-gradient(90deg, #7fd8b4, #5fc4e8); border-radius: 999px; transition: width .1s; }
#staminaBar.low { background: linear-gradient(90deg, #ffb36b, #ff7b7b); }
#prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--cream); border: 3px solid #f0d9b5; padding: 10px 22px; border-radius: 999px; font-size: 20px; font-weight: 600; box-shadow: var(--shadow); animation: floaty 1.4s infinite ease-in-out; white-space: nowrap; pointer-events: auto; cursor: pointer; }
#prompt kbd { background: var(--pink2); color: #fff; border-radius: 8px; padding: 1px 9px; margin-right: 6px; font-family: inherit; box-shadow: 0 3px 0 #d94f7f; }
@keyframes floaty { 50% { transform: translate(-50%, -6px); } }
#toasts { position: absolute; top: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.toast { background: var(--cream); border: 3px solid #f0d9b5; border-radius: 18px; padding: 10px 20px; font-size: 18px; font-weight: 600; box-shadow: var(--shadow); animation: toastIn .45s cubic-bezier(.3,1.6,.5,1); text-align: center; max-width: 80vw; }
.toast.big { font-size: 24px; background: linear-gradient(#fff8ec, #ffe6f0); border-color: #ffc2d6; }
.toast.out { animation: toastOut .4s forwards; }
@keyframes toastIn { from { transform: translateY(-20px) scale(0.7); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-20px); opacity: 0; } }

/* touch */
#touch { position: absolute; inset: 0; pointer-events: none; }
#joy { position: absolute; left: 30px; bottom: 120px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255, 248, 236, 0.45); border: 3px solid rgba(240, 217, 181, 0.8); pointer-events: auto; touch-action: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: var(--cream); border: 3px solid #f0d9b5; box-shadow: var(--shadow); }
#touchBtns { position: absolute; right: 24px; bottom: 30px; display: flex; flex-direction: column; gap: 14px; align-items: flex-end; }
.tbtn { pointer-events: auto; width: 84px; height: 84px; border-radius: 50%; border: 3px solid #f0d9b5; background: rgba(255, 248, 236, 0.85); font-size: 30px; font-family: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: var(--shadow); touch-action: none; color: var(--brown); }
.tbtn small { font-size: 12px; font-weight: 600; }
.tbtn.on { background: #ffd8e6; transform: scale(0.95); }
#tAct { background: #ffe6f0; animation: floaty2 1.2s infinite; }
@keyframes floaty2 { 50% { transform: translateY(-5px); } }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(90, 60, 40, 0.35); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 30; padding: 12px; }
#modalBox { position: relative; width: min(880px, 100%); max-height: calc(100vh - 24px); overflow: auto; padding: 22px 26px; animation: popIn .35s cubic-bezier(.3,1.5,.5,1); }
#modalClose { position: absolute; right: 12px; top: 12px; z-index: 2; }
#modalContent h2 { margin: 0 0 8px; font-size: 30px; color: var(--pink2); }
#modalContent h3 { margin: 16px 0 8px; font-size: 20px; }
.sub { margin: 0 0 14px; opacity: 0.85; }

/* map */
.map-wrap { position: relative; width: min(600px, 100%, calc(100vh - 170px)); aspect-ratio: 1; margin: 0 auto; border-radius: 24px; overflow: hidden; border: 4px solid #f0d9b5; background: #8fd8e8; }
.map-wrap canvas { width: 100%; height: 100%; display: block; image-rendering: auto; }
.map-pin { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; font-weight: 600; font-size: 12px; text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff; cursor: default; }
.map-pin .pic { font-size: 26px; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--cream); border: 3px solid #f0d9b5; box-shadow: 0 3px 0 rgba(0,0,0,0.15); }
.map-pin.go { cursor: pointer; }
.map-pin.go .pic { animation: floaty2 1.6s infinite; }
.map-pin.go:hover .pic { background: #ffe6f0; border-color: var(--pink); transform: scale(1.15); }
.map-pin.unknown .pic { background: #e9e2d6; color: #a08b74; font-weight: 700; font-size: 22px; }
.map-pin.horse .pic { width: 24px; height: 24px; font-size: 14px; }
.map-player { position: absolute; width: 0; height: 0; border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 22px solid var(--pink2); transform-origin: 50% 66%; filter: drop-shadow(0 0 3px #fff); }
.map-legend { text-align: center; margin-top: 10px; font-size: 15px; }

/* stable */
.horse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.hcard { background: #fff; border: 3px solid #f0d9b5; border-radius: 20px; padding: 12px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.hcard.riding { border-color: var(--pink); background: #fff5f9; }
.hcard .top { display: flex; gap: 10px; align-items: center; }
.hcard .pic { width: 76px; height: 76px; border-radius: 50%; background: #e7f6ff; overflow: hidden; flex: none; border: 3px solid #f0d9b5; }
.hcard .pic svg { width: 100%; height: 100%; }
.hcard .nm { font-size: 22px; font-weight: 700; }
.hcard .br { font-size: 13px; opacity: 0.75; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.stat .lbl { width: 62px; }
.stat .pips { letter-spacing: 1px; }
.hcard .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.hcard .btns .btn { font-size: 14px; padding: 6px 12px; }
.riding-badge { position: absolute; right: 10px; top: 10px; background: var(--pink2); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.mystery { opacity: 0.6; }
.mystery .pic { filter: brightness(0) opacity(0.25); }

/* dress up */
.opt-row { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 3px solid #f0d9b5; background: #fff; border-radius: 16px; padding: 8px 12px; cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 600; color: var(--brown); display: flex; align-items: center; gap: 6px; }
.opt.sel { border-color: var(--pink2); background: #ffe6f0; }
.opt:disabled { opacity: 0.45; cursor: default; }
.opt .dot { width: 20px; height: 20px; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px #ddd; }
.dress-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.dress-preview { border-radius: 20px; overflow: hidden; background: linear-gradient(#cfeeff, #fff3e0); border: 3px solid #f0d9b5; aspect-ratio: 1; }
.dress-preview canvas { width: 100% !important; height: 100% !important; }
@media (max-width: 640px) { .dress-layout { grid-template-columns: 1fr; } }

/* befriend */
.friend-wrap { text-align: center; }
.friend-pic { width: 140px; height: 140px; margin: 0 auto; border-radius: 50%; background: #e7f6ff; border: 4px solid #f0d9b5; overflow: hidden; }
.friend-pic svg { width: 100%; height: 100%; }
.friend-pic.happy { animation: bounce 0.4s 3 alternate; }
.friend-pic.shy { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.hearts-row { font-size: 38px; margin: 10px 0; letter-spacing: 6px; }
.meter { position: relative; height: 46px; background: #f0e2cc; border-radius: 999px; margin: 16px auto; max-width: 520px; overflow: hidden; border: 3px solid #e6cfaa; cursor: pointer; }
.meter .zone { position: absolute; top: 0; bottom: 0; background: linear-gradient(#b4f0cf, #7fd8b4); border-radius: 999px; }
.meter .cursor { position: absolute; top: 2px; font-size: 32px; line-height: 38px; transform: translateX(-50%); }
.say { font-size: 20px; font-weight: 600; min-height: 30px; margin: 8px 0; }
.big-emoji { font-size: 60px; }
.name-input { font-family: inherit; font-size: 22px; padding: 8px 14px; border-radius: 14px; border: 3px solid #f0d9b5; text-align: center; width: 220px; user-select: text; -webkit-user-select: text; color: var(--brown); }

/* journal */
.tabs { display: flex; gap: 8px; margin: 6px 0 14px; flex-wrap: wrap; }
.tab { font-family: inherit; font-size: 16px; font-weight: 600; padding: 8px 16px; border-radius: 999px; border: 3px solid #f0d9b5; background: #fff; color: var(--brown); cursor: pointer; }
.tab.sel { background: var(--pink); color: #fff; border-color: var(--pink2); }
.rosettes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.rosette { text-align: center; background: #fff; border: 3px solid #f0d9b5; border-radius: 18px; padding: 12px 8px; }
.rosette .e { font-size: 40px; }
.rosette.locked { opacity: 0.45; filter: grayscale(1); }
.rosette .n { font-weight: 700; }
.rosette .d { font-size: 12px; opacity: 0.8; }
.places { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.place { background: #fff; border: 3px solid #f0d9b5; border-radius: 18px; padding: 10px 14px; }
.place .n { font-weight: 700; font-size: 18px; }
.place .d { font-size: 13px; opacity: 0.85; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 2px dashed #f0d9b5; font-size: 18px; font-weight: 600; }
.toggle { width: 64px; height: 34px; border-radius: 999px; background: #e6d5bb; border: none; position: relative; cursor: pointer; }
.toggle::after { content: ''; position: absolute; left: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--mint); }
.toggle.on::after { left: 34px; }

#fade { position: fixed; inset: 0; pointer-events: none; z-index: 40; opacity: 0; transition: opacity .5s; background: radial-gradient(circle, #fff8ec 0%, #ffd6e6 60%, #c9b6ff 100%); display: grid; place-items: center; font-size: 80px; }
#fade.on { opacity: 1; }

@media (max-width: 760px) {
  #goal { max-width: 46vw; font-size: 13px; padding: 8px 12px; top: 72px; }
  #compass { width: 56vw; left: 16px; transform: none; height: 42px; }
  #toasts { top: 130px; }
  .logo { font-size: 42px; }
  #rideInfo { bottom: auto; top: auto; left: auto; right: 16px; bottom: 250px; display: none; }
  #inv { font-size: 15px; gap: 8px; padding: 6px 10px; }
  .round { width: 44px; height: 44px; font-size: 20px; }
  #prompt { bottom: 260px; font-size: 16px; }
}


.shoe { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.15em; background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 28 L5 14 A11 11 0 0 1 27 14 L25 28 L20 28 L21.5 15 A5.5 5.5 0 0 0 10.5 15 L12 28 Z' fill='%23ffcf3d' stroke='%23c98d12' stroke-width='1.6' stroke-linejoin='round'/%3E%3Ccircle cx='8.3' cy='17' r='1.1' fill='%23c98d12'/%3E%3Ccircle cx='23.7' cy='17' r='1.1' fill='%23c98d12'/%3E%3Ccircle cx='9' cy='23' r='1.1' fill='%23c98d12'/%3E%3Ccircle cx='23' cy='23' r='1.1' fill='%23c98d12'/%3E%3C/svg%3E"); }

/* soft storybook vignette */
#game::after { content: ''; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(255,240,220,0) 55%, rgba(120,80,60,0.18) 100%); }
