/* ============================================================================
   Gifts (release 2). The card for the gift steps and the lines added to the end card.
   Every look comes from the approved mock (gift-mock/index.html): the game's own paper, wobble edge, flat shadow, coral and lavender.
   It reuses .paper .pw .cta from index.html. Every rule starts with #gift-card, #gift-signin or .g-, so nothing here can reach the game.
   Arabic reads right to left, English left to right: the rules use start and end, never left and right (except the number field, which is always LTR).

   THE TYPE SYSTEM. One table, defined once below. No other font-size is written in this file.
     role                          size  weight  colour
     hero line (the gift itself)    34    900    indigo
     card title                     26    900    indigo
     numbers (points, code digits)  24    900    indigo
     the code text                  26    900    cream on indigo
     main button                    20    900    indigo on coral
     field text                     20    700    indigo
     secondary button               15    700    ink on lavender
     label                          14    700    indigo at 70 percent
     explanation, row value         14    400/700 indigo (a row value is 700)
     small print                    12.5  400    indigo at 60 percent
     text link under a button       13    700    indigo, underlined
     error line                     13    700    indigo, on tan, with a small mark
   Three weights only: 400, 700, 900.
   THE FLOOR. On a small phone the stage is drawn at about 0.69 of its size (--kk). Nothing may render under 10.5 CSS px, so the small sizes
   are lifted to 10.5 / --kk logical px, and the big sizes are lifted by half of the same factor, so the six roles stay clearly different.
   THE ALIGNMENT. Everything in a card starts on the START edge. Only the content of the lavender ticket, the code inside its dark block and
   the label inside a button are centred. A link under a full width button is centred under it.
   THE RHYTHM. 4, 8, 12, 16, 24 only.
   ========================================================================== */

#gift-card, #gift-signin, .g-hint {
  --gz: max(1, calc(10.5 / (12.5 * var(--kk, 1))));                 /* 1 on a computer, about 1.2 on a 667 x 375 phone */
  --gzl: calc(1 + (var(--gz) - 1) * 0.5);                           /* the big sizes grow by half as much */
  --g-floor: calc(10.5px / var(--kk, 1));
  --g-hero: calc(34px * var(--gzl));
  --g-title: calc(26px * var(--gzl));
  --g-num: calc(24px * var(--gzl));
  --g-code: calc(26px * var(--gzl));
  --g-btn: calc(20px * var(--gzl));
  --g-field: calc(20px * var(--gzl));
  --g-btn2: max(15px, var(--g-floor));
  --g-label: max(14px, var(--g-floor));
  --g-ex: max(14px, var(--g-floor));
  --g-link: max(13px, var(--g-floor));
  --g-err: max(13px, var(--g-floor));
  --g-fine: max(12.5px, var(--g-floor));
  --g-w1: 400;
  --g-w2: 700;
  --g-w3: 900;
  --g-ink: #321F61;
  --g-ink70: rgba(50, 31, 97, .7);
  --g-ink60: rgba(50, 31, 97, .6);
  --g-rule: 2px solid rgba(17, 17, 17, .08);
  --g-1: 4px;
  --g-2: 8px;
  --g-3: 12px;
  --g-4: 16px;
  --g-5: 24px;
}

/* ---------- the link on the start card ---------- */
#gift-signin { margin: 8px 8px 0 0; font-size: var(--g-ex); font-weight: var(--g-w1); line-height: 1.6; color: var(--g-ink); }
html[lang="en"] #gift-signin { margin: 8px 0 0 8px; }
#gift-signin button { font-size: var(--g-ex) !important; font-weight: var(--g-w1) !important; line-height: 1.6; color: var(--g-ink) !important; position: relative; }
#gift-signin u, .g-lnk { font-weight: var(--g-w2); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
/* a finger needs 44 CSS px: the box is bigger than the words, and invisible */
#gift-signin button::after { content: ""; position: absolute; inset-inline: -8px; top: 50%; height: max(100%, var(--tb)); transform: translateY(-50%); }

/* ---------- the card ---------- */
#gift-card {
  right: calc(30px + var(--sr)); top: calc(26px + var(--st) * .5); width: var(--ew);
  transform: rotate(-1.6deg); transform-origin: 100% 0;
  pointer-events: auto; will-change: transform;
  --gs: 1;
}
#gift-card.pop { animation: giftPop .42s var(--pop) backwards; }
@keyframes giftPop { from { opacity: 0; transform: translateY(26px) rotate(-1.6deg) scale(.96); } to { opacity: 1; transform: translateY(0) rotate(-1.6deg) scale(1); } }
/* a card taller than the stage is shrunk to fit (gifts.js sets --gs) */
#gift-card.fit { transform: rotate(-1.6deg) scale(var(--gs)); }
/* one inner padding for every state, and one text edge: the start edge */
#gift-card .g-sheet { padding: var(--g-4) 20px 20px; text-align: start; }
#gift-card a, #gift-card input, #gift-card button { pointer-events: auto; }
#gift-card .num { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
#gift-card .nw { white-space: nowrap; }
#ui.gift-open #end-card.gifted { display: none; }
/* on the start card the title card gives way to the sign-in card: both would need the same room on a 4:3 screen */
#ui.gift-open.gift-title #title-card { visibility: hidden; }
#ui.gift-open.gift-title #btn-start { pointer-events: none; }

/* ---------- the head of a card: the title, and under it its explanation ---------- */
#gift-card .g-head { margin: 0 0 var(--g-4); }
#gift-card .g-title { margin: 0; font-size: var(--g-title); font-weight: var(--g-w3); line-height: 1.2; color: var(--g-ink); }
/* explanation: what a gift gives, the line under a title, the helper under a field */
#gift-card .g-ex { margin: 0; font-size: var(--g-ex); font-weight: var(--g-w1); line-height: 1.6; color: var(--g-ink); text-wrap: pretty; }
#gift-card .g-title + .g-ex { margin-top: var(--g-1); }
#gift-card .g-ex + .g-ex { margin-top: var(--g-2); }
#gift-card .g-ex.g-val { margin-top: 0; font-weight: var(--g-w2); }
#gift-card .g-ex b { font-weight: var(--g-w2); }
/* the label of a field, the label of a row, the small word above the hero line */
#gift-card .g-label { display: block; margin: 0 0 var(--g-1); font-size: var(--g-label); font-weight: var(--g-w2); line-height: 1.4; color: var(--g-ink70); }
/* small print: the rules, the privacy line, the timer. Links inside it are bold and underlined. */
#gift-card .g-fine { margin: 0; font-size: var(--g-fine); font-weight: var(--g-w1); line-height: 1.5; color: var(--g-ink60); text-wrap: pretty; }
#gift-card .g-fine .g-lnk, #gift-card .g-fine b { color: var(--g-ink); font-weight: var(--g-w2); }
#gift-card .g-field + .g-fine, #gift-card .g-err + .g-fine { margin-top: var(--g-2); }
#gift-card .g-block { margin: var(--g-3) 0 0; }
#gift-card .g-block .g-fine + .g-fine { margin-top: var(--g-1); }
/* the reminder of the gift on the phone step: one quiet line, ruled off like a row of the end card */
#gift-card .g-chip { margin: 0 0 var(--g-3); padding: 0 0 var(--g-3); border-bottom: var(--g-rule); }
/* a text link under a button (and the resend link inside the timer). Centred under a full width button. */
#gift-card .g-lnk { color: var(--g-ink); }
#gift-card button.g-lnk { background: none; font-size: var(--g-link); font-weight: var(--g-w2); line-height: 1.4; position: relative; }
#gift-card .g-fine button.g-lnk { font-size: var(--g-fine); line-height: 1.5; }
#gift-card button.g-lnk::after { content: ""; position: absolute; inset-inline: -12px; top: -2px; height: max(calc(100% + 4px), var(--tb)); transform: none; }
#gift-card .g-linkrow { margin: var(--g-3) 0 0; text-align: center; }

/* ---------- the buttons: the same main button in every state, and the same secondary ---------- */
#gift-card .cta.full { display: block; width: 100%; }
#gift-card .cta.full .paper { text-align: center; padding: 10px 16px 12px; font-size: var(--g-btn); font-weight: var(--g-w3); line-height: 1.25; }
#gift-card .g-btnrow { margin: var(--g-4) 0 0; }
#gift-card .g-sec { margin: var(--g-2) 0 0; }
#gift-card .cta.full .paper.g-pill { display: flex; align-items: center; justify-content: center; gap: var(--g-2); padding: 8px 16px 10px; font-size: var(--g-btn2); font-weight: var(--g-w2); color: var(--ink); }
#gift-card .cta.full .paper.g-pill.lav { background: var(--lav); }
/* the hit boxes of two stacked buttons must not meet: the main one reaches out evenly, the secondary one only downward */
#gift-card .g-sec .cta::after { top: 0; transform: none; height: max(100%, var(--tb)); }
#gift-card .cta.wait { pointer-events: none; opacity: .45; }
#gift-card.g-busy .cta { opacity: .6; pointer-events: none; }
#gift-card .cta { transition: transform .18s var(--pop), filter .18s, opacity .25s; }
#gift-card a.cta { display: block; text-decoration: none; color: inherit; }

/* ---------- rows: a label on the start edge, a value on the end edge, as the game's end card has them ---------- */
#gift-card .g-row { display: flex; justify-content: space-between; align-items: baseline; padding: var(--g-1) 0; }
#gift-card .g-rows { margin: var(--g-3) 0 0; }
#gift-card .g-rows .g-row { border-bottom: var(--g-rule); }
#gift-card .g-rows .g-row:last-child { border-bottom: 0; }
#gift-card .g-rl { font-size: var(--g-label); font-weight: var(--g-w2); line-height: 1.4; color: var(--g-ink70); }
#gift-card .g-rv { padding-inline-start: var(--g-3); font-size: var(--g-ex); font-weight: var(--g-w2); line-height: 1.4; color: var(--g-ink); text-align: end; }
#gift-card .g-rn { font-size: var(--g-num); font-weight: var(--g-w3); line-height: 1.1; color: var(--g-ink); }
#gift-card .g-pts { padding: 0 0 var(--g-2); }

/* ---------- the gift ticket (state 2): the only centred body content, with the code block ---------- */
#gift-card .g-ticket { margin: 0; }
#gift-card .g-ticket .paper { padding: var(--g-3); text-align: center; }
#gift-card .g-eyebrow { font-size: var(--g-label); font-weight: var(--g-w2); line-height: 1.4; color: var(--g-ink70); }
#gift-card .g-big { font-size: var(--g-hero); font-weight: var(--g-w3); line-height: 1.1; color: var(--g-ink); }
#gift-card .g-sub { margin-top: var(--g-1); font-size: var(--g-ex); font-weight: var(--g-w1); line-height: 1.5; color: var(--g-ink); }

/* ---------- the rail of the three steps: thin and quiet, the game's own rail ---------- */
#gift-card .g-rail { position: relative; margin: var(--g-3) 0 0; height: calc(var(--g-fine) * 1.5 + 12px); }
#gift-card .g-track { position: absolute; inset-inline: 0; top: 3px; height: 4px; background: var(--tan); border-radius: 2px; }
#gift-card .g-fill { position: absolute; inset-inline-start: 0; top: 3px; height: 4px; background: var(--lav); border-radius: 2px; }
#gift-card .g-tick { position: absolute; top: 0; width: 2px; height: 10px; background: var(--ink); opacity: .2; }
#gift-card .g-tl { position: absolute; top: 12px; font-size: var(--g-fine); font-weight: var(--g-w1); line-height: 1.5; color: var(--g-ink60); white-space: nowrap; }
#gift-card .g-tl.on { font-weight: var(--g-w2); color: var(--g-ink); }
#ui[dir="rtl"] #gift-card .g-tick, #ui[dir="rtl"] #gift-card .g-tl { transform: translateX(50%); }
#ui[dir="ltr"] #gift-card .g-tick, #ui[dir="ltr"] #gift-card .g-tl { transform: translateX(-50%); }
/* the last mark sits on the end edge of the card: its label ends there, so the end edge stays one line */
#ui #gift-card .g-tl.last, #ui #gift-card .g-tick.last { transform: none; inset-inline-start: auto; inset-inline-end: 0; }
#gift-card .g-next { margin: var(--g-2) 0 0; }

/* ---------- fields: the game's paper, not a web form ---------- */
#gift-card .g-field { display: flex; direction: ltr; gap: var(--g-2); }
#gift-card .g-field .paper { font-size: var(--g-field); font-weight: var(--g-w2); color: var(--g-ink); padding: 10px 10px 12px; line-height: 1.2; background: var(--tan); }
#gift-card .g-cc { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; font-weight: var(--g-w2); }
#gift-card .g-cc svg { display: block; }
#gift-card input.g-in {
  flex: 1 1 auto; min-width: 0; width: 100%; box-sizing: border-box; border: 0; border-radius: 0; margin: 0; outline: none; font: inherit; font-size: var(--g-field); font-weight: var(--g-w2); color: var(--g-ink);
  background: var(--tan); text-align: left; direction: ltr; letter-spacing: .02em; padding: 10px 10px 12px; line-height: 1.2; caret-color: var(--coral); touch-action: manipulation;
  -webkit-user-select: text; user-select: text; -webkit-appearance: none; appearance: none;
}
#gift-card input.g-in::placeholder { color: rgba(50, 31, 97, .42); opacity: 1; }
#gift-card input.g-in:focus { background: var(--cream); box-shadow: inset 0 -4px 0 var(--coral); }
#gift-card .g-field.g-single { direction: inherit; }
#gift-card .g-field.g-single input.g-in { text-align: start; direction: inherit; letter-spacing: 0; }
/* the six boxes: one group, its first box on the start edge and its last on the end edge */
#gift-card .g-boxes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); direction: ltr; gap: var(--g-2); margin: 0; }
#gift-card input.g-box {
  width: 100%; height: 52px; box-sizing: border-box; border: 0; border-radius: 0; margin: 0; padding: 0; outline: none; font: inherit; font-size: var(--g-num); font-weight: var(--g-w3); color: var(--g-ink); text-align: center;
  background: var(--tan); box-shadow: inset 0 0 0 2px rgba(50, 31, 97, .18); caret-color: var(--coral); touch-action: manipulation;
  -webkit-user-select: text; user-select: text; -webkit-appearance: none; appearance: none;
}
#gift-card input.g-box:focus { background: var(--cream); box-shadow: inset 0 0 0 2px rgba(50, 31, 97, .18), inset 0 -5px 0 var(--coral); }
#gift-card .g-boxes + .g-fine { margin-top: var(--g-2); }
#gift-card .g-timer.ready { color: var(--g-ink); }

/* ---------- an error: one style in every state, directly under the field or the boxes. Coral stays for the main action. ---------- */
#gift-card .g-err { margin: var(--g-2) 0 0; }
#gift-card .g-err:empty { display: none; }
#gift-card .g-err .paper, .g-hint.g-note {
  display: flex; align-items: flex-start; gap: var(--g-2); background: var(--tan); color: var(--g-ink); padding: 6px 10px 8px; font-size: var(--g-err); font-weight: var(--g-w2); line-height: 1.4; text-align: start;
}
/* the mark: a small indigo disc with a cream exclamation mark, drawn with gradients so it needs no font */
#gift-card .g-err .paper::before, .g-hint.g-note::before {
  content: ""; flex: 0 0 auto; width: 16px; height: 16px; margin-top: 1px; border-radius: 50%;
  background: radial-gradient(circle at 50% 73%, #FFF7E9 1.3px, transparent 1.6px), linear-gradient(#FFF7E9, #FFF7E9) 50% 26% / 2.4px 6px no-repeat, #321F61;
}

/* ---------- the claimed code (state 6) ---------- */
#gift-card .g-code { margin: 0; }
#gift-card .g-code .paper { padding: var(--g-3); text-align: center; font-size: var(--g-code); font-weight: var(--g-w3); line-height: 1.2; letter-spacing: .05em; direction: ltr; white-space: nowrap; background: var(--indigo); color: var(--cream); }
#gift-card .g-code + .g-ex { margin-top: var(--g-3); }
#gift-card [data-gifts-select] { -webkit-user-select: text; user-select: text; }

/* ---------- while a field has focus on a phone: the keyboard covers half the screen ----------
   The card goes to the top of the stage and keeps only the field and the button. The corner buttons and the end-card foot step aside. */
#ui.gtyping #btn-mute, #ui.gtyping #btn-fs { visibility: hidden; }
#ui.gtyping #gift-card { top: calc(8px + var(--st) * .5); }
#gift-card.typing .g-hide-typing { display: none; }
#gift-card.typing .g-sheet { padding-top: var(--g-3); padding-bottom: var(--g-4); }
#gift-card.typing .g-btnrow { margin-top: var(--g-3); }

/* ---------- the lines added to the end card (states 1 and 7, and an error that is not a gift) ----------
   The text edge is the one of the rows above it (their 4 px of padding), so the rows are not touched. */
.g-hint { display: flex; align-items: center; gap: var(--g-2); text-align: start; font-size: var(--g-ex); font-weight: var(--g-w1); line-height: 1.6; color: var(--g-ink); margin: var(--g-3) 4px 0; }
.g-hint svg { flex: 0 0 auto; }
.g-hint .nw { white-space: nowrap; }
.g-hint.g-note { margin: var(--g-3) 0 0; }

/* ---------- a phone (#ui.phone, set by game.js): the stage is 400 logical px high and drawn larger. No gift text is under 12 CSS px, and the card is
   tightened (spacing only: the words, the order and the look are the same) so it fits the 400 high picture with nothing cut. ---------- */
#ui.phone #gift-card, #ui.phone #gift-signin { --gz: max(1, calc(12.8 / (12.5 * var(--kk, 1)))); --g-floor: calc(12.8px / var(--kk, 1)); }
/* the lines inside the end card are drawn at the end card's own scale (--cs), so their floor is lifted by it */
#ui.phone .g-hint { --gz: max(1, calc(12.5 / (12.5 * var(--kk, 1) * var(--cs, 1)))); --g-floor: calc(12.5px / (var(--kk, 1) * var(--cs, 1))); }
#ui.phone #gift-card { top: calc(14px + var(--st) * .5); }
#ui.phone #gift-card .g-sheet { padding: 10px 18px 12px; }
#ui.phone #gift-card .g-head { margin-bottom: 6px; }
#ui.phone #gift-card .g-ex { line-height: 1.4; }
#ui.phone #gift-card .g-fine { line-height: 1.3; }
#ui.phone #gift-card .g-ex + .g-ex { margin-top: 4px; }
#ui.phone #gift-card .g-block { margin-top: 6px; }
#ui.phone #gift-card .g-block .g-fine + .g-fine { margin-top: 2px; }
#ui.phone #gift-card .g-btnrow { margin-top: 8px; }
#ui.phone #gift-card .g-sec { margin-top: 6px; }
#ui.phone #gift-card .g-rail { margin-top: 6px; }
#ui.phone #gift-card .g-next { margin-top: 4px; }
#ui.phone #gift-card .g-rows { margin-top: 6px; }
#ui.phone #gift-card .g-row { padding: 2px 0; }
#ui.phone #gift-card .g-pts { padding-bottom: 4px; }
#ui.phone #gift-card .g-chip { margin-bottom: 6px; padding-bottom: 6px; }
#ui.phone #gift-card .g-ticket .paper { padding: 8px 12px; }
#ui.phone #gift-card .g-code .paper { padding: 8px 12px; }
#ui.phone #gift-card .g-code + .g-ex { margin-top: 6px; }
#ui.phone #gift-card .cta.full .paper { padding: 7px 14px 9px; }
#ui.phone #gift-card .cta.full .paper.g-pill { padding: 5px 14px 7px; }
#ui.phone #gift-card .g-field .paper, #ui.phone #gift-card input.g-in { padding: 7px 10px 9px; }
#ui.phone #gift-card input.g-box { height: 44px; }
#ui.phone #gift-card .g-linkrow { margin-top: 6px; }
#ui.phone #gift-card .g-err { margin-top: 4px; }
#ui.phone #gift-card .g-err .paper { padding: 4px 10px 6px; }

@media (prefers-reduced-motion: reduce) {
  #gift-card.pop { animation: none; }
  #gift-card .cta { transition: none; }
}
