/* The app's shell and the main screens: the frame, the top bar, the tab bar, the map, the lesson page, the diary, the museum, the profile.
   The lesson player and its steps are in quest.css. Tokens (colours, sizes) are in tokens.css. */

/* The shell is as tall as the VISIBLE area (--app-h) and starts where it starts (--app-top). js/viewport.js writes both from innerHeight and
   visualViewport, not from Telegram's --tg-viewport-height: on iOS the keyboard shrinks the window or overlays it, and this follows either. */
body { background: var(--bg); }
#app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100%); display: flex; flex-direction: column;
  background: radial-gradient(130% 60% at 50% 0%, var(--bg-glow), var(--bg) 70%); }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
/* A screen arriving. animation-fill-mode is "backwards" on purpose: a finished animation of transform kept by "forwards"/"both" would stay the containing
   block of position: fixed children (verified in Chrome and WebKit). */
.screen.push { animation: push var(--d3) var(--ease) backwards; }
.screen.fade { animation: fade var(--d2) var(--ease) backwards; }
@keyframes push { from { opacity: 0; transform: translateX(28px); } }
@keyframes fade { from { opacity: 0; } }

.scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.page { width: 100%; max-width: var(--column); margin: 0 auto; display: grid; gap: var(--s4); align-content: start;
  padding: var(--s3) calc(var(--sar) + var(--s4)) calc(var(--s7) + var(--s4)) calc(var(--sal) + var(--s4)); }

/* ---- top bar */
.bar { flex: none; display: flex; align-items: center; gap: var(--s3); min-height: calc(var(--bar-h) + var(--sat)); padding: var(--sat) calc(var(--sar) + var(--s4)) var(--s2) calc(var(--sal) + var(--s4)); }
.bar.has-back { padding-left: calc(var(--sal) + var(--s3)); }
.bar-title { min-width: 0; flex: 1; display: grid; gap: 2px; padding-top: var(--s2); }
.bar h1 { margin: 0; font: 700 var(--t-large)/1.05 var(--f-title); color: var(--text); overflow-wrap: anywhere; }
.kicker { display: inline-flex; align-items: center; gap: 6px; font: 700 12px/1.2 var(--f-cap); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.kicker svg { flex: none; }
.section-title { display: flex; align-items: center; gap: var(--s2); margin: var(--s3) 0 0; font: 700 22px/1.1 var(--f-title); color: var(--text); }
.section-title svg { color: var(--accent); }
.muted { color: var(--muted); }
.hand { font-family: var(--f-hand); font-weight: 600; color: var(--text); }
.small-note { font-size: var(--t-meta); }

/* ---- tab bar */
.tabbar { flex: none; display: flex; height: calc(var(--tab-h) + var(--sab)); padding: 0 var(--sar) var(--sab) var(--sal); z-index: 20;
  background: linear-gradient(180deg, var(--card-a), var(--card-b)); border-top: 2px solid var(--gold); box-shadow: 0 -8px 20px rgba(0, 0, 0, .18); }
.tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 700 12px/1 var(--f-body); color: var(--muted); }
.tab.is-on { color: var(--accent); }
.tab.is-on::after { content: ""; position: absolute; top: -2px; left: 26%; right: 26%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab.is-on svg { animation: tab-up .45s both; }
@keyframes tab-up { 0% { transform: translateY(5px); } 60% { transform: translateY(-3px); } 100% { transform: none; } }

/* ---- splash */
.splash { background: radial-gradient(120% 80% at 50% 0%, #1A4766, #0E2538 70%); }
.splash-card { display: grid; justify-items: center; gap: var(--s3); }
.splash-mark { width: 84px; height: 84px; border-radius: 26px; display: grid; place-items: center; color: #F3D57E; border: 2px solid #E7BC5D; background: linear-gradient(180deg, #17415F, #0F3047); animation: pulse 1.6s var(--ease) infinite; }
.splash-name { font: 700 34px/1 var(--f-title); letter-spacing: .12em; color: #F3D57E; }

/* ---- gates */
.gate .mark { background: var(--accent-soft); color: var(--accent); }

/* ---- list rows and notices */
.notice { display: grid; justify-items: center; gap: var(--s3); text-align: center; padding: var(--s7) var(--s4); }
.notice h2 { font: 700 24px/1.15 var(--f-title); }
.notice p { color: var(--muted); max-width: 340px; overflow-wrap: anywhere; }
.skeleton-list { display: grid; gap: var(--s3); }
.skel-card { height: 96px; border-radius: var(--r-l); }
.rows { display: grid; gap: var(--s2); }
.row-link { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 56px; padding: var(--s3) var(--s4); text-align: left; border-radius: var(--r-l);
  background: var(--surface); border: 1.5px solid var(--line); color: var(--text); transition: transform var(--d1) var(--ease); }
.row-link:active { transform: scale(.985); }
.row-link svg { color: var(--accent); }
.row-link > svg:last-child { margin-left: auto; color: var(--muted); }
.rl-txt { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---- map */
.map-hero { position: relative; height: 290px; overflow: hidden; background: #143e58; }
.map-hero.skeleton { height: 290px; border-radius: 0; }
.map-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 46% 36%; transform: scale(1.5); transform-origin: 46% 36%; }
.map-hero::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(6, 26, 40, .5) 0%, transparent 28%, transparent 62%, var(--bg) 100%); }
.map-top { position: absolute; z-index: 2; left: calc(var(--sal) + var(--s4)); right: calc(var(--sar) + var(--s4)); top: calc(var(--sat) + var(--s3)); display: flex; gap: var(--s2); justify-content: flex-end; }
.map-pin { position: absolute; z-index: 2; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; justify-items: center; gap: 2px; }
.map-chibi { height: 118px; width: auto; filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .5)); animation: bob 3.4s ease-in-out infinite; }
.map-label { padding: 3px 12px; border-radius: 6px; background: linear-gradient(180deg, #F8E9C6, #E6CB94); border: 1.5px solid #b88a3a; font: 700 14px/1.1 var(--f-title); color: #4a3114; box-shadow: 0 2px 0 rgba(70, 40, 5, .5); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.map-body .page { margin-top: -26px; position: relative; z-index: 3; }
.today-head { display: flex; align-items: center; gap: var(--s3); cursor: pointer; }
.today-thumb { width: 74px; height: 74px; flex: none; object-fit: cover; border-radius: 12px; border: 2px solid var(--gold); }
.today-txt { flex: 1; min-width: 0; display: grid; gap: 3px; }
.card-title { margin: 0; font: 700 28px/1.05 var(--f-title); color: var(--text); overflow-wrap: anywhere; }
.go { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; color: #F3D57E; background: linear-gradient(180deg, #123F59, #0A2A3F); border: 2px solid #E7BC5D; box-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.meter { height: 9px; margin: var(--s3) 0; border-radius: 6px; background: rgba(80, 50, 15, .22); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #1F7C8C, #4FB3C0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4); transition: width var(--d3) var(--ease); }
.durations { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); margin: 0 0 var(--s3); }
.dur { flex-direction: column; gap: 1px; padding: 8px 0; justify-content: center; }
.dur b { font: 700 22px/1 var(--f-body); }
.dur span { font-size: 12px; opacity: .85; }
.today .btn-big { margin-top: 2px; }
.today .btn-parch { width: 100%; margin-top: var(--s2); }
.soon { display: flex; align-items: center; justify-content: center; gap: var(--s2); padding: var(--s3); border-radius: var(--r-m); background: var(--surface-2); color: var(--muted); font-weight: 600; }
.due { width: 100%; text-align: left; display: block; }
.due-in { display: flex !important; align-items: center; gap: var(--s3); padding-top: 12px; padding-bottom: 12px; }
.due-ic { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-contrast); }
.due-txt { flex: 1; display: grid; gap: 2px; }
.due-txt b { font: 700 20px/1.1 var(--f-title); }
.due-txt span { color: var(--muted); font-size: var(--t-sm); }
.cases { display: grid; gap: var(--s2); }
.case { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 68px; padding: var(--s3) var(--s4); text-align: left; border-radius: var(--r-l); background: var(--surface); border: 1.5px solid var(--border); color: var(--text); }
.case.locked { opacity: .72; border-style: dashed; }
.case-n { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; font: 700 20px/1 var(--f-title); background: var(--accent); color: var(--accent-contrast); }
.case.locked .case-n { background: var(--surface-2); color: var(--muted); }
.case-txt { flex: 1; min-width: 0; display: grid; gap: 1px; }
.case-town { font: 700 12px/1.2 var(--f-cap); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.case-title { font: 700 20px/1.1 var(--f-title); overflow-wrap: anywhere; }
.case-count { font-size: var(--t-meta); color: var(--muted); }
.case-soon { font-size: var(--t-meta); font-weight: 700; color: var(--muted); }
.case > svg { color: var(--muted); }

/* ---- case page, lessons list */
.lessons { display: grid; gap: var(--s2); }
.lesson-row { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 72px; padding: var(--s3) var(--s4); text-align: left; border-radius: var(--r-l); background: var(--surface); border: 1.5px solid var(--border); color: var(--text); }
.lesson-row.locked { opacity: .7; border-style: dashed; }
.lesson-row.done { border-color: var(--ok); }
.lr-n { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; font: 700 19px/1 var(--f-title); background: var(--accent); color: var(--accent-contrast); }
.lesson-row.done .lr-n { background: var(--ok); color: var(--ok-contrast); }
.lesson-row.locked .lr-n { background: var(--surface-2); color: var(--muted); }
.lr-txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.lr-title { font-size: 22px; font-weight: 700; }
.lr-goal { color: var(--muted); font-size: var(--t-sm); }

/* ---- lesson page (hub) */
.hub-hero { position: relative; height: 220px; overflow: hidden; margin-bottom: -70px; flex: none; }
.hub-hero img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
.hub-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, .22) 0%, transparent 34%, transparent 62%, var(--bg) 100%); }
.hub-back { position: absolute; z-index: 2; left: calc(var(--sal) + var(--s3)); top: calc(var(--sat) + var(--s3)); }
.hub-page { position: relative; z-index: 2; padding-top: 0; }
.hub-title { font-size: 40px; }
.hub-tagline { font-size: 28px; line-height: 1.1; margin: var(--s1) 0 var(--s2); }
.done-note { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-m); background: var(--ok-soft); color: var(--text); font-weight: 600; }
.done-note svg { color: var(--ok); }
.len-grid { display: grid; gap: var(--s2); }
.len-card { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 2px var(--s3); text-align: left; padding: var(--s3) var(--s4); border-radius: var(--r-l); background: var(--surface); border: 2px solid var(--border); color: var(--text); }
.len-card.is-on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 3px 0 var(--burg-2); }
.len-min { grid-row: 1 / span 2; display: grid; justify-items: center; line-height: 1; }
.len-min b { font: 700 32px/1 var(--f-title); color: var(--accent); }
.len-min span { font-size: 12px; color: var(--muted); }
.len-blocks { font-size: var(--t-sm); font-weight: 500; }
.len-steps { font-size: var(--t-meta); }
.cons-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.cons-list li { font-size: var(--t-sm); }
.cons-list .it { font-size: 20px; }
.hub-actions { display: grid; gap: var(--s2); margin-top: var(--s2); }
.hub-actions .btn-parch { width: 100%; }

/* ---- diary, words */
.wlist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.wrow { display: flex; align-items: center; gap: var(--s3); width: 100%; padding: var(--s2) var(--s3); text-align: left; border-radius: var(--r-l); background: var(--surface); border: 1.5px solid var(--line); color: var(--text); }
.wrow img, .wph { width: 56px; height: 56px; flex: none; border-radius: 10px; object-fit: cover; border: 1.5px solid var(--gold); background: var(--surface-2); display: grid; place-items: center; color: var(--accent); }
.wtxt { flex: 1; min-width: 0; display: grid; gap: 1px; }
.wit { font-size: 22px; font-weight: 700; }
.wtr { font-size: var(--t-meta); color: var(--muted); }
.wru { font-size: var(--t-sm); }
.stress { color: var(--accent); font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.strength { display: flex; gap: 3px; flex: none; }
.strength i { width: 7px; height: 14px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); }
.strength i.on { background: var(--ok); border-color: var(--ok); }

/* ---- museum */
.clue-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.clue-card { margin: 0; border-radius: var(--r-l); overflow: hidden; background: var(--surface); border: 2px solid var(--gold); box-shadow: var(--shadow); }
.clue-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.clue-card figcaption { padding: var(--s2) var(--s3); font: 700 17px/1.15 var(--f-title); }
.ex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.ex-card { position: relative; border-radius: var(--r-m); overflow: hidden; border: 1.5px solid var(--border); background: var(--surface-2); aspect-ratio: 1; }
.ex-card img { width: 100%; height: 100%; object-fit: cover; display: block; filter: grayscale(1) brightness(.62) contrast(.9); }
.ex-lock { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(14, 37, 56, .85); color: #F3D57E; }
.ex-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px; text-align: center; font: 700 12px/1 var(--f-body); color: #FFF3D6; background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .75)); }
.people { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.person { margin: 0; display: grid; gap: var(--s2); justify-items: center; text-align: center; padding: var(--s3); border-radius: var(--r-l); background: var(--surface); border: 1.5px solid var(--border); }
.person img { height: 150px; width: auto; border-radius: 12px; }
.person b { display: block; font: 700 20px/1.1 var(--f-title); }
.person span { font-size: var(--t-meta); color: var(--muted); }

/* ---- profile */
.hero-card { position: relative; height: 270px; flex: none; overflow: hidden; }
.hero-card img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.hero-card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, .2) 0%, transparent 40%, var(--bg) 100%); }
.hero-name { position: absolute; z-index: 2; left: calc(var(--sal) + var(--s4)); right: var(--s4); bottom: var(--s4); display: grid; gap: 2px; }
.hero-title { font: 700 46px/1 var(--f-title); font-style: italic; color: #FFF3D6; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); }
.hero-sub { font: 600 22px/1.1 var(--f-hand); color: #F3D57E; text-shadow: 0 1px 4px rgba(0, 0, 0, .7); }
.profile .bar { min-height: auto; padding-top: var(--s2); }
.profile .bar h1 { font-size: 24px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin: var(--s3) 0; }
.stats.four { grid-template-columns: repeat(4, 1fr); margin: 0; }
.stat { display: grid; justify-items: center; gap: 2px; padding: var(--s3) var(--s1); border-radius: var(--r-m); background: var(--surface); border: 1.5px solid var(--line); text-align: center; }
.stat svg { color: var(--accent); }
.stat b { font: 700 24px/1 var(--f-title); }
.stat span { font-size: var(--t-meta); color: var(--muted); }
.paper-in .set-label, .set-label { margin: var(--s3) 0 var(--s2); font-size: var(--t-meta); font-weight: 700; color: var(--muted); }
.paper-in .set-label:first-child { margin-top: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); }
.seg button { min-height: 44px; border-radius: 10px; font-size: var(--t-sm); font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 2px 0 var(--burg-3); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s3) 0; border-top: 1px solid var(--line); }
.paper-in .switch-row:first-of-type { border-top: 0; }
.sw-label { font-weight: 700; }
.sw-hint { font-size: var(--t-meta); }
.switch { position: relative; width: 56px; height: 32px; flex: none; border-radius: 16px; background: var(--surface-2); border: 2px solid var(--border); transition: background var(--d2); }
.switch i { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: transform var(--d2) var(--ease), background var(--d2); }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(24px); background: var(--accent-contrast); }
.kv { display: grid; gap: var(--s2); margin: 0; font-size: var(--t-sm); }
.kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); }
.kv dt { color: var(--muted); flex: none; }
.kv dd { margin: 0; min-width: 0; text-align: right; overflow-wrap: anywhere; }
.kv code { font-family: var(--mono); font-size: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.btn-danger { color: var(--danger); background: var(--danger-soft); border: 2px solid var(--danger); justify-self: start; }
.reset { width: 100%; }
