:root {
  --ink: #4a2e3f;
  --rose: #c0607a;
  --plum: #6a4c7a;
  --cream: #fbf6ee;
  --stitch: #c48aa8;
  --knit-cream: none; /* set from the yarn texture engine at startup */
  --knit-plum: none;
  --font: "Chalkboard SE", "Comic Sans MS", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1f2a; font-family: var(--font); color: var(--ink); }
.hidden { display: none !important; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
button { font-family: var(--font); cursor: pointer; }
input, textarea, select { font-family: var(--font); font-size: 16px; color: var(--ink); }

/* knitted panels */
.panel {
  background: var(--knit-cream), var(--cream);
  background-size: 48px;
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 10px 40px rgba(30, 10, 30, .45), inset 0 0 0 6px rgba(255,255,255,.35);
  outline: 3px dashed var(--stitch);
  outline-offset: -12px;
  position: relative;
}
.panel h2 { margin: 0 0 10px; font-size: 26px; color: var(--plum); }
.paper { background: rgba(251, 246, 238, .93); border-radius: 14px; padding: 14px; }

#login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--knit-plum), #4a3050; background-size: 64px; z-index: 50; }
.loginPanel { width: min(440px, 92vw); text-align: center; }
.logo { font-size: 54px; margin: 6px 0 0; color: var(--rose); text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(106,76,122,.35); letter-spacing: 1px; }
.logo span { color: var(--plum); }
.tag { margin: 4px 0 18px; }
#loginForm label { display: block; text-align: left; margin: 10px 0; font-weight: bold; }
#loginForm input { display: block; width: 100%; padding: 10px 14px; margin-top: 4px; border-radius: 14px; border: 3px solid #e4cfd9; background: #fff; }
.small { font-size: 13px; opacity: .85; }
.error { color: #b02a3a; min-height: 1.2em; font-weight: bold; }

.btn, button.big {
  border: none; border-radius: 16px; padding: 10px 18px; font-size: 17px; font-weight: bold; color: #fff;
  background: var(--rose); box-shadow: 0 4px 0 #8a3a52; transition: transform .08s;
  outline: 2px dashed rgba(255,255,255,.55); outline-offset: -6px;
}
button.big { width: 100%; padding: 14px; font-size: 20px; margin-top: 10px; }
.btn:hover, button.big:hover { transform: translateY(-1px); }
.btn:active, button.big:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a3a52; }
.btn.alt { background: var(--plum); box-shadow: 0 4px 0 #3e2c4a; }
.btn.green { background: #3c8d5a; box-shadow: 0 4px 0 #24583a; }
.btn.blue { background: #3a6fa8; box-shadow: 0 4px 0 #23476e; }
.btn.ghost { background: #e8dcd8; color: var(--ink); box-shadow: 0 4px 0 #bfaaa6; }
.btn:disabled { opacity: .45; cursor: default; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.chip { position: absolute; top: 14px; padding: 8px 16px; border-radius: 18px; background: rgba(251,246,238,.92); outline: 2px dashed var(--stitch); outline-offset: -5px; font-weight: bold; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
#where { left: 14px; }
#coins { right: 14px; font-size: 18px; }
#coins.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.25); } }
#hint { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); background: rgba(74,46,63,.85); color: #fff; padding: 8px 18px; border-radius: 16px; font-size: 16px; white-space: nowrap; }
#toolbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: auto; padding: 8px; border-radius: 22px; background: rgba(251,246,238,.85); outline: 2px dashed var(--stitch); outline-offset: -5px; }
#toolbar button { border: none; background: #fff; border-radius: 14px; font-size: 24px; width: 64px; height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 0 #d8c4ce; }
#toolbar button span { font-size: 11px; font-weight: bold; color: var(--ink); }
#toolbar button:hover { background: #fdeef3; }
#crosshair { position: fixed; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: rgba(255,255,255,.7); box-shadow: 0 0 0 2px rgba(74,46,63,.4); pointer-events: none; z-index: 5; }

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.openPost { position: absolute; transform: translate(-50%, -100%); pointer-events: auto; cursor: pointer; background: linear-gradient(90deg, #e74c3c, #f39c12, #2ecc71, #3498db, #8e44ad); color: #fff; font-weight: bold; padding: 6px 14px; border-radius: 14px; border: 3px solid #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.4); box-shadow: 0 3px 8px rgba(0,0,0,.3); animation: bob 1.2s ease-in-out infinite; white-space: nowrap; }
@keyframes bob { 50% { margin-top: -5px; } }

/* modal */
#modalWrap { position: fixed; inset: 0; background: rgba(40, 20, 40, .45); display: grid; place-items: center; z-index: 30; }
#modal { width: min(720px, 94vw); max-height: 90vh; overflow: auto; }
.close { position: absolute; top: 14px; right: 18px; background: #fff; border: none; border-radius: 50%; width: 38px; height: 38px; font-size: 20px; box-shadow: 0 2px 0 #d8c4ce; z-index: 2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { background: rgba(255,255,255,.9); border-radius: 16px; padding: 12px; text-align: center; border: 3px solid transparent; cursor: pointer; }
.card.sel { border-color: var(--rose); background: #fff1f5; }
.card .emoji { font-size: 34px; }
.card .price { font-weight: bold; color: var(--plum); }
.card.disabled { opacity: .5; cursor: default; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #d8c4ce; cursor: pointer; }
.swatch.sel { box-shadow: 0 0 0 3px var(--rose); transform: scale(1.1); }
input[type=color] { width: 44px; height: 38px; border: none; background: none; cursor: pointer; }
.field { width: 100%; padding: 10px 12px; border-radius: 12px; border: 3px solid #e4cfd9; background: #fff; }
textarea.field { min-height: 120px; resize: vertical; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { border: none; padding: 8px 14px; border-radius: 12px; background: #fff; font-weight: bold; font-size: 15px; box-shadow: 0 3px 0 #d8c4ce; }
.tabs button.on { background: var(--plum); color: #fff; box-shadow: 0 3px 0 #3e2c4a; }
.split { display: flex; gap: 16px; flex-wrap: wrap; }
.split > .preview { flex: 0 0 220px; height: 280px; border-radius: 16px; overflow: hidden; background: radial-gradient(#fff, #f0dfe8); }
.split > .controls { flex: 1 1 280px; }
.pill { display: inline-block; background: #fff; border-radius: 10px; padding: 2px 10px; margin: 2px; font-size: 14px; }
.muted { opacity: .75; font-size: 14px; }

/* the knit piece of paper for posts */
.postPaper { background: var(--knit-cream), #f3ead9; background-size: 40px; border-radius: 10px; padding: 18px; }
.postPaper .sheet { background: #fffdf7; border-radius: 6px; padding: 18px 20px; box-shadow: 0 2px 8px rgba(0,0,0,.15); border: 2px dashed #d8b8c8; }
.postPaper .media { width: 100%; max-height: 420px; object-fit: contain; border-radius: 8px; background: #eee; display: block; margin-bottom: 12px; }
.postPaper iframe.media { aspect-ratio: 16/9; height: auto; border: none; }
.postPaper .text { white-space: pre-wrap; font-size: 18px; line-height: 1.45; }
.postPaper .by { margin-top: 14px; font-weight: bold; color: var(--plum); }

/* map */
.mapCanvas { width: 100%; border-radius: 14px; cursor: crosshair; display: block; box-shadow: inset 0 0 0 3px #fff; }

/* book */
.bookPage { background: #fffdf7; border-radius: 6px 14px 14px 6px; padding: 24px; min-height: 300px; white-space: pre-wrap; font-size: 18px; line-height: 1.55; box-shadow: inset 12px 0 18px -12px rgba(0,0,0,.3), 0 3px 10px rgba(0,0,0,.15); border-left: 8px solid #a8467f; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.photos img { width: 100%; border-radius: 10px; border: 6px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); cursor: pointer; }

#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(251,246,238,.97); padding: 10px 20px; border-radius: 16px; font-weight: bold; box-shadow: 0 4px 14px rgba(0,0,0,.3); outline: 2px dashed var(--stitch); outline-offset: -5px; animation: toastIn .3s; max-width: 80vw; }
.toast.mega { background: #fff1f5; font-size: 18px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

#fade { position: fixed; inset: 0; background: #2a1f2a; opacity: 0; pointer-events: none; transition: opacity .35s; z-index: 45; }
#fade.on { opacity: 1; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 46; transition: opacity .4s; }
#flash.on { opacity: .9; transition: none; }

#flight { position: fixed; inset: 0; z-index: 47; }
.flightSky { position: absolute; inset: 0; background: var(--knit-sky, #86b6e2); background-size: 64px; display: grid; place-items: center; overflow: hidden; }
.plane { position: absolute; font-size: 120px; left: -200px; top: 35%; animation: fly 3s ease-in-out forwards; filter: drop-shadow(4px 8px 0 rgba(0,0,0,.15)); }
@keyframes fly { to { left: 110%; top: 25%; } }
#flightText { font-size: 34px; font-weight: bold; background: rgba(251,246,238,.92); padding: 14px 28px; border-radius: 20px; outline: 3px dashed var(--stitch); outline-offset: -8px; margin-top: 260px; }

/* messages from friends */
#messages { position: fixed; top: 64px; right: 14px; z-index: 35; display: flex; flex-direction: column; gap: 10px; width: min(320px, 80vw); }
.message { background: var(--knit-cream), var(--cream); background-size: 40px; border-radius: 18px; padding: 14px; box-shadow: 0 6px 20px rgba(30,10,30,.35); outline: 2px dashed var(--stitch); outline-offset: -7px; animation: toastIn .3s; }
.message .from { color: var(--plum); margin-bottom: 4px; }
.message .text { background: rgba(255,255,255,.85); border-radius: 10px; padding: 8px 10px; white-space: pre-wrap; word-wrap: break-word; }
.message .row { margin: 8px 0 0; }
.message .btn { font-size: 14px; padding: 6px 12px; }

/* under the sea: a soft blue-green tint with a darker edge */
#underwater { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: radial-gradient(ellipse at 50% 40%, rgba(80,200,230,.08), rgba(10,60,90,.45)); mix-blend-mode: multiply; }
.pickGrid img { cursor: pointer; }

/* The Stitch Times */
.newspaper { background: #faf6ec; border-radius: 6px; padding: 22px 26px; color: #2a2a2a; box-shadow: inset 0 0 40px rgba(120,100,60,.15); font-family: Georgia, "Times New Roman", serif; }
.newspaper .masthead { text-align: center; font: bold 46px/1 "Chalkboard SE", Georgia, serif; letter-spacing: 1px; border-bottom: 3px double #2a2a2a; padding-bottom: 8px; }
.newspaper .dateline { display: flex; justify-content: space-between; font-size: 13px; text-transform: uppercase; border-bottom: 1px solid #2a2a2a; padding: 4px 0; margin-bottom: 12px; }
.newspaper .headline { font-size: 32px; text-align: center; margin: 6px 0 16px; line-height: 1.15; }
.newspaper .columns { columns: 2 260px; column-gap: 26px; column-rule: 1px solid #c8c0b0; }
.newspaper article { break-inside: avoid; margin-bottom: 16px; }
.newspaper article img { width: 100%; border-radius: 4px; filter: sepia(.15); }
.newspaper article h3 { margin: 6px 0 4px; font-size: 20px; }
.newspaper article p { margin: 0; white-space: pre-wrap; line-height: 1.5; font-size: 16px; }
.newspaper .editor { text-align: right; font-style: italic; margin-top: 8px; font-size: 14px; }

/* your pet, always in the corner of the screen */
#petBadge { position: absolute; left: 14px; bottom: 14px; pointer-events: auto; border: none; border-radius: 22px; padding: 6px 10px 6px 6px; display: flex; align-items: center; gap: 6px; background: rgba(251,246,238,.92); outline: 2px dashed var(--stitch); outline-offset: -5px; box-shadow: 0 3px 10px rgba(0,0,0,.25); font-weight: bold; font-size: 15px; color: var(--ink); }
#petBadge canvas { width: 58px; height: 58px; border-radius: 50%; background: radial-gradient(#fff, #f0dfe8); }
#petBadge:hover canvas { animation: bump .5s; }
