/* ==========================================================================
   หน้าเขียน — write page. Mobile-first; the mock's 452px panel is the
   large-screen presentation of the same column.
   ========================================================================== */

.page-write {
  background: var(--sky-canvas);
  min-height: 100vh;
  min-height: 100dvh;
}

.write {
  position: relative;
  width: 100%;
  max-width: var(--write-w);
  margin: 0 auto;
  background: var(--sky-panel);
  overflow: hidden;
}

/* ------------------------------------------------------------------ hero */

/* The scene is artwork; the wordmark over it is type. See the note in
   write.html for why that changed. */
.hero {
  position: relative;
  padding: 0;
  background: var(--sky-panel);
  isolation: isolate;
}

.hero__art {
  position: relative;
  width: 100%;
  /* The banner's own 1400:694, so nothing is cropped and the percentages the
     lockup is positioned by keep meaning what they were measured against. */
  aspect-ratio: 1400 / 694;
  background-color: var(--sky-panel);
  /* One flattened banner, not a scene plus a separate title lockup: the
     wordmark is real text drawn over it, so it can be the same face as the
     welcome screen instead of a picture of a different one. */
  background-image: url("../img/gen/header-form-banner.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* The band of open sky in the banner, measured off the file: the moon ends at
   34% of its height and the rabbits begin at 72%. The lockup is given that
   band and centres itself in it, so the type can change size per tier without
   anyone re-checking that it still clears both. */
.hero__lockup {
  position: absolute;
  left: 0;
  right: 0;
  top: 36%;
  height: 36%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  text-align: center;
  /* Nothing here is interactive, and the back arrow is underneath its left
     end at the narrowest widths. */
  pointer-events: none;
}

/* The same face, weight and tracking as TSUKIMI on the welcome screen — that
   is the point of setting it in text. It is sized off the viewport below
   520px, where the hero is as wide as the phone, and pinned per tier above
   that, where the panel has a fixed width and vw no longer describes it. */
/*
   Full width, centred by text-align — never a shrink-to-fit box centred by
   align-items. See the long note on .poster__head-name in
   assets/css/summary.css: a measured box collapses where the font that was
   measured is not the font that paints, and the line then runs off to one
   side by half its own width. */
.hero__en,
.hero__sub {
  width: 100%;
}

.hero__en {
  font: 300 clamp(26px, 9.6vw, 42px)/1 var(--font-en);
  letter-spacing: .14em;
  /* NO text-indent to "re-centre" this. There used to be one, equal to the
     letter-spacing, on the premise that tracking pads the right of the last
     glyph and centring therefore leans left. `text-align: center` does not
     count that trailing space, in Blink or in WebKit — measured on both: at
     text-indent 0 the glyph run's centre and the box's centre are the same
     point to within 0.00px, and every em of indent moves the run bodily
     right. So the compensation was not a correction, it WAS the offset: this
     line sat a full 0.16em right of centre, and on the poster it disagreed
     with the canvas export, which centres the tracked run by hand (see
     drawTracked in assets/js/poster.js) — so the words jumped sideways the
     moment the saved image was laid over the page. */
  color: var(--cream);
  text-shadow: 0 2px 24px rgba(6, 10, 26, .6);
}
.hero__sub {
  font: 400 clamp(9.5px, 3.2vw, 14px)/1 var(--font-en);
  letter-spacing: .26em;
  /* No text-indent here — see the note beside the first of these. */
  color: var(--gold-a90);
  text-shadow: 0 1px 14px rgba(6, 10, 26, .7);
}

/* The back arrow floats over the art rather than sitting in a bar of its own:
   a strip of chrome above a full-bleed scene would cut the banner in half for
   one button. */
.hero__bar {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 2;
}
.hero__bar .icon-btn {
  background: rgba(8, 13, 32, .5);
  backdrop-filter: blur(3px);
}


/* ------------------------------------------------------------- form sheet */

.sheet {
  /* Hints, fields and the submit button all sit flush with the section number
     rather than hanging under the label. Kept as a token because four rules
     depend on it staying in step. */
  --indent: 0px;
  position: relative;
  background: var(--paper);
  padding: 20px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field { display: block; padding-left: var(--indent); }

.field__head { display: flex; align-items: baseline; gap: 9px; }
.field__num {
  /* Cormorant's lining 1 reads as a roman numeral I at this size. */
  font: 300 23px/1 var(--font-sans);
  color: var(--ink);
  font-variant-numeric: lining-nums;
}
.field__label {
  font: 500 15px/1.4 var(--font-thai);
  color: var(--ink);
  display: flex;
  /* REQ-03: center, not baseline. The "ไม่บังคับ" pill has its own padding, so
     sitting it on the text baseline pushes the pill visibly below the heading
     it belongs to. */
  align-items: center;
  gap: 8px;
}
.field__optional {
  font: 300 10.5px/1 var(--font-sans);
  color: var(--ink-faint);
  border: 1px solid var(--paper-border);
  border-radius: var(--r-pill);
  padding: 3px 8px;
}
.field__hint {
  /* 11px, not 11.5: Prompt is ~6.5% wider than the Noto Sans Thai this token
     used to resolve to, which pushed the longer hint onto a second line at
     375px. */
  font: 300 11px/1.55 var(--font-sans);
  color: var(--ink-muted);
  margin: 5px 0 7px var(--indent);
}
.field__hint--label { margin: 0 0 8px; display: block; }
.field__box { position: relative; }

.field__box textarea,
.field__box input {
  display: block;
  width: 100%;
  border: 1px solid var(--paper-border);
  border-radius: var(--r-field);
  background: var(--paper-field);
  padding: 13px 14px 26px;
  font: 400 13.5px/1.75 var(--font-thai);
  color: var(--ink);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
/* Four lines of Thai (4 x 23.6px) plus the 13px top padding. At 84px it
   scrolled after two, which made an ordinary-length message look like it had
   overflowed; longer text still scrolls, which is correct. The extra height
   used to be room for the seal stamped across the corner — there is no seal
   and no card to choose any more, and the box keeps the height because the
   messages did not get shorter. */
.field__box textarea { height: 112px; resize: none; }
.field__box input { padding: 13px 58px 13px 14px; line-height: 1.4; }

.field__box textarea:focus,
.field__box input:focus {
  border-color: var(--gold-focus);
  box-shadow: 0 0 0 3px rgba(200, 167, 95, .14);
}
.field__box textarea[aria-invalid="true"],
.field__box input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(229, 132, 154, .16);
}

.field__count {
  position: absolute;
  right: 12px;
  bottom: 9px;
  z-index: 1;
  font: 400 10px/1 var(--font-mono);
  color: var(--ink-faint);
  pointer-events: none;
}
/* The count sits INSIDE the box, at its foot: it is a property of the text, and
   reading it outside the field made it look like a caption on the field below.
   Section 3's is centred on the input's own line instead. */
.field__count--inline { bottom: auto; top: 50%; transform: translateY(-50%); }
.field__count.is-max { color: var(--danger-ink); }

/* ---- the requirement note ---- */
.sheet__req {
  margin: -6px 0 0;
  padding: 10px 13px;
  border-radius: var(--r-field);
  background: rgba(200, 167, 95, .1);
  border: 1px solid var(--gold-a28);
  font: 300 12.5px/1.6 var(--font-sans);
  color: var(--ink-muted);
  text-align: center;
}
.sheet__req strong { color: var(--ink); font-weight: 500; }

/* ------------------------------------------------------------------ submit */

.submit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  margin-left: var(--indent);
}

.submit__error {
  align-self: stretch;
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--r-field);
  background: rgba(229, 132, 154, .14);
  border: 1px solid rgba(229, 132, 154, .45);
  color: var(--danger-ink);
  font: 400 12.5px/1.6 var(--font-thai);
  animation: riseIn .22s ease-out;
}


/* ------------------------------------------------------------- >= 520px */

@media (min-width: 520px) {
  .page-write {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 26px;
    background:
      radial-gradient(circle at 50% 8%, rgba(240, 208, 122, .10), transparent 46%),
      var(--sky-canvas);
  }
  .write {
    border-radius: var(--r-panel);
    box-shadow: var(--sh-panel);
  }
  /* 452px of panel, whatever the window does, so the type stops following vw.
     The band is 452 * 694/1400 * 36% = 81px tall and this lockup is 61px. */
  .hero__en  { font-size: 42px; }
  .hero__sub { font-size: 14px; }

  /* The hero art is full-bleed to the panel edges, so no side padding here. */
  .sheet {
    padding: 22px 28px 26px;
    gap: 20px;
  }
}

/* ============================================================== desktop === */

/* The phone layout is a banner on top of a paper sheet, both inside one narrow
   panel. That does not scale up: at 1440px it is a 452px card marooned in a
   dark field.
   
   A two-column split was the obvious move and it does not work with this
   artwork — header-bg-form.png is a *landscape scene* and carries no wordmark
   (that is the separate overlay), so cropping it into a tall column throws away
   the moon and the rabbits and leaves a strip of mountainside.

   So the scene goes full-bleed, at the shape it was drawn for, and the page
   composes on top of it: the lockup floating on the sky, the form as a single
   sheet of paper below. */
@media (min-width: 1024px) {
  .page-write {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    background:
      linear-gradient(180deg, rgba(6, 10, 26, .55), rgba(6, 10, 26, .18) 38%, rgba(6, 10, 26, .62)),
      url("../img/gen/form-desktop.webp") center / cover no-repeat,
      var(--sky-void);
    background-attachment: scroll, fixed, scroll;
  }

  /* The panel stops being a panel — the sheet below is the only solid part.
     Which means the border-radius and the drop shadow it inherits from the
     >= 520px tier have to go with the background: a shadow is still painted
     around a transparent box, so what was left was a 660x980 rectangle of
     darkness floating over the sky with the lockup sitting inside it. The
     sheet carries its own shadow, and it is the only thing that should. */
  .write {
    max-width: 660px;
    background: transparent;
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
  }

  /* Just the lockup, floating on the sky. The scene behind it is the page, so
     the banner is not drawn twice — .hero__art is reduced to the box the
     lockup is centred in. */
  .hero {
    background: transparent;
    padding: 0 0 26px;
  }
  .hero__art {
    aspect-ratio: 1400 / 300;
    background-color: transparent;
    background-image: none;
  }
  /* No moon and no rabbits to clear here — the whole box is open sky. */
  .hero__lockup {
    top: 0;
    height: 100%;
    gap: 10px;
  }
  .hero__en  { font-size: 56px; }
  .hero__sub { font-size: 17px; }

  /* The card floats, so an arrow pinned to its corner reads as stranded.
     Anchor it to the page instead. */
  .hero__bar {
    position: fixed;
    top: 26px;
    left: 26px;
  }

  .sheet {
    border-radius: var(--r-panel);
    box-shadow: var(--sh-panel);
    padding: 40px clamp(36px, 4vw, 52px) 44px;
    gap: 26px;
  }

  .field__label { font-size: 16.5px; }
  .field__hint { font-size: 12px; }
  .submit__btn { padding: 20px 0; }
}

/* Tall screens can afford more of the sky above and below the card. */
@media (min-width: 1024px) and (min-height: 900px) {
  .page-write { padding: 72px 24px; }
}
