:root {
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", system-ui, -apple-system, sans-serif;
  --panel: rgba(255, 250, 238, 0.86);
  --ink: #2e3a24;
  --ink-soft: #5c6a4c;
  --green: #4e8a3a;
  --green-d: #376a28;
  --orange: #f0a030;
  --pink: #ff6f96;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #7fae6a;
  position: fixed; inset: 0; width: 100%;
  font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

button { font-family: var(--font); color: var(--ink); touch-action: manipulation; }
.btn {
  border: none; border-radius: 18px; padding: 14px 26px; font-size: 20px; font-weight: 700;
  background: #fff8e8; box-shadow: 0 4px 0 rgba(0,0,0,0.18); cursor: pointer;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.18); }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-d); font-size: 24px; padding: 16px 36px; }
.btn.danger { background: #d8584a; color: #fff; box-shadow: 0 5px 0 #a8382c; }
.btn.small { padding: 8px 12px; font-size: 20px; border-radius: 12px; }
.btn.round { width: 56px; height: 56px; padding: 0; border-radius: 50%; font-size: 26px; }
.btn.wide { width: 100%; margin-top: 14px; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; }
#loading { background: radial-gradient(circle at 50% 40%, #cfe8c0, #7fae6a); }
.load-box { text-align: center; }
.logo { font-size: 90px; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-4deg); } }
.load-box h1 { font-size: 44px; margin: 6px 0 20px; color: #2f4a22; }
.bar { width: 300px; height: 18px; border-radius: 10px; background: rgba(255,255,255,0.5); overflow: hidden; margin: 0 auto; }
#load-fill { height: 100%; width: 0; background: var(--orange); border-radius: 10px; transition: width 0.2s; }
#load-text { color: #2f4a22; font-size: 18px; }

#title { background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,0.35)); align-items: flex-end; padding-bottom: calc(60px + var(--sab)); }
.title-box { text-align: center; color: #fff; text-shadow: 0 3px 12px rgba(0,0,0,0.45); }
h1.big { font-size: clamp(44px, 8vw, 84px); margin: 0; letter-spacing: 1px; }
.sub { font-size: 22px; margin: 8px 0 24px; }
.title-buttons { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.hint { font-size: 15px; opacity: 0.9; max-width: 520px; margin: 18px auto 0; }

/* Välj dinosaurie */
#select { justify-content: flex-end; align-items: center; padding-right: calc(24px + var(--sar)); pointer-events: none; }
#select > * { pointer-events: auto; }
.select-card {
  width: min(400px, 46vw); background: var(--panel); border-radius: 26px; padding: 22px 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.sel-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.select-card h2 { margin: 0; font-size: 30px; }
#sel-blurb { font-size: 18px; margin: 8px 0 12px; color: var(--ink-soft); }
.sel-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 18px; }
.lbl { font-weight: 700; min-width: 70px; color: var(--ink-soft); font-size: 15px; text-transform: uppercase; letter-spacing: 0.5px; }
.sel-pick-label { font-weight: 800; font-size: 14px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.strip button {
  position: relative; padding: 0; border: 3px solid transparent; border-radius: 14px; background: #e6ecd8;
  aspect-ratio: 1; overflow: hidden; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
.strip button img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scale(1.35); }
.strip button.on { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(240,160,48,0.35); }
.strip button.locked img { filter: grayscale(1) brightness(0.8) blur(1.5px); opacity: 0.55; }
.strip button.locked::after { content: '🔒'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
#swipe-hint {
  position: fixed; left: calc(30px + var(--sal)); top: calc(24px + var(--sat)); background: rgba(255,250,238,0.9); padding: 10px 16px;
  border-radius: 16px; font-weight: 700; font-size: 17px; box-shadow: 0 4px 12px rgba(0,0,0,0.18); pointer-events: none;
}
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.25); cursor: pointer; position: relative; }
.swatch.on { outline: 4px solid var(--orange); }
.swatch.locked { opacity: 0.4; }
.swatch.locked::after { content: '🔒'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; }
#sel-dname { flex: 1; font-family: var(--font); font-size: 20px; padding: 8px 12px; border-radius: 12px; border: 2px solid #d8ccb0; background: #fff; color: var(--ink); min-width: 0; user-select: text; -webkit-user-select: text; }
.lock { background: #fde8c8; border-radius: 14px; padding: 12px; font-size: 18px; margin-top: 10px; font-weight: 700; }
.arrow {
  position: fixed; top: 50%; transform: translateY(-50%); width: 96px; height: 96px; border-radius: 50%; border: 4px solid #fff;
  background: var(--orange); color: #fff; font-size: 64px; font-weight: 800; line-height: 1; padding-bottom: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25); z-index: 21; cursor: pointer;
}
.arrow:active { transform: translateY(-50%) scale(0.92); }
.arrow.left { left: calc(24px + var(--sal)); }
.arrow.right { left: calc(100vw - min(400px, 46vw) - 24px - 96px - 24px - var(--sar)); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .panel { pointer-events: auto; }
.panel { background: var(--panel); border-radius: 20px; box-shadow: 0 4px 14px rgba(0,0,0,0.18); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#player-card { position: absolute; top: calc(14px + var(--sat)); left: calc(14px + var(--sal)); padding: 12px 16px; width: 260px; }
.pc-row { display: flex; align-items: center; gap: 12px; }
.level-badge {
  width: 52px; height: 52px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd86a, #f09a20);
  color: #fff; font-size: 26px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  text-shadow: 0 2px 2px rgba(0,0,0,0.25); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15); flex: none;
}
.level-badge.pop { animation: pop 0.6s; }
@keyframes pop { 40% { transform: scale(1.35); } }
.pc-info { flex: 1; min-width: 0; }
#pc-name { font-weight: 800; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xpbar, .nbar { height: 12px; border-radius: 8px; background: rgba(0,0,0,0.1); overflow: hidden; margin-top: 4px; }
#xp-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd34a, #f39a1e); border-radius: 8px; transition: width 0.4s; }
.needs { display: flex; gap: 12px; margin-top: 10px; }
.need { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 18px; }
.need .nbar { flex: 1; margin: 0; }
#need-food { height: 100%; background: #6cbf4a; border-radius: 8px; transition: width 0.3s; }
#need-water { height: 100%; background: #4aaee0; border-radius: 8px; transition: width 0.3s; }
#quest { position: absolute; top: calc(160px + var(--sat)); left: calc(14px + var(--sal)); padding: 10px 14px; max-width: 300px; font-size: 16px; font-weight: 700; display: flex; gap: 8px; align-items: center; }
#quest.done { animation: pop 0.6s; background: #fff2b8; }
#quest-prog { color: var(--ink-soft); white-space: nowrap; }

#top-right { position: absolute; top: calc(14px + var(--sat)); right: calc(14px + var(--sar)); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
#minimap { width: 150px; height: 150px; border-radius: 50%; border: 5px solid rgba(255,250,238,0.9); box-shadow: 0 4px 14px rgba(0,0,0,0.25); background: #6a8a4a; }
.tr-buttons { display: flex; gap: 10px; }

#joy-base {
  position: absolute; width: 150px; height: 150px; border-radius: 50%; left: calc(40px + var(--sal)); bottom: calc(40px + var(--sab));
  background: rgba(255,255,255,0.18); border: 3px solid rgba(255,255,255,0.45); transform: translate(0,0); opacity: 0.6;
}
#joy-base.active { opacity: 1; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%;
  background: rgba(255,250,238,0.92); box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

#actions {
  position: absolute; right: calc(24px + var(--sar)); bottom: calc(28px + var(--sab));
  display: grid; grid-template-columns: repeat(3, auto); grid-auto-flow: dense; gap: 12px; align-items: end; justify-items: center; direction: rtl;
}
.act {
  direction: ltr; width: 84px; height: 84px; border-radius: 50%; border: none; background: rgba(255,250,238,0.92);
  box-shadow: 0 5px 0 rgba(0,0,0,0.2), 0 6px 14px rgba(0,0,0,0.18); display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.1s, opacity 0.2s, filter 0.2s;
}
.act .ic { font-size: 32px; line-height: 1; }
.act .tx { font-size: 13px; font-weight: 800; margin-top: 2px; }
.act.big { width: 116px; height: 116px; grid-row: span 2; }
.act.big .ic { font-size: 46px; }
.act.big .tx { font-size: 17px; }
.act.small { width: 64px; height: 64px; }
.act.small .ic { font-size: 26px; }
.act:active, .act.pressed { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.2); }
.act.off { opacity: 0.45; filter: grayscale(0.8); }
.act.glow { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 5px 0 rgba(0,0,0,0.2), 0 0 0 8px rgba(255,214,80,0.55); } }
.act.toggled { background: #ffe08a; }
#fly-ud { display: flex; flex-direction: column; gap: 10px; direction: ltr; }
#act-hint { position: absolute; right: calc(28px + var(--sar)); bottom: calc(260px + var(--sab)); background: var(--panel); padding: 8px 14px; border-radius: 14px; font-weight: 700; font-size: 16px; opacity: 0; transition: opacity 0.3s; max-width: 280px; text-align: center; }
#act-hint.show { opacity: 1; }

#thought {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%); background: #fff; border-radius: 30px; padding: 10px 18px; font-size: 30px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2); animation: bob 2s ease-in-out infinite;
}
#thought::after { content: ''; position: absolute; left: 50%; bottom: -16px; width: 16px; height: 16px; border-radius: 50%; background: #fff; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.nlabel {
  position: absolute; transform: translate(-50%, -100%); background: rgba(255,250,238,0.9); border-radius: 12px; padding: 3px 10px; font-weight: 800; font-size: 15px;
  white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,0.2); text-align: center; will-change: transform;
}
.nlabel .hearts { font-size: 12px; letter-spacing: 1px; display: block; color: var(--pink); }
.nlabel.friend { background: #ffe3ec; }

#toasts { position: fixed; left: 50%; top: calc(16px + var(--sat)); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--panel); padding: 10px 18px; border-radius: 16px; font-weight: 800; font-size: 18px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); animation: toast 2.6s forwards; white-space: nowrap; }
.toast .xp { color: #e08a10; margin-left: 6px; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }

#banner { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 31; text-align: center; color: #fff; text-shadow: 0 3px 14px rgba(0,0,0,0.5); pointer-events: none; animation: banner 3.6s forwards; }
#banner .b-icon { font-size: 64px; }
#banner .b-title { font-size: 46px; font-weight: 800; }
#banner .b-sub { font-size: 22px; font-weight: 700; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 20px) scale(0.9); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

.modal { position: fixed; inset: 0; background: rgba(20, 30, 20, 0.45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: #fffaf0; border-radius: 28px; padding: 26px 30px; max-width: 560px; width: 100%; text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,0.3); max-height: 92vh; overflow: auto; }
.modal-box h2 { font-size: 34px; margin: 4px 0 12px; }
.lv-stars { font-size: 34px; animation: bob 1.2s infinite; }
#lv-list { list-style: none; padding: 0; margin: 10px 0 20px; text-align: left; }
#lv-list li { background: #fff2d0; border-radius: 14px; padding: 12px 16px; margin: 8px 0; font-size: 20px; font-weight: 700; display: flex; gap: 12px; align-items: center; }
#lv-list li .i { font-size: 30px; }
.menu-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
#help { text-align: left; font-size: 17px; background: #f4efe0; border-radius: 16px; padding: 6px 16px; margin-bottom: 16px; }

.book-box { max-width: 860px; text-align: left; }
.book-head { display: flex; justify-content: space-between; align-items: center; }
#book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.bcard { background: #f4ecd8; border-radius: 18px; padding: 10px; text-align: center; cursor: pointer; border: none; font-family: var(--font); }
.bcard img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: #dfe9d0; display: block; }
.bcard .bn { font-weight: 800; font-size: 17px; margin-top: 6px; }
.bcard.locked img { filter: blur(7px) grayscale(1) opacity(0.5); }
.bcard.locked .bn { color: #9a9282; }
#book-detail { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
#book-detail img { width: 240px; border-radius: 18px; background: #dfe9d0; }
#book-detail .bd-text { flex: 1; min-width: 240px; font-size: 18px; }
#book-detail h3 { font-size: 30px; margin: 0 0 8px; }
#book-detail .fact { background: #fff2d0; border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
#book-detail dl { margin: 0; }
#book-detail dt { font-weight: 800; color: var(--ink-soft); font-size: 14px; text-transform: uppercase; margin-top: 8px; }
#book-detail dd { margin: 2px 0 0; }

#rotate-hint { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 8px 16px; border-radius: 14px; z-index: 50; font-weight: 700; }

@media (max-width: 900px) {
  .select-card { width: min(380px, 92vw); }
  #select { justify-content: center; align-items: flex-end; padding: 0 0 calc(16px + var(--sab)); }
  .arrow { top: 30%; bottom: auto; }
  .arrow.right { left: auto; right: calc(20px + var(--sar)); }
}
@media (max-height: 700px) {
  .act { width: 70px; height: 70px; }
  .act.big { width: 96px; height: 96px; }
  #minimap { width: 120px; height: 120px; }
  #quest { top: calc(150px + var(--sat)); }
}
