/* Touch mode (phones, tablets). Everything here is scoped: #start.touchstart before the game starts,
   body.touch once it runs. The desktop game never matches any of these rules. */

/* ---------- start screen ---------- */
#start.touchstart { align-items: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#start.touchstart .start-box { padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)); }
#start.touchstart .start-box h1 { font-size: 40px; }
#start.touchstart .start-box .sub { margin-bottom: 12px; font-size: 16px; }
.tcard { text-align: left; margin: 0 auto 10px; max-width: 520px; }
.tcard .tscheme { display: flex; width: fit-content; margin: 0 auto 10px; }
.tcard svg { display: block; width: 100%; max-width: 420px; margin: 0 auto 8px; }
.ctl-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 14px; line-height: 1.4; }
.ctl-rows li { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: start; }
.ctl-rows .ic { font-size: 18px; text-align: center; color: var(--accent); font-weight: bold; }
.tcard .muted { text-align: center; margin: 10px 0 0; }
#start.touchstart .btn.primary { width: min(320px, 100%); font-size: 22px; }

/* ---------- page behaviour ---------- */
body.touch { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
body.touch button { touch-action: manipulation; }
body.touch .panel input { -webkit-user-select: text; user-select: text; }

/* ---------- desktop HUD parts not used on touch ---------- */
body.touch #yearbox, body.touch #hint, body.touch #speedbox, body.touch #escpill, body.touch #paused, body.touch #compass { display: none !important; }

/* ---------- year pill (top left) ---------- */
#tyear { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 3px;
  padding: 3px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; pointer-events: auto; text-shadow: none; }
#tyear .yb { width: 36px; height: 36px; font-size: 22px; line-height: 1; }
.tsbig .yb, .tmspeed .yb { width: 44px; height: 44px; font-size: 26px; line-height: 1; }
#tyear .ynum { display: flex; flex-direction: column; align-items: center; min-width: 70px; background: none; border: none; color: var(--text); padding: 0 4px; font: inherit; cursor: pointer; }
#tyear .ynum .y { font-family: var(--serif); font-size: 20px; font-weight: bold; color: var(--accent); line-height: 1.05; }
#tyear .ynum .era { font-size: 10px; color: var(--muted); max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- top right: menu button + discovery counter ---------- */
body.touch #topright { right: calc(10px + env(safe-area-inset-right)); top: calc(10px + env(safe-area-inset-top)); display: flex; gap: 6px; align-items: center; flex-direction: row-reverse; }
body.touch #discovered { font-size: 12px; }
body.touch #soundbtn { width: 48px; height: 48px; margin: 0; border-radius: 50%; font-size: 20px; }
.tround { pointer-events: auto; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text);
  font: inherit; font-size: 22px; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; text-shadow: none; cursor: pointer; }
.tround small { font-size: 9px; margin-top: 2px; color: var(--muted); }
.tround:active, #tyear .yb:active { background: #2a3642; }

/* ---------- buttons on the right ---------- */
#tbtns { position: absolute; right: calc(10px + env(safe-area-inset-right)); top: calc(70px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 8px; }
#tbtns .tround { width: 54px; height: 54px; }

/* ---------- minimap (tap: big map) ---------- */
body.touch #minimap { pointer-events: auto; width: 104px; height: 104px; right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); }

/* ---------- toasts and the tour arrow at the top centre ---------- */
body.touch #toasts { top: calc(10px + env(safe-area-inset-top)); right: auto; left: 50%; transform: translateX(-50%); align-items: center; width: min(320px, calc(100vw - 260px)); }
body.touch #tourarrow { top: calc(64px + env(safe-area-inset-top)); }

/* ---------- the landmark in front of you: a small bubble (tap: read) ---------- */
body.touch #nearcard { pointer-events: none; bottom: calc(14px + env(safe-area-inset-bottom)); width: auto; max-width: calc(100vw - 260px); padding: 0;
  background: none; border: none; display: flex; gap: 8px; align-items: center; justify-content: center; }
.tbubble { pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; height: 40px; padding: 0 14px 0 10px;
  border-radius: 20px; border: 1.5px solid var(--accent); background: var(--panel); color: var(--text); font: inherit; font-size: 15px; font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); cursor: pointer; text-shadow: none; animation: bubblein 0.25s ease-out; }
.tbubble .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbubble .new { color: var(--accent); }
.tbubble.round { width: 40px; padding: 0; justify-content: center; font-size: 19px; flex: none; }
.tbubble:active { background: #2a3642; }
@keyframes bubblein { from { opacity: 0; transform: translateY(8px) scale(0.92); } }

/* ---------- joystick ---------- */
#joy { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.55); background: rgba(10, 14, 18, 0.25); }
#joy.run { border-color: var(--accent); box-shadow: 0 0 14px rgba(224, 178, 90, 0.7); }
#joy .knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(224, 178, 90, 0.9); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
#joyidle { position: absolute; left: calc(28px + env(safe-area-inset-left)); bottom: calc(28px + env(safe-area-inset-bottom)); width: 96px; height: 96px; border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.35); background: radial-gradient(circle, rgba(224, 178, 90, 0.35) 0 20px, transparent 21px); }

/* ---------- panels ---------- */
body.touch .panel { max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
body.touch .panel .close { width: 44px; height: 44px; font-size: 24px; margin: -10px -10px 0 0; }
body.touch .phase-list li, body.touch .tl-list li, body.touch .lm-list li { min-height: 44px; }
/* the year sheet is see-through, so the town can be watched changing while the year slides */
body.touch #panel-tyear { text-align: center; background: rgba(18, 24, 31, 0.5); backdrop-filter: none; -webkit-backdrop-filter: none; box-shadow: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); }
body.touch #panel-tyear .btn { background: rgba(31, 41, 51, 0.75); }
body.touch #panel-tyear .btn.primary { background: var(--accent); }
.tsbig { display: flex; justify-content: center; align-items: center; gap: 14px; }
#tsy { font-family: var(--serif); font-size: 46px; font-weight: bold; color: var(--accent); min-width: 120px; }
#tsera { font-weight: 600; margin: 2px 0 10px; }
#tsslider { width: 100%; height: 36px; accent-color: var(--accent); }
.tsrow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.tsrow .btn { min-height: 44px; }
.tsrow .btn.primary { display: inline-block; margin: 0; font-size: 16px; padding: 8px 18px; }
#tsinput { width: 120px; font-size: 22px; text-align: center; padding: 6px; border-radius: 8px; border: 1px solid var(--panel-border); background: #1b232c; color: var(--text); }
#tstl { min-height: 44px; width: 100%; }
.tmenu { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.tmenu > .btn { min-height: 46px; text-align: left; }
.tmrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tmrow .btn { min-height: 44px; }
.tmspeed { display: flex; gap: 12px; align-items: center; font-size: 20px; }

/* portrait: reading posture — panels become bottom sheets, the place card sits above the thumbs */
@media (orientation: portrait) {
  body.touch .panel { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; max-height: 86dvh; border-radius: 16px 16px 0 0; }
  body.touch .info-photos { grid-template-columns: repeat(2, 1fr); }
  body.touch .info-photos img { height: 110px; }
  body.touch #nearcard { max-width: calc(100vw - 24px); bottom: calc(136px + env(safe-area-inset-bottom)); }
  /* one thumb held upright: the resting joystick sits in the middle at the bottom */
  body.touch[data-scheme="one"] #joyidle { left: 50%; margin-left: -48px; }
  body.touch #toasts { width: calc(100vw - 24px); top: calc(66px + env(safe-area-inset-top)); }
  body.touch #tourarrow { top: calc(120px + env(safe-area-inset-top)); }
  body.touch #discovered { display: none; }
}
/* short landscape screens (phones held sideways) */
@media (orientation: landscape) and (max-height: 500px) {
  #tbtns { top: calc(64px + env(safe-area-inset-top)); gap: 6px; }
  #tbtns .tround { width: 48px; height: 48px; font-size: 20px; }
  body.touch #minimap { width: 92px; height: 92px; }
  body.touch .info-photos figure.main img { max-height: 200px; }
  /* the year sheet fits without scrolling (wider, no title, smaller) and sits low, leaving the town visible */
  body.touch #panel-tyear { width: min(600px, calc(100vw - 32px)); padding-top: 8px; top: auto; bottom: calc(6px + env(safe-area-inset-bottom)); transform: translateX(-50%); }
  #panel-tyear h2 { display: none; }
  #tsy { font-size: 36px; }
  #tsera { margin-bottom: 4px; }
  #tsslider { height: 28px; }
  .tsrow { margin: 6px 0; }
}
#tsinput::placeholder { font-size: 15px; }
.tmscheme { margin: 0; }
.tmscheme button { padding: 10px 12px; min-height: 44px; }
