/* main.css — title, intro, PIN, onboarding, shell */
:root { --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); }

/* ---------- title ---------- */
#title-screen { z-index: 20; background: #2a1840 url(../assets/cover-bg.webp) center / cover no-repeat; overflow: hidden; cursor: pointer; }
.title-logo {
  position: absolute; left: 50%; top: calc(6% + var(--sat)); width: 82%; max-height: 30%; object-fit: contain; transform: translateX(-50%);
  image-rendering: auto; filter: drop-shadow(0 6px 10px rgba(60,20,80,.5));
  animation: logo-drop .9s cubic-bezier(.2, 1.6, .4, 1) both, logo-float 3.2s ease-in-out .9s infinite;
}
@keyframes logo-drop { 0% { transform: translate(-50%, -140%) scale(.7); opacity: 0; } 100% { transform: translate(-50%, 0) scale(1); opacity: 1; } }
@keyframes logo-float { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -8px); } }
.tstar, .ob-star {
  position: absolute; width: 8px; height: 8px; background: #fff7c8; pointer-events: none;
  clip-path: polygon(40% 0, 60% 0, 60% 40%, 100% 40%, 100% 60%, 60% 60%, 60% 100%, 40% 100%, 40% 60%, 0 60%, 0 40%, 40% 40%);
  animation: twinkle 2.2s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
.title-prompt {
  position: absolute; left: 10%; right: 10%; bottom: calc(12% + var(--sab)); text-align: center; font-size: 22px; font-weight: 900;
  animation: pulse 1.6s ease-in-out infinite; padding: 0 8px;
}

/* ---------- intro ---------- */
#intro { position: absolute; inset: 0; z-index: 90; background: #000 url(../assets/cover-bg.webp) center / cover no-repeat; }
#intro video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; background: transparent; }
#intro video.show { opacity: 1; }
.intro-skip { position: absolute !important; left: 50%; bottom: calc(32px + var(--sab)); transform: translateX(-50%); }
.intro-skip:hover { transform: translateX(-50%) scale(1.05); }

/* ---------- shake ---------- */
.shake { animation: shake .4s both; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

/* ---------- PIN ---------- */
.pin-overlay {
  position: absolute; inset: 0; z-index: 85; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(180deg, var(--bg1), var(--bg2)); animation: fade-in .25s both;
}
.pin-overlay.out { animation: fade-out .22s both; }
.pin-overlay h2 { margin: 0; font-size: 24px; }
.pin-dots { display: flex; gap: 16px; }
.pin-dots i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; transition: transform .15s cubic-bezier(.3,1.8,.5,1), background .15s; }
.pin-dots i.on { background: var(--accent); transform: scale(1.2); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; }
.pin-key {
  all: unset; box-sizing: border-box; cursor: pointer; height: 60px; border-radius: 16px; text-align: center; line-height: 54px;
  background: linear-gradient(180deg, #fff, var(--bg2)); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
  font-size: 24px; font-weight: 900; color: var(--ink); font-family: var(--font); transition: transform .1s cubic-bezier(.3,1.6,.5,1);
}
.pin-key:active { transform: translateY(3px) scale(.95); box-shadow: 0 1px 0 var(--ink); }
.pin-key:focus-visible, .pin-key.focus { outline: 3px solid var(--accent); box-shadow: 0 4px 0 var(--ink), 0 0 12px var(--accent); }

/* ---------- onboarding ---------- */
.ob-overlay {
  position: absolute; inset: 0; z-index: 60; overflow: hidden; display: flex; flex-direction: column; align-items: center;
  background: linear-gradient(180deg, var(--bg1), var(--bg2)); padding: calc(24px + var(--sat)) 16px calc(24px + var(--sab));
  animation: fade-in .25s both; transition: background .4s;
}
.ob-overlay.out { animation: fade-out .26s both; }
.ob-star { background: #fff; width: 10px; height: 10px; animation: twinkle 3s ease-in-out infinite, drift 8s linear infinite; }
@keyframes drift { from { translate: 0 0; } to { translate: 20px -30px; } }
.ob-dots { display: flex; gap: 8px; position: relative; z-index: 1; margin-bottom: 8px; }
.ob-dot { font-size: 24px; color: #fff; text-shadow: -1px -1px 0 var(--ink), 1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); opacity: .45; transition: transform .25s cubic-bezier(.3,1.8,.5,1), opacity .2s, color .2s; }
.ob-dot.on { opacity: 1; color: var(--gold); transform: scale(1.2); }
.ob-stage { position: relative; z-index: 1; flex: 1; width: 100%; max-width: 380px; display: flex; align-items: center; min-height: 0; }
.ob-card { width: 100%; max-height: 100%; overflow-y: auto; margin: 0; padding: 8px 8px; animation: slide-in .4s cubic-bezier(.2, 1.3, .4, 1) both; text-align: center; }
@keyframes slide-in { from { transform: translateX(80px); opacity: 0; } to { transform: none; opacity: 1; } }
.ob-title { font-size: 22px; margin: 6px 0 10px; font-weight: 900; }
.ob-text { font-size: 15px; line-height: 1.6; margin: 6px 4px 10px; color: var(--ink); }
.ob-duo { display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.ob-nav { display: flex; gap: 10px; justify-content: center; margin: 10px 0 4px; }
.ob-nav .pbtn { min-width: 112px; }
.ob-card .pfield { text-align: left; }
.ob-genders { display: flex; gap: 8px; margin: 8px 0; }
.ob-gender {
  all: unset; box-sizing: border-box; cursor: pointer; flex: 1; min-height: 110px; border-radius: 16px; background: #fff; border: 3px solid var(--line);
  box-shadow: 0 4px 0 var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 900; color: var(--ink); font-family: var(--font); transition: transform .18s cubic-bezier(.3,1.7,.5,1), box-shadow .18s;
}
.ob-gender b { font-size: 34px; color: var(--accent); }
.ob-gender.on { border-color: var(--ink); background: linear-gradient(180deg, #fff, var(--bg1)); transform: translateY(-4px) scale(1.04); box-shadow: 0 4px 0 var(--ink), 0 0 16px var(--accent); }
.ob-gender:focus-visible { outline: 3px solid var(--accent); }
.ob-chars { display: flex; gap: 8px; margin: 6px 0; }
.ob-char {
  all: unset; box-sizing: border-box; cursor: pointer; flex: 1; min-width: 0; border-radius: 16px; background: #fff; border: 3px solid var(--line);
  box-shadow: 0 4px 0 var(--line); padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink);
  font-family: var(--font); transition: transform .2s cubic-bezier(.3,1.7,.5,1), box-shadow .2s;
}
.ob-char canvas { max-width: 100%; height: auto; }
.ob-char b { font-size: 16px; font-weight: 900; }
.ob-char small { font-size: 13px; line-height: 1.35; font-weight: 700; color: var(--ink-soft); padding: 0 4px; }
.ob-char.on { border-color: var(--ink); transform: translateY(-4px) scale(1.03); background: linear-gradient(180deg, #fff, var(--bg1)); box-shadow: 0 4px 0 var(--ink), 0 0 18px 3px var(--accent); }
.ob-char:focus-visible { outline: 3px solid var(--accent); }
.ob-avatar { display: flex; justify-content: center; margin: 4px 0; }
.set-row { margin: 0 0 12px; min-height: 44px; }
.set-row .plabel { font-size: 14px; font-weight: 900; }
.set-danger { border-top: 2px dashed var(--line); padding-top: 10px; }

/* level-up modal */
.lu-body { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.lu-lv { font-size: 40px; font-weight: 900; animation: pop-in .5s cubic-bezier(.2,1.8,.4,1) both; }
.lu-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lu-item { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 80px; font-size: 13px; text-align: center; color: var(--ink); background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 6px 4px; }
.lu-item img { width: 44px; height: 44px; object-fit: contain; }

/* ---------- shell ---------- */
#main-layer { z-index: 10; }
#bg-layer { position: absolute; inset: 0; background: var(--bg1) center / cover no-repeat; transition: background-image .3s; }
#bg-layer::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,.75), rgba(255,255,255,.35) 40%, rgba(255,255,255,.55)); }
#topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5; height: calc(56px + var(--sat)); padding: var(--sat) 64px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.lv-badge { flex: none; width: 76px; padding: 3px 8px 5px; border-radius: 14px; background: linear-gradient(180deg, #fff, var(--bg1)); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.lv-text { display: block; font-size: 16px; font-weight: 900; line-height: 18px; color: var(--ink); text-align: center; }
.lv-badge .xpbar { height: 8px; margin-top: 2px; border-width: 2px; }
.tb-title { flex: 1; min-width: 0; font-size: 20px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gold-pill {
  all: unset; box-sizing: border-box; cursor: pointer; flex: none; min-height: 44px; display: inline-flex; align-items: center; gap: 4px; padding: 0 6px;
  font-family: var(--font); font-size: 16px; font-weight: 900; color: #fff;
  text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 2px 0 var(--ink);
  transition: transform .15s cubic-bezier(.3,1.7,.5,1);
}
.gold-pill img { width: 22px; height: 22px; image-rendering: pixelated; }
.gold-pill:active { transform: scale(.92); }
#view {
  position: absolute; left: 0; right: 0; top: calc(56px + var(--sat)); bottom: 0; z-index: 2; overflow-y: auto; overflow-x: hidden;
  padding: 12px 12px calc(90px + var(--sab)); -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
#view::-webkit-scrollbar { display: none; }
#nav {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; height: calc(68px + var(--sab)); padding: 0 6px var(--sab);
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; align-items: end;
  background: linear-gradient(180deg, rgba(255,255,255,.88), var(--bg2)); border-top: 3px solid var(--ink); box-shadow: 0 -4px 12px rgba(90,46,94,.2);
}
.tab {
  all: unset; box-sizing: border-box; cursor: pointer; height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 16px; transition: transform .25s cubic-bezier(.3,1.8,.5,1), background .2s;
}
.tab img { width: 36px; height: 36px; filter: grayscale(.35) opacity(.8); transition: filter .2s; }
.tab-label { font-size: 12px; font-weight: 900; color: #fff; white-space: nowrap; text-shadow: -1.5px -1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px 1.5px 0 var(--ink); }
.tab.on { transform: translateY(-8px); background: radial-gradient(circle at 50% 40%, #fff, rgba(255,255,255,0) 75%); box-shadow: 0 0 14px 2px var(--accent); }
.tab.on img { filter: drop-shadow(0 0 6px var(--accent)); }
.tab.bounce { animation: tab-bounce .4s cubic-bezier(.3,1.8,.5,1); }
@keyframes tab-bounce { 0% { scale: 1; } 40% { scale: 1.18 .85; } 70% { scale: .95 1.1; } 100% { scale: 1; } }
.tab:focus-visible { outline: none; }

/* gamepad / keyboard focus ring */
.focus { outline: 3px solid var(--accent) !important; outline-offset: 2px; box-shadow: 0 0 12px 3px var(--accent); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tab.focus, .tab:focus-visible { outline: 3px solid var(--accent); }
