/* ---- page layout (mobile first) ---- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Base text size: 17px on phones, 18px from tablet up (as percentages, so a
   reader's own browser setting still scales it). Everything sized in rem,
   speech bubbles included, follows this. */
html {
  font-size: 106.25%;
}

@media (min-width: 768px) {
  html {
    font-size: 112.5%;
  }
}

body {
  margin: 0;
  line-height: 1.6;
  overflow-wrap: break-word;
}

/* Text sits in a readable column with a 16px gutter; the tapes run full width. */
header > :not(.tape-wrap),
main {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

ul, ol {
  padding-left: 1.25rem;
}

/* ---- sections: the same spacing at every start and end ---- */
/* Each section opens with the same gap above its heading and closes with the
   same gap below its last line; a thin rule sits between neighbours. */
main > section {
  padding: 2rem 0;
}

main > section + section {
  border-top: 1px solid #ddd;
}

main > section > h2 {
  margin-top: 0;
  margin-bottom: 1rem;
}

main > section > :last-child,
main > section > :last-child > :last-child {
  margin-bottom: 0;
}

/* Body text is justified; hyphenation keeps narrow phone lines from
   opening big gaps between words. The header stays centred. */
main p,
main li,
main dd {
  text-align: justify;
  -webkit-hyphens: auto;
  hyphens: auto;
}

dd {
  margin: 0 0 0.75rem 1rem;
}

/* ---- header: name to nav, centred ---- */
header {
  text-align: center;
}

h1 {
  font-size: clamp(1.8rem, 7vw, 2.75rem);
  line-height: 1.15; /* a heading's own line height, not the body's 1.6 */
  margin-bottom: 0.25rem;
}

/* ---- pixel-art hero (drawn by hero.js) ---- */
/* The top padding is room for the speech bubbles above the heads. */
header > .hero {
  position: relative;
  max-width: 440px;
  padding-top: 6rem;
  overflow: hidden; /* bubbles can never stick out of the hero */
}

/* The first screen must show everything from the tape down to the role and
   "Colombo, Sri Lanka". On short screens (an iPhone SE with Safari's bars
   showing, a 1366x768 laptop) the drawing shrinks just enough to fit; on
   taller ones it stays full width. --first-screen-rest is the height of
   everything on that first screen except the drawing, plus a small gap at
   the bottom. svh is the visible height with the browser bars showing;
   browsers without it keep the full-width drawing. */
/* Measured at 320-1920px wide: about 19rem + 2vw (the tilted tape's padding
   grows with width), plus ~1rem to spare at the bottom. */
:root {
  --first-screen-rest: calc(20rem + 2vw);
}

#hero-canvas {
  display: block;
  width: 100%;
  width: min(100%, max(14rem, (100svh - var(--first-screen-rest)) * 64 / 44));
  margin: 0 auto;
  height: auto;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.bubble {
  position: absolute;
  top: 0;
  left: 0;
  width: max-content;
  max-width: min(92%, 22rem);
  margin: 0;
  padding: 0.45rem 0.65rem;
  background: #fff;
  color: #111;
  border: 3px solid #111;
  box-shadow: 4px 4px 0 #111;
  /* the same size as the body text, so every line reads easily on a phone */
  font: 700 1rem/1.35 "Courier New", Courier, monospace;
  text-align: left;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 2;
}

.bubble.is-on {
  opacity: 1;
}

/* the little tail pointing down at the speaker */
.bubble::after {
  content: "";
  position: absolute;
  left: var(--tail, 50%);
  bottom: -12px;
  width: 12px;
  height: 10px;
  margin-left: -6px;
  background: #111;
  clip-path: polygon(0 0, 100% 0, 25% 100%);
}

/* The dog peeking up from the bottom edge. hero.js picks a spot along the
   edge, raises it a bit at a time from just below, then ducks it back down. */
#peek-dog {
  position: fixed;
  bottom: 0;
  left: 0;
  width: clamp(100px, 28vw, 120px); /* in step with the bigger text on phones */
  height: auto;
  z-index: 20;
  pointer-events: none;
  display: none; /* not in the page at all unless it's peeking */
  transform: translateY(100%);
  transform-origin: 50% 100%;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.bubble-fixed {
  position: fixed;
  z-index: 21;
  display: none; /* only exists while the peeking dog is talking */
}

.bubble-fixed.is-on {
  display: block;
}

/* Contact links in the header: one centred row that wraps on phones. */
.contact-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1rem;
}

.contact-links a {
  padding: 0.35rem 0.25rem; /* bigger tap target on phones */
}

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #ccc;
}

nav a {
  padding: 0.35rem 0.25rem; /* bigger tap target on phones */
}

/* ---- contact form: full width on phones, capped on desktop ---- */
input, select, textarea, button {
  font: inherit;
}

#contact-form p {
  text-align: left; /* not justified: it's a form, not a paragraph */
}

#contact-form label {
  display: block;
}

/* Fields can never be wider than the screen: block, border-box, min-width 0
   (some phone browsers give selects and inputs a minimum width of their own).
   16px text stops iPhone Safari zooming in on tap, which looks like cropping. */
input, select, textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 28rem;
  min-width: 0;
  margin-top: 0.25rem;
  padding: 0.5rem;
  font-size: max(16px, 1rem);
  border: 1px solid #8a8a8a;
  border-radius: 4px;
  background: #fff;
  color: #111;
}

textarea {
  resize: vertical;
}

button {
  padding: 0.5rem 1.25rem;
  font-size: max(16px, 1rem);
}

/* ---- tape strips (top and footer) ---- */
/* The wrapper crops the tilted tape to the page width, so it can never cause
   sideways scrolling. Its vertical padding leaves room for the tilt (about
   1vw at 1deg). */
.tape-wrap {
  overflow: hidden;
  padding: calc(1vw + 4px) 0;
  margin: 0.5rem 0 1rem;
  /* Belt and braces for iPhone Safari, where overflow: hidden alone may not
     clip a GPU-animated child: these make the wrapper a hard clipping box, so
     the ~3500px scrolling strip inside can never widen the page. */
  position: relative;
  contain: paint;
  clip-path: inset(0);
  -webkit-clip-path: inset(0);
}

footer .tape-wrap {
  margin: 2.5rem 0 1rem;
}

.tape {
  overflow: hidden;
  color: #111;
  /* The black-and-yellow hazard stripes along the top and bottom edges are
     two plain background bands, 6px tall, over the yellow. Not border-image:
     iPhone browsers (all WebKit) left those edges plain yellow. The 6px
     padding keeps the words clear of the stripes. */
  --tape-stripes: repeating-linear-gradient(-45deg, #111 0 10px, #ffd400 10px 20px);
  background:
    var(--tape-stripes) top / 100% 6px no-repeat,
    var(--tape-stripes) bottom / 100% 6px no-repeat,
    #ffd400;
  padding: 6px 0;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: clamp(0.8rem, 3vw, 0.9rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  transform: rotate(-1deg);
  margin: 0 -1rem; /* wider than the page so the tilted ends stay covered */
}

footer .tape {
  transform: rotate(1deg);
}

.tape-track {
  display: inline-flex;
  padding: 0.35rem 0;
  animation: tape-scroll 30s linear infinite;
}

.tape-track span {
  padding: 0 1rem;
}

.tape-track span::after {
  content: "\25B2"; /* ▲ separator */
  margin-left: 2rem;
  font-size: 0.7em;
}

/* The track holds the words twice; moving it by half loops seamlessly. */
@keyframes tape-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .tape-track { animation: none; }
}
