/* Treehouse: style.css. A hand-drawn notebook look: thick ink lines, wobbly boxes, bright colours. */
:root {
  --ink: #1b1b1b; --paper: #fffbe9; --paper2: #fff3c9; --green: #7cc35b; --pink: #ff6fa3; --yellow: #ffd23f;
  --blue: #19c3c9; --red: #e94f4f; --orange: #ff8a3d; --purple: #8d6cc9;
  --wob: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wob2: 15px 225px 15px 255px / 255px 15px 225px 15px;
  --font: "Patrick Hand", "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfeefd; color: var(--ink); font-family: var(--font); font-size: 18px;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
input { user-select: text; -webkit-user-select: text; }
#world { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
/* a faint paper grain over the whole game */
#paper { position: fixed; inset: 0; pointer-events: none; opacity: 0.16; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.38 0 0 0 0 0.25 0 0 0 0.9 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>"); }
.hide { display: none !important; }
button { font-family: var(--font); color: var(--ink); cursor: pointer; }

/* ---------- cards and buttons ---------- */
.card { background: var(--paper); border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 5px 6px 0 rgba(0,0,0,0.25); padding: 18px 20px; }
.btn { font-size: 20px; padding: 8px 18px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob2); box-shadow: 3px 4px 0 var(--ink);
  transition: transform .08s; white-space: nowrap; }
.btn:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.green { background: var(--green); } .btn.pink { background: var(--pink); } .btn.yellow { background: var(--yellow); } .btn.blue { background: var(--blue); }
.btn.red { background: #ff9a9a; }
.btn.big { font-size: 26px; padding: 10px 26px; width: 100%; margin-top: 8px; }
.btn.small { font-size: 17px; padding: 4px 12px; box-shadow: 2px 3px 0 var(--ink); }
.btn:disabled { opacity: .45; }
.tiny { font-size: 14px; opacity: .8; }
.msg { min-height: 22px; color: #b3261e; margin: 6px 0 0; font-size: 17px; }
a { color: #2f6db3; }

/* ---------- log in ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.login-card { width: min(420px, 100%); transform: rotate(-0.6deg); }
.logo { font-size: 58px; margin: 0; line-height: 1; text-align: center; color: #8a5a33; text-shadow: 3px 3px 0 var(--ink); letter-spacing: 1px;
  -webkit-text-stroke: 1.5px var(--ink); }
.logo span { color: var(--green); }
.sub { text-align: center; margin: 4px 0 12px; }
.tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.tab { flex: 1; font-size: 20px; padding: 6px; background: #f2ead0; border: 3px solid var(--ink); border-radius: var(--wob2); }
.tab.on { background: var(--yellow); }
label { display: block; margin: 8px 0; font-size: 19px; }
label input { display: block; width: 100%; margin-top: 3px; font-family: var(--font); font-size: 22px; padding: 6px 10px; border: 3px solid var(--ink);
  border-radius: var(--wob); background: #fff; outline: none; }
label input:focus { background: #fffde0; }
.known { display: flex; flex-wrap: wrap; gap: 6px; }
.known button { font-size: 17px; padding: 3px 10px; background: #e7f6ff; border: 2px solid var(--ink); border-radius: var(--wob2); }
.known button.on { background: var(--blue); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topLeft { position: absolute; left: calc(10px + var(--safe-l)); top: calc(10px + var(--safe-t)); }
.me-card { display: flex; align-items: center; gap: 10px; background: var(--paper); border: 3px solid var(--ink); border-radius: var(--wob); padding: 6px 12px 6px 8px;
  box-shadow: 3px 4px 0 rgba(0,0,0,.25); min-width: 180px; }
.lvl { width: 46px; height: 46px; border-radius: 50%; background: var(--yellow); border: 3px solid var(--ink); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: bold; }
.me-name { font-size: 20px; line-height: 1; }
.me-floor { font-size: 14px; opacity: .85; }
.xpbar { width: 130px; height: 12px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; overflow: hidden; margin: 3px 0; }
#xpFill { height: 100%; width: 0; background: var(--green); transition: width .4s; }
.net-badge { margin-top: 6px; background: #e7f6ff; border: 2px solid var(--ink); border-radius: var(--wob2); padding: 2px 10px; font-size: 16px; display: inline-block; }
.inv { position: absolute; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; max-width: 46vw; }
.inv span { background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wob2); padding: 1px 9px; font-size: 18px; box-shadow: 2px 2px 0 rgba(0,0,0,.2); }
.inv span.bump { animation: bump .35s; }
@keyframes bump { 50% { transform: scale(1.3) rotate(-4deg); } }
.views { position: absolute; left: 50%; transform: translateX(-50%); top: calc(10px + var(--safe-t)); display: flex; gap: 4px; }
.views button { background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wob2); font-size: 18px; padding: 3px 9px; }
.views button span { margin-left: 4px; font-size: 16px; }
.views button.on { background: var(--yellow); }
.menu { position: absolute; right: calc(10px + var(--safe-r)); top: calc(62px + var(--safe-t)); display: flex; flex-direction: column; gap: 6px; }
.menu button { position: relative; width: 64px; height: 56px; background: var(--paper); border: 3px solid var(--ink); border-radius: var(--wob2); font-size: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: 2px 3px 0 rgba(0,0,0,.25); }
.menu button span { font-size: 13px; margin-top: 2px; }
.menu button.on { background: var(--yellow); }
.menu button:nth-child(odd) { transform: rotate(-1.5deg); } .menu button:nth-child(even) { transform: rotate(1.2deg); }
.dot { position: absolute; top: -4px; right: -4px; width: 16px; height: 16px; border-radius: 50%; background: var(--red); border: 2px solid var(--ink); }

/* joystick and buttons */
.joy { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px dashed rgba(27,27,27,.5); background: rgba(255,255,255,.25);
  left: calc(30px + var(--safe-l)); bottom: calc(30px + var(--safe-b)); display: none; pointer-events: none !important; }
body.touch .joy { display: block; opacity: .55; }
.joy.on { opacity: 1 !important; }
#joyKnob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); }
.pads { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); display: flex; align-items: flex-end; gap: 10px; }
.pad { border: 3px solid var(--ink); background: var(--paper); border-radius: 50%; box-shadow: 3px 4px 0 rgba(0,0,0,.3); font-size: 26px; touch-action: none; }
.pad:active { transform: translate(2px, 3px); }
.pad.jump { width: 92px; height: 92px; background: var(--green); font-size: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pad.jump span { font-size: 15px; }
.pad.small { width: 58px; height: 58px; }
.pad.action { min-width: 92px; height: 66px; border-radius: var(--wob2); background: var(--yellow); font-size: 20px; padding: 0 12px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
body:not(.touch) .pad.jump { width: 70px; height: 70px; font-size: 26px; }

/* challenge */
.ch-hud { position: absolute; left: 50%; top: calc(56px + var(--safe-t)); transform: translateX(-50%); background: var(--paper); border: 3px solid var(--ink);
  border-radius: var(--wob); padding: 6px 16px; text-align: center; box-shadow: 4px 5px 0 rgba(0,0,0,.25); min-width: 190px; }
.ch-clock { font-size: 40px; line-height: 1; }
#chScore { font-size: 20px; }
.big-count { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: 140px; color: var(--yellow); -webkit-text-stroke: 4px var(--ink);
  pointer-events: none; animation: pop .8s; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(2); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* building */
.build-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); background: var(--paper); border: 3px solid var(--ink);
  border-radius: var(--wob); padding: 8px 10px; box-shadow: 4px 5px 0 rgba(0,0,0,.25); max-width: calc(100vw - 260px); }
.block-pick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.block-pick button { flex: 0 0 auto; width: 58px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; padding: 2px; font-size: 13px; line-height: 1.1; }
.block-pick button i { display: block; width: 30px; height: 26px; margin: 2px auto; border: 2px solid var(--ink); border-radius: 4px; }
.block-pick button.on { background: var(--yellow); transform: translateY(-3px); }
.block-pick button.locked { opacity: .4; }
.build-btns { display: flex; gap: 6px; justify-content: center; margin-top: 4px; }
.build-btns .on { background: #ff9a9a; }
.build-help { text-align: center; }

/* emotes and lift */
.emote-menu, .lift-menu { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(120px + var(--safe-b)); background: var(--paper); border: 3px solid var(--ink);
  border-radius: var(--wob); padding: 10px; box-shadow: 4px 5px 0 rgba(0,0,0,.25); width: min(330px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; }
.emote-menu .emo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.emote-menu .emo button { font-size: 30px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 4px; }
.emote-menu .phr { display: flex; flex-wrap: wrap; gap: 5px; }
.emote-menu .phr button { font-size: 16px; background: #e7f6ff; border: 2px solid var(--ink); border-radius: var(--wob2); padding: 3px 9px; }
.lift-menu h3 { margin: 0 0 6px; }
.lift-menu button { display: flex; width: 100%; justify-content: space-between; margin: 4px 0; font-size: 18px; background: #fff; border: 2px solid var(--ink);
  border-radius: var(--wob2); padding: 4px 10px; }
.lift-menu button.here { background: var(--yellow); }
.lift-menu button:disabled { opacity: .5; }

/* toasts */
#toasts { position: fixed; left: 50%; top: calc(120px + var(--safe-t)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 30; width: min(560px, 92vw); }
.toast { background: var(--paper); border: 3px solid var(--ink); border-radius: var(--wob2); padding: 6px 16px; font-size: 19px; box-shadow: 3px 4px 0 rgba(0,0,0,.25);
  animation: tin .3s; text-align: center; }
.toast.big { background: var(--yellow); font-size: 24px; }
@keyframes tin { from { transform: translateY(-10px) scale(.9); opacity: 0; } }

/* panels */
.modal { position: fixed; inset: 0; background: rgba(40, 30, 10, .35); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.modal.side { justify-content: flex-end; background: transparent; pointer-events: none; }
.modal.side .modal-card { pointer-events: auto; width: min(420px, 58vw); max-height: calc(100vh - 24px); }
.modal-card { position: relative; width: min(760px, 100%); max-height: calc(100vh - 24px); overflow: auto; padding: 16px 18px; }
.modal-card h2 { margin: 0 0 8px; font-size: 32px; }
.modal-card h3 { margin: 14px 0 6px; font-size: 23px; }
.x { position: sticky; float: right; top: 0; font-size: 20px; background: #fff; border: 2px solid var(--ink); border-radius: 50%; width: 38px; height: 38px; z-index: 2; }
.row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 2px dashed rgba(27,27,27,.2); }
.row .grow { flex: 1; min-width: 0; }
.row .ic { font-size: 30px; width: 40px; text-align: center; }
.bar { height: 12px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: var(--green); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.item { background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); padding: 8px; text-align: center; }
.item .ic { font-size: 40px; }
.item.owned { background: #e9f8df; }
.item.locked { opacity: .5; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 38px; height: 38px; border: 3px solid var(--ink); border-radius: 50%; }
.swatches button.on { outline: 4px solid var(--yellow); outline-offset: 1px; transform: scale(1.1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font-size: 17px; background: #fff; border: 2px solid var(--ink); border-radius: var(--wob2); padding: 4px 10px; }
.chips button.on { background: var(--yellow); }
.tbl { width: 100%; border-collapse: collapse; font-size: 18px; }
.tbl td, .tbl th { padding: 5px 6px; border-bottom: 2px dashed rgba(27,27,27,.2); text-align: left; }
.tbl tr.me { background: #fff3a0; }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.medal { font-size: 26px; }
.center { text-align: center; }
.result-big { font-size: 64px; text-align: center; margin: 6px 0; }
.loading { position: fixed; inset: 0; background: var(--paper); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 50; }
.loading p { font-size: 22px; }
.help-keys td:first-child { white-space: nowrap; font-weight: bold; }

/* phones */
@media (max-width: 720px), (max-height: 480px) {
  html, body { font-size: 16px; }
  .menu { top: calc(52px + var(--safe-t)); gap: 4px; }
  .menu button { width: 52px; height: 46px; font-size: 20px; }
  .menu button span { font-size: 11px; }
  .me-card { min-width: 0; padding: 4px 8px 4px 5px; }
  .lvl { width: 38px; height: 38px; font-size: 20px; }
  .xpbar { width: 90px; }
  .views { top: auto; bottom: calc(150px + var(--safe-b)); left: auto; right: calc(10px + var(--safe-r)); transform: none; flex-direction: column; }
  .views button span { display: none; }
  .inv { max-width: 40vw; }
  .inv span { font-size: 15px; padding: 0 6px; }
  .build-bar { max-width: calc(100vw - 20px); bottom: calc(110px + var(--safe-b)); }
  .modal.side .modal-card { width: min(420px, 100%); }
  .modal.side { justify-content: center; align-items: flex-end; }
  .modal.side .modal-card { max-height: 55vh; }
  .logo { font-size: 46px; }
}
@media (max-height: 480px) {
  .menu { flex-direction: row; flex-wrap: wrap; top: auto; bottom: calc(8px + var(--safe-b)); right: auto; left: 50%; transform: translateX(-50%); max-width: 60vw; justify-content: center; }
  .menu button { width: 44px; height: 40px; font-size: 18px; }
  .menu button span { display: none; }
  .views { bottom: calc(110px + var(--safe-b)); }
  .build-bar { bottom: calc(56px + var(--safe-b)); }
}
