/* Shared tokens, buttons, the paper-style dialog and toasts. */
:root {
  --navy-950: #070d1f;
  --navy-900: #0b1530;
  --navy-800: #13214a;
  --navy-700: #1c2f63;
  --gold: #c9a14a;
  --gold-light: #ecd593;
  --gold-dark: #8f6b22;
  --paper: #f7f1e1;
  --paper-2: #efe5cb;
  --paper-line: #d8c9a3;
  --ink: #2a2418;
  --ink-soft: #6b5f45;
  --crimson: #b3263a;
  --danger: #c0392b;
  --ok: #2e7d4f;

  --font-body: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
  --font-display: 'Chonburi', 'Sarabun', serif;
  --font-hand: 'Charm', 'Sarabun', cursive;

  --radius: 10px;
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .45);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 42px; padding: 0 1.1em; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; transition: transform .12s, filter .15s, background .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn--gold {
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, var(--gold-dark));
  color: #241a06; border-color: #a8832f;
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, 0 6px 16px rgba(143,107,34,.35);
}
.btn--gold:hover { filter: brightness(1.06); }
.btn--ghost { background: transparent; border-color: currentColor; opacity: .8; }
.btn--ghost:hover { opacity: 1; }
.btn--danger { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ yearbook paper dialog */
.yb-dialog {
  padding: 0; border: 0; background: transparent; max-width: min(760px, calc(100vw - 24px));
  width: 100%; max-height: calc(100dvh - 24px); overflow: visible;
}
.yb-dialog::backdrop { background: rgba(5, 10, 25, .72); backdrop-filter: blur(3px); }
.yb-dialog[open] { animation: dlg-in .35s cubic-bezier(.2,.9,.3,1.2); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(18px) scale(.97) rotate(-.6deg); } }

.paper {
  position: relative; color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.6), transparent 40%),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(150,125,70,.12) 31px 32px),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  border-radius: 6px 14px 14px 6px;
  box-shadow: var(--shadow-lg), inset 18px 0 22px -18px rgba(90,60,10,.35);
  padding: 34px 32px 22px;
  max-height: calc(100dvh - 24px); overflow: auto;
  border-left: 6px double rgba(143,107,34,.45);
}
.paper-ribbon {
  position: absolute; top: 0; right: 28px; padding: 6px 16px 10px;
  background: var(--crimson); color: #fff; font-family: var(--font-display); font-size: 13px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  box-shadow: 0 4px 10px rgba(0,0,0,.25);
}
.paper-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.paper-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 22px; color: var(--navy-800); line-height: 1.35; }
.kicker { margin: 0; font-size: 12px; letter-spacing: .08em; color: var(--ink-soft); text-transform: uppercase; }

.paper-tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--paper-line); flex-wrap: wrap; }
.paper-tabs button {
  border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--ink-soft);
  border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 600;
}
.paper-tabs button[aria-selected="true"] { color: var(--navy-800); border-color: var(--gold); }
.paper-tabs button.pulse { animation: pulse 1s 3; }
@keyframes pulse { 50% { background: rgba(201,161,74,.3); } }

.profile-grid { display: grid; grid-template-columns: 170px 1fr; gap: 24px; align-items: start; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; }
.field-grid--narrow { max-width: 460px; }

.line-field { position: relative; display: flex; flex-direction: column; font-size: 13px; color: var(--ink-soft); }
.field-hint {
  position: absolute; right: 0; top: -2px; z-index: 2; padding: 3px 8px; border-radius: 6px;
  background: #8b1d12; color: #fff; font-size: 12px; white-space: nowrap; opacity: 0; transform: translateY(-4px);
  transition: opacity .15s, transform .15s; pointer-events: none;
}
.field-hint.is-shown { opacity: 1; transform: none; }

/* phone: format guide shown while typing (highlights the detected format) */
/* position: fixed (placed by fields.js) so the scrolling paper never clips it */
.phone-guide {
  position: fixed; z-index: 10; min-width: 320px; list-style: none; margin: 0; padding: 4px 0;
  background: #fff; border-radius: 8px; box-shadow: 0 10px 28px rgba(0,0,0,.22); overflow: hidden;
}
.phone-guide li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 8px 14px; color: #333; }
.phone-guide li b { white-space: nowrap; font-weight: 400; font-size: 15px; font-family: var(--font-body); letter-spacing: .02em; }
.phone-guide li small { color: #8a8a8a; font-size: 11.5px; white-space: nowrap; }
.phone-guide li.is-active { background: #e2e2e2; }
.phone-guide li.is-active b { color: #3aa8b3; }
.phone-field.is-complete input { border-bottom-color: var(--ok); border-bottom-style: solid; }
.phone-field.is-complete > span::after { content: ' ✓'; color: var(--ok); font-weight: 700; }
.line-field input {
  border: 0; border-bottom: 1.5px dashed var(--paper-line); background: transparent;
  padding: 6px 2px 5px; font-size: 17px; color: var(--navy-900); font-family: var(--font-hand);
  outline: none; transition: border-color .15s;
}
.line-field input::placeholder { color: #b9ab88; font-family: var(--font-body); font-size: 14px; }
.line-field input:focus { border-bottom-color: var(--gold-dark); border-bottom-style: solid; }

.gender-field { grid-column: 1 / -1; border: 0; padding: 4px 0 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.gender-field legend { font-size: 13px; color: var(--ink-soft); padding: 0; margin-bottom: 6px; }
.chip-radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip-radio span {
  display: inline-block; padding: 5px 14px; border-radius: 999px; border: 1px solid var(--paper-line);
  background: rgba(255,255,255,.55); cursor: pointer; font-size: 14px;
}
.chip-radio input:checked + span { background: var(--navy-800); color: var(--gold-light); border-color: var(--navy-800); }
.chip-radio input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

.polaroid {
  margin: 0; background: #fff; padding: 10px 10px 34px; box-shadow: 0 8px 20px rgba(0,0,0,.25);
  position: relative;
}
.polaroid-photo { aspect-ratio: 1; background: linear-gradient(135deg, var(--navy-700), var(--navy-900)); display: grid; place-items: center; overflow: hidden; }
.polaroid figcaption { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-family: var(--font-hand); font-size: 18px; color: #333; }
.polaroid--slot { transform: rotate(-3deg); }
.polaroid--slot::before {
  content: ''; position: absolute; top: -10px; left: 50%; width: 70px; height: 22px; transform: translateX(-50%) rotate(2deg);
  background: rgba(236, 213, 147, .75); box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.slot-initial { font-family: var(--font-display); font-size: 56px; color: var(--gold-light); }

.consent, .claim-help { font-size: 13px; color: var(--ink-soft); margin: 14px 0 0; }
.form-error { margin: 12px 0 0; padding: 8px 12px; border-radius: 8px; background: #fbe3df; color: #8b1d12; font-size: 14px; }
.paper-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--paper-line); }
.paper-actions .btn--ghost { color: var(--ink-soft); }

@media (max-width: 640px) {
  .paper { padding: 28px 18px 16px; }
  .profile-grid { grid-template-columns: 1fr; }
  .polaroid--slot { width: 130px; margin: 0 auto; }
  .field-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ toast */
.toast-host { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 3000; display: grid; gap: 8px; pointer-events: none; }
.toast {
  padding: 10px 18px; border-radius: 999px; background: #22252c; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  font-size: 14px; animation: toast-in .25s ease-out; transition: opacity .3s, transform .3s; border: 1px solid #3a3e48;
}
.toast--ok { border-color: var(--ok); }
.toast--error { border-color: var(--danger); background: #3a1d1d; }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------------ image cropper (cropper.js) */
.crop-dialog { padding: 0; border: 0; background: transparent; width: min(420px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); overflow: visible; }
.crop-dialog::backdrop { background: rgba(5, 8, 16, .78); backdrop-filter: blur(3px); }
.crop-card {
  background: #1b1d22; color: #e8eaee; border: 1px solid #33373f; border-radius: 18px; box-shadow: 0 30px 70px rgba(0,0,0,.55);
  padding: 16px; font-family: var(--font-body); max-height: calc(100dvh - 20px); overflow: auto;
}
.crop-head h3 { margin: 0; font-size: 17px; }
.crop-head p { margin: 2px 0 12px; font-size: 12.5px; color: #979dab; }
.crop-stage {
  position: relative; width: 100%; aspect-ratio: 1 / 1.02; overflow: hidden; border-radius: 12px; touch-action: none;
  cursor: grab; outline: none; user-select: none;
  background: repeating-conic-gradient(#2a2d34 0 25%, #23262c 0 50%) 0 0 / 22px 22px;
}
.crop-stage:focus-visible { box-shadow: 0 0 0 2px var(--gold); }
.crop-stage.is-dragging { cursor: grabbing; }
.crop-img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop-window { position: absolute; box-shadow: 0 0 0 2000px rgba(12, 14, 18, .66); pointer-events: none; }
.crop-dialog--pin .crop-window { border-radius: 50%; }
.crop-dialog--polaroid .crop-window { border-radius: 2px; }
.crop-pin-frame {
  position: absolute; pointer-events: none; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 6px solid var(--c); box-shadow: 0 8px 22px rgba(0,0,0,.45);
}
.crop-pin-badge {
  position: absolute; width: 38px; height: 38px; border-radius: 50%; background: #fff; border: 3px solid var(--c);
  display: grid; place-items: center; font-size: 18px; pointer-events: none;
}
.crop-polaroid-frame {
  position: absolute; pointer-events: none; border-style: solid; border-color: #fff; box-shadow: 0 10px 26px rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.crop-polaroid-frame span { position: absolute; bottom: -36px; font-family: var(--font-hand); font-size: 20px; color: #333; }
.crop-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #979dab; font-size: 14px; }
.crop-controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.crop-zoom { flex: 1; accent-color: var(--gold); }
.crop-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid #33373f; background: #23262c; color: #e8eaee;
  font-size: 18px; cursor: pointer; flex: none;
}
.crop-btn:hover { background: #2c3037; }
.crop-btn--text { width: auto; padding: 0 12px; font-size: 13px; }
.crop-preview-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: #23262c; font-size: 12.5px; color: #979dab; }
.crop-preview-row .yb-pin { margin: 6px 10px 12px 0; }
.crop-preview-row .yb-pin-body canvas { width: 40px; height: 40px; border-radius: 50%; transform: rotate(45deg); border: 2px solid #fff; }
.crop-mini-polaroid { background: #fff; padding: 4px 4px 14px; box-shadow: 0 4px 10px rgba(0,0,0,.4); transform: rotate(-3deg); }
.crop-mini-polaroid canvas { display: block; width: 64px; height: 64px; }
.crop-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn-plain { border: 1px solid #33373f; background: #23262c; color: #e8eaee; border-radius: 999px; padding: 0 18px; min-height: 42px; cursor: pointer; font-weight: 600; }
.btn-plain:hover { background: #2c3037; }

/* ------------------------------------------------------------------ profile photo on the polaroid */
.polaroid--pick { display: block; cursor: pointer; transition: transform .15s; }
.polaroid--pick:hover { transform: rotate(-1.5deg) scale(1.02); }
.polaroid--pick:focus-within { outline: 2px solid var(--gold); outline-offset: 4px; }
.polaroid-photo { position: relative; }
.polaroid-photo img[data-avatar-img] { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot-pick {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); white-space: nowrap;
  padding: 4px 12px; border-radius: 999px; background: rgba(5,10,25,.72); color: #fff; font-size: 13px;
  font-family: var(--font-body); opacity: .92; transition: opacity .15s;
}
.polaroid--pick:not(:hover) img:not([hidden]) ~ .slot-pick { opacity: 0; }
.avatar-adjust { margin: 10px 0 0 4px; }

.link-btn { border: 0; background: none; padding: 4px 2px; color: var(--navy-700); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }
.link-btn:hover { color: var(--crimson); }
.paper-actions { align-items: center; }
.forgot-btn { margin-right: auto; }
.line-field--wide { grid-column: 1 / -1; }
.line-field--wide input { font-family: var(--font-body); font-size: 15px; }

/* forgot-password states */
.reset-body { margin-top: 8px; }
.reset-status { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 12px; margin: 6px 0 10px; }
.reset-status b { display: block; font-size: 16px; color: var(--navy-800); }
.reset-status small { color: var(--ink-soft); font-size: 13px; }
.reset-icon { font-size: 30px; line-height: 1; }
.reset-status--pending { background: rgba(201,161,74,.16); border: 1px dashed var(--gold-dark); }
.reset-status--pending .reset-icon { animation: hourglass 2s ease-in-out infinite; }
.reset-status--ok { background: rgba(46,125,79,.12); border: 1px solid rgba(46,125,79,.4); }
.reset-status--bad { background: rgba(192,57,43,.1); border: 1px solid rgba(192,57,43,.35); }
@keyframes hourglass { 50% { transform: rotate(180deg); } }
