/* Trick or Fright: phones and tablets.
   1. the on-screen touch controls (#touch, built by js/touch.js)
   2. HUD placement while touch controls are on (html.touch)
   3. menu layouts for landscape phones and tablets (portrait just shows the rotate screen) (media queries, so a small
      desktop window gets them too)
   4. 44 px tap targets, safe areas, no text selection or callouts. */

:root {
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}
html.touch, html.touch body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.touch img, html.touch svg { -webkit-user-drag: none; pointer-events: none; }
html.touch #ui button, html.touch #ui input[type=range] { touch-action: manipulation; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 20; pointer-events: none; display: none; touch-action: none; --b1: clamp(78px, 19vmin, 108px); --b2: clamp(60px, 14.5vmin, 82px); --b3: clamp(54px, 12.5vmin, 70px); --pc: #ff7a18; }
html.touch #touch { display: block; }
#touch .tt-zone { position: absolute; inset: 0; pointer-events: none; touch-action: none; }
#touch.on .tt-zone { pointer-events: auto; }
#touch .tt-btn {
  position: absolute; display: grid; place-items: center; align-content: center; padding: 0; margin: 0; border-radius: 50%;
  color: var(--bone); font-family: var(--f-vhs); text-align: center; line-height: 1; cursor: pointer;
  background: radial-gradient(circle at 50% 38%, rgba(30,34,48,.62), rgba(5,7,13,.7));
  border: 2px solid rgba(232,224,204,.34); box-shadow: 0 6px 18px rgba(0,0,0,.55), inset 0 0 14px rgba(0,0,0,.45);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  visibility: hidden; pointer-events: none; touch-action: none; -webkit-tap-highlight-color: transparent;
  transition: transform .08s, background .15s, border-color .15s, box-shadow .2s;
}
#touch.on .tt-btn { visibility: visible; pointer-events: auto; }
#touch .tt-btn[hidden] { display: none; }
#touch .tt-btn .tt-ico { display: grid; place-items: center; }
#touch .tt-btn svg { width: 100%; height: 100%; display: block; }
#touch .tt-btn small { font-size: clamp(14px, 3.8vmin, 20px); letter-spacing: .1em; text-transform: uppercase; opacity: .88; margin-top: 1px; text-shadow: var(--chroma); }
#touch .tt-btn.down { transform: scale(.9); background: radial-gradient(circle at 50% 38%, rgba(70,70,90,.7), rgba(5,7,13,.8)); }

#touch .tt-roar { width: var(--b1); height: var(--b1); right: calc(var(--sr) + 18px); bottom: calc(var(--sb) + 18px);
  background: radial-gradient(circle at 50% 36%, rgba(224,36,46,.78), rgba(80,6,12,.82) 78%); border-color: rgba(255,122,24,.8);
  box-shadow: 0 6px 22px rgba(0,0,0,.6), 0 0 24px rgba(224,36,46,.5), inset 0 0 18px rgba(0,0,0,.4); }
#touch .tt-roar .tt-ico { width: 38%; height: 38%; color: #fff; }
#touch .tt-roar small { color: #fff; font-size: clamp(18px, 5vmin, 26px); }
#touch .tt-roar.down { background: radial-gradient(circle at 50% 36%, rgba(255,90,70,.95), rgba(120,10,16,.9) 78%); }

#touch .tt-power { width: var(--b2); height: var(--b2); right: calc(var(--sr) + 18px + var(--b1) + 12px); bottom: calc(var(--sb) + 26px); --pp: 1; border-color: transparent;
  background: conic-gradient(var(--pc) calc(var(--pp) * 360deg), rgba(232,224,204,.14) 0); }
#touch .tt-power::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: radial-gradient(circle at 50% 38%, #1a1d2a, #07090f); }
#touch .tt-power > * { position: relative; }
#touch .tt-power .tt-ico { width: 40%; height: 40%; color: rgba(232,224,204,.55); transition: color .3s, filter .3s; }
#touch .tt-power small { font-size: clamp(11px, 3vmin, 15px); max-width: 92%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
#touch .tt-power.ready { box-shadow: 0 6px 18px rgba(0,0,0,.5), 0 0 22px color-mix(in srgb, var(--pc) 70%, transparent); animation: pwGlow 1.6s ease-in-out infinite; }
#touch .tt-power.ready .tt-ico { color: var(--pc); filter: drop-shadow(0 0 6px var(--pc)); }
#touch .tt-power.ready small { opacity: 1; }
#touch .tt-power.active .tt-ico { color: #fff; filter: drop-shadow(0 0 10px var(--pc)); }

#touch .tt-sneak { width: var(--b3); height: var(--b3); right: calc(var(--sr) + 18px + var(--b1) * .12); bottom: calc(var(--sb) + 18px + var(--b1) + 12px); }
#touch .tt-sneak .tt-ico { width: 40%; height: 40%; color: var(--bone-dim); }
#touch .tt-sneak small { font-size: clamp(11px, 3vmin, 15px); }
#touch .tt-sneak.on { border-color: var(--pumpkin); background: radial-gradient(circle at 50% 38%, rgba(255,122,24,.4), rgba(5,7,13,.78)); box-shadow: 0 0 18px rgba(255,122,24,.55); }
#touch .tt-sneak.on .tt-ico { color: var(--pumpkin); }

#touch .tt-pause { width: 46px; height: 46px; left: calc(var(--sl) + 10px); top: calc(var(--st) + 10px); border-radius: 12px; }
#touch .tt-pause svg { width: 22px; height: 22px; }

/* floating joystick */
#touch .tt-stick { position: fixed; width: calc(var(--r, 56px) * 2); height: calc(var(--r, 56px) * 2); transform: translate(-50%, -50%); opacity: 0; pointer-events: none; transition: opacity .12s; }
#touch .tt-stick.on { opacity: 1; }
#touch .tt-ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(232,224,204,.4); background: radial-gradient(circle, rgba(232,224,204,.05), rgba(5,7,13,.34)); box-shadow: 0 0 22px rgba(0,0,0,.5); transition: border-color .12s, box-shadow .12s; }
#touch .tt-ring.sprint { border-color: var(--pumpkin); box-shadow: 0 0 22px rgba(255,122,24,.55); }
#touch .tt-knob { position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; border-radius: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,.55), rgba(232,224,204,.3)); border: 2px solid rgba(232,224,204,.6); box-shadow: 0 3px 10px rgba(0,0,0,.5); }

/* first-seconds hints */
#touch .tt-hint { position: absolute; bottom: 64%; font-family: var(--f-vhs); font-size: clamp(20px, 5vmin, 28px); letter-spacing: .08em; color: var(--osd, #f3f0e6); text-shadow: var(--chroma); opacity: 0; transition: opacity .6s; text-transform: uppercase; }
#touch .tt-hint-l { left: calc(var(--sl) + 8%); }
#touch .tt-hint-r { right: calc(var(--sr) + 8%); }
#touch.hints .tt-hint { opacity: .75; }

/* fullscreen button (menu, pause and play) */
.tt-fs { display: none; position: fixed; z-index: 30; top: calc(var(--st) + 10px); right: calc(var(--sr) + 10px); width: 46px; height: 46px; padding: 11px; border-radius: 12px; cursor: pointer;
  color: var(--bone); background: rgba(5,7,13,.55); border: 1px solid rgba(232,224,204,.3); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.tt-fs svg { width: 100%; height: 100%; display: block; }
html.touch .tt-fs.show:not([hidden]) { display: block; }
.tt-fs.on { border-color: var(--pumpkin); color: var(--pumpkin); }
html.clean .tt-fs { display: none !important; }

/* rotate screen: portrait on a touch device. Full screen, cannot be dismissed. */
.tt-rotate { position: fixed; inset: 0; z-index: 200; display: none; place-items: center; background: #05070d; color: var(--osd, #f3f0e6); text-align: center; touch-action: none; }
.tt-rotate.on { display: grid; }
.tt-rotate::before { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .55; background: repeating-linear-gradient(0deg, rgba(0,0,0,.35) 0 1px, transparent 1px 3px); }
.tt-rotate::after { content: 'PLAY \25B6'; position: absolute; left: 20px; bottom: calc(var(--sb) + 20px); font-family: var(--f-vhs); font-size: 24px; opacity: .6; text-shadow: var(--chroma); }
.tt-rotate-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px; }
.tt-rotate-title { margin: 0; font-family: var(--f-vhs); font-size: 44px; letter-spacing: .06em; text-transform: uppercase; text-shadow: var(--chroma); line-height: 1; }
.tt-rotate-sub { margin: 0; font-family: var(--f-vhs); font-size: 22px; letter-spacing: .08em; opacity: .65; text-transform: uppercase; }
.tt-rotate-ico { width: 52px; height: 84px; border: 4px solid var(--osd, #f3f0e6); border-radius: 10px; position: relative; margin-bottom: 18px; box-shadow: -2px 0 rgba(0,255,170,.5), 2px 0 rgba(255,0,170,.55); animation: ttTurn 2.4s ease-in-out infinite; }
.tt-rotate-ico::after { content: ''; position: absolute; left: 50%; bottom: 6px; width: 12px; height: 4px; margin-left: -6px; background: var(--osd, #f3f0e6); border-radius: 2px; }
@keyframes ttTurn { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
html.portrait-block #ui, html.portrait-block #touch, html.portrait-block .tt-fs { pointer-events: none !important; }

/* ---------- HUD while touch controls are on ---------- */
html.touch .fps-counter[data-mode="playing"] { top: 62px; right: 14px; }
html.touch .hud-power { display: none !important; }
html.touch .crosshair { opacity: .8; }
html.touch .hud-candy { left: calc(var(--sl) + 66px); top: calc(var(--st) + 10px); padding: 3px 12px 3px 8px; gap: 8px; }
html.touch .hud-candy .ico { width: 30px; height: 20px; }
html.touch .candy-num { font-size: 22px; }
html.touch .candy-goal { font-size: 13px; }
html.touch .hud-clock { top: calc(var(--st) + 10px); padding: 3px 14px; gap: 8px; }
html.touch .clock-text { font-size: 18px; }
html.touch .hud-scares { right: calc(var(--sr) + 66px); top: calc(var(--st) + 10px); padding: 3px 12px; gap: 8px; }
html.touch .scare-num { font-size: 20px; }
html.touch .hud .ico { width: 20px; height: 20px; }
html.touch .hud-stamina { left: calc(var(--sl) + 68px); top: calc(var(--st) + 58px); bottom: auto; }
html.touch .hud-stamina .bar { width: 110px; }
html.touch .hud-exposure { top: calc(var(--st) + 58px); bottom: auto; }
html.touch .hud-exposure .bar { width: min(240px, 34vw); height: 7px; }
html.touch .hud-exposure .ico { width: 20px; height: 20px; }
html.touch .toasts { top: 30%; }
html.touch .toast { font-size: 17px; }
html.touch .toast.scream { font-size: clamp(30px, 8vmin, 46px); }
html.touch .toast.gold { font-size: 15px; }

/* ---------- pause and end ---------- */
html.touch .pause, html.touch .end { overflow-y: auto; }
.end { overflow-y: auto; }
.pause .center-card, .end .center-card { margin: auto; padding: 12px 16px; max-width: 100vw; }
.pause, .end { display: flex; }
html.touch .center-card .mbtn { min-height: 48px; }

html.touch .osd-tr { right: calc(var(--sr) + 66px); }
html.touch .menu[data-view="settings"] .showcase-plate, html.touch .menu[data-view="how"] .showcase-plate, html.touch .menu[data-view="credits"] .showcase-plate { visibility: hidden; animation: none; }

/* ---------- tap targets on touch devices ---------- */
html.touch .mbtn, html.touch .plate-link, html.touch .dbtn, html.touch .code-btn { min-height: 44px; min-width: 44px; }
html.touch .segbtn { min-height: 44px; }
html.touch .mbtn { display: inline-flex; align-items: center; }
html.touch input[type=range] { height: 44px; }
html.touch input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -10px; }
html.touch .code-in { min-height: 44px; font-size: 20px; }

/* =====================================================================
   Landscape phones (844x390, 932x430) and any very short window
   ===================================================================== */
@media (max-height: 520px) {
  .menu-col { left: calc(var(--sl) + 16px); top: calc(var(--st) + 6px); width: min(58vw, 500px); }
  .title, .menu-col:not([data-view="main"]) .title {
    display: flex; align-items: baseline; gap: .3em; font-size: 42px; line-height: 1; margin-left: 0;
  }
  .title span { display: inline; margin: 0; }
  .title .t2 { font-size: .38em; letter-spacing: .3em; margin: 0; }
  .tagline { display: none; }
  .menu-items { gap: 0; }
  .menu-items[data-panel="main"].open { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; width: 100%; margin-top: 2px; align-items: center; }
  .menu .menu-items .mbtn { min-height: 44px; display: inline-flex; align-items: center; justify-self: start; }
  .menu .menu-items .mbtn[data-act="play"] { grid-column: 1 / -1; font-size: 56px; min-height: 58px; margin: 0; }
  .menu .menu-items .mbtn[data-act="monsters"] { font-size: 30px; margin-top: 0; }
  .menu .menu-items .mbtn[data-act="map"] { font-size: 30px; }
  .menu .menu-items .mbtn[data-act="how"] { font-size: 28px; margin-top: 0; }
  .menu .menu-items .mbtn[data-act="settings"] { font-size: 28px; }
  .menu .menu-items .mbtn[data-act="credits"] { font-size: 26px; }
  .menu-col .diff { grid-column: 1 / -1; margin: 0 0 2px 4px; }
  .diff-seg { gap: 22px; }
  .dbtn { padding: 0 0 2px; min-height: 44px; justify-content: center; }
  .dbtn b { font-size: 26px; }
  .dbtn small { font-size: 15px; }
  .diff-desc { font-size: 16px; min-height: 0; }

  .osd-tr { top: calc(var(--st) + 10px); right: calc(var(--sr) + 66px); font-size: 22px; }
  .osd-bl { display: none; }

  .showcase-plate { bottom: calc(var(--sb) + 10px); right: calc(var(--sr) + 14px); width: min(300px, 38vw); padding: 12px 14px 8px; --rot: 1deg; }
  .showcase-plate::before { width: 80px; height: 20px; top: -9px; }
  .menu[data-view="settings"] .showcase-plate, .menu[data-view="how"] .showcase-plate, .menu[data-view="credits"] .showcase-plate { visibility: hidden; animation: none; }
  .plate-blurb { display: none; }
  .plate-top { gap: 10px; }
  .lv-counter { font-size: 22px; }
  .lv-badge small { font-size: 10px; }
  .plate-name { font-size: 28px; }
  .plate-xp { margin-top: 6px; }
  .plate-link { font-size: 20px; margin-top: 2px; display: inline-flex; align-items: center; }

  /* sub panels */
  .menu-col .panel { margin-top: 8px; width: min(78vw, 600px); max-height: calc(100vh - 72px - var(--st) - var(--sb)); max-height: calc(100dvh - 72px - var(--st) - var(--sb));
    overflow-y: auto; overflow-x: hidden; padding: 16px 20px 6px; transform: none; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .menu-col .panel::before { display: none; }
  .panel h2 { font-size: 28px; margin-bottom: 6px; }
  .panel[data-panel="settings"] { width: min(86vw, 660px); }
  .panel .setting label { font-size: 18px; margin-bottom: 4px; }
  .sgrid .setting { margin-bottom: 8px; }
  .panel .segbtn { font-size: 18px; padding: 4px 14px; }
  .panel .objectives { font-size: 13px; line-height: 1.35; }
  .panel .objectives li { margin-bottom: 4px; }
  .panel .krow em { font-size: 12px; }
  .panel .credits { max-height: none; font-size: 13px; line-height: 1.5; }
  .panel .mbtn.back { min-height: 44px; margin-top: 2px; position: sticky; bottom: 0; background: var(--paper); width: 100%; justify-content: flex-start; font-size: 28px; }

  /* settings: BACK sits in the heading row (not a sticky bottom row that hid the sliders), rows are tight, and a fade at the bottom shows there is more to scroll */
  .menu-col .panel[data-panel="settings"] { padding-top: 8px; }
  .menu-col .panel[data-panel="settings"] .mbtn.back { position: absolute; top: 6px; right: 14px; bottom: auto; width: auto; margin: 0; background: transparent; z-index: 2; }
  .panel[data-panel="settings"] h2 { margin-bottom: 0; padding-bottom: 0; }
  .panel[data-panel="settings"] .sgrid .setting { margin-bottom: 2px; }
  .panel[data-panel="settings"] .setting label { margin-bottom: 0; line-height: 1.15; font-size: 16px; }
  .panel[data-panel="settings"] .segbtn { min-height: 40px; padding: 2px 14px; }
  html.touch .panel[data-panel="settings"] input[type=range] { height: 40px; }
  .panel[data-panel="settings"]::after { content: ''; display: block; position: sticky; bottom: -6px; height: 26px; margin-top: -26px; pointer-events: none; background: linear-gradient(to bottom, transparent, var(--paper)); }

  /* wide screens: monsters and map */
  .wide { inset: calc(var(--st) + 8px) calc(var(--sr) + 12px) calc(var(--sb) + 8px) calc(var(--sl) + 12px); gap: 8px; }
  .wide-head { gap: 12px; flex-wrap: nowrap; }
  .wide-head h2 { font-size: 28px; padding: 4px 18px 2px; }
  .wide-sub { font-size: 20px; margin-left: 8px; }
  .xpbox { grid-template-columns: auto 90px auto; font-size: 16px; gap: 8px; margin-right: 56px; }
  .xpbox b { font-size: 22px; }
  .xpbox .lv-xp { display: none; }
  .mon-body { grid-template-columns: 250px 1fr; grid-template-rows: none; gap: 14px; }
  .mon-list { flex-direction: column; overflow-y: auto; overflow-x: hidden; gap: 6px; }
  .mcard { flex: 0 0 auto; min-height: 50px; padding: 4px 8px; }
  .mc-text b { font-size: 14px; letter-spacing: .04em; }
  .mc-text small { font-size: 14px; }
  .mon-stage { margin: 4px; }
  .mon-stage::after { font-size: 20px; top: 8px; right: 14px; }
  .stage-info { left: 14px; bottom: 10px; max-width: 66%; }
  .mon-name { font-size: 30px; }
  .mon-blurb { font-size: 12px; margin: 2px 0 6px; line-height: 1.25; }
  .mon-power { font-size: 12px; margin: 0 0 6px; line-height: 1.3; }
  .mon-stats { display: none; }
  .wide-foot { gap: 10px; flex-wrap: nowrap; }
  .code-in { width: 150px; }
  .wide .mbtn.back { font-size: 28px; min-height: 44px; }
  .map-cards { grid-template-columns: repeat(3, 1fr); overflow: visible; align-content: center; gap: 14px; padding: 0 6px; }
  .thumb { aspect-ratio: 16 / 8; }
  .mp-text { margin: -14px 10px 0; padding: 6px 10px; }
  .mp-text b { font-size: 18px; }
  .mp-text small { display: none; }
  .mp-tag { font-size: 18px; margin: 6px 12px 8px; }

  /* pause and end */
  .center-card .big { font-size: 48px; margin-bottom: 8px; }
  .center-card .mbtn { font-size: 30px; }
  .center-card .mbtn:first-child { font-size: 36px; }
  .end-title { font-size: 46px; }
  .end-reason { font-size: 18px; margin: 4px 0 10px; }
  .end-diff { margin-top: 0; margin-bottom: 8px; font-size: 18px; }
  .stats { margin-bottom: 8px; gap: 36px; }
  .stat b { font-size: 30px; }
  .stat .ico { width: 24px; height: 20px; }
  .end-prog { margin: 0 0 8px; gap: 6px; }
  .xp-gain { font-size: 22px; } .xp-gain b { font-size: 30px; }
  .unlock-card { padding: 8px 24px 6px; } .unlock-card b { font-size: 28px; }
  .end .menu-items.center { flex-direction: row; gap: 36px; }
  .end .center-card { padding-top: 6px; }

  /* intro card */
  .tof-intro .clock { font-size: 52px; line-height: 1; }
  .tof-intro .night { font-size: 11px; margin-top: 2px; }
  .tof-intro .rules { margin-top: 8px; font-size: 12px; line-height: 1.5; min-height: 0; }
  .tof-intro .go { margin-top: 6px; font-size: 12px; }
}

/* ---------- very short landscape (iPhone 852x393 and smaller): the end screen has to fit without scrolling ---------- */
@media (max-height: 430px) {
  .end .center-card { padding-top: 2px; padding-bottom: 4px; }
  .end-title { font-size: 34px; margin: 0; }
  .end-reason { font-size: 15px; margin: 2px 0 4px; }
  .end-diff { display: none; }
  .stats { margin-bottom: 2px; gap: 30px; }
  .stat b { font-size: 24px; }
  .stat small { font-size: 12px; }
  .xp-gain { font-size: 16px; } .xp-gain b { font-size: 22px; }
  .end-prog { margin: 0 0 2px; gap: 2px; }
  .end .menu-items.center { gap: 28px; }
  .end .center-card .mbtn { font-size: 26px; min-height: 44px; }
  .unlock-card { padding: 4px 18px 2px; } .unlock-card b { font-size: 22px; }
}

/* ---------- tablets and small laptops (1024x768) ---------- */
@media (min-width: 701px) and (max-height: 800px) and (min-height: 521px) {
  .menu-col { top: clamp(14px, 3vh, 40px); }
  .title { font-size: clamp(52px, 8vh, 84px); }
  .menu-col:not([data-view="main"]) .title { font-size: 48px; }
  .menu .menu-items .mbtn[data-act="play"] { font-size: 64px; }
  .menu .menu-items .mbtn { min-height: 44px; display: inline-flex; align-items: center; }
  .menu-col .panel { max-height: calc(100vh - 190px); overflow-y: auto; overflow-x: hidden; }
  .menu-col .panel::before { display: none; }
  .wide { inset: 16px 22px 14px; gap: 10px; }
  .mon-body { grid-template-columns: 250px 1fr; grid-template-rows: none; }
  .mon-list { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
  .mcard { flex: 0 0 auto; }
}
