/* =========================================================
   Admit Two — 約會車票  |  Design System
   Elegant · Romantic · Vintage ticket
   Mobile-first
   ========================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* paper & ink */
  --paper:      #F4F0E6;   /* warm cream background */
  --paper-2:    #EDE8DA;
  --ink:        #2C2A24;   /* near-black warm ink */
  --ink-soft:   #6B675C;
  --hairline:   #D8D2C2;

  /* ticket (sage vintage) */
  --ticket:     #AEB79E;   /* muted sage */
  --ticket-2:   #9EA98C;
  --ticket-ink: #35392E;
  --ticket-line:#7E886C;

  /* romantic accents */
  --rose:       #C4877F;   /* dusty rose */
  --burgundy:   #7C3B3B;
  --gold:       #B49A5E;

  /* ui */
  --btn:        #26241E;
  --btn-ink:    #F4F0E6;
  --radius:     16px;
  --radius-sm:  10px;
  --shadow:     0 18px 50px -20px rgba(44,42,36,.45);
  --shadow-sm:  0 8px 24px -12px rgba(44,42,36,.4);

  --sans:   "Microsoft JhengHei", "微軟正黑體", "PingFang TC", "Noto Sans TC", "Heiti TC", sans-serif;
  --serif:  var(--sans);
  --body:   var(--sans);
  --hand:   var(--sans);
  --script: var(--sans);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--body);
  background:
    radial-gradient(120% 90% at 50% -10%, #FBF8F0 0%, var(--paper) 45%, var(--paper-2) 100%) fixed;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* subtle paper grain */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

/* ---------- Layout shell ---------- */
.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 40px;
}
.stage {
  width: 100%;
  max-width: 440px;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.brand {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: lowercase;
  font-size: 15px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.footer {
  margin-top: 28px;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ink-soft);
  opacity: .7;
  text-align: center;
}

/* ---------- Screens ---------- */
.screen {
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: rise .7s cubic-bezier(.2,.7,.2,1) both;
}
.screen.is-active { display: flex; }
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ---------- Typography helpers ---------- */
.eyebrow {
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: .34em;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
.display {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.08;
  font-size: clamp(30px, 8.5vw, 40px);
  letter-spacing: -.01em;
}
.display .accent { font-style: italic; color: var(--burgundy); }
.lede {
  font-size: 19px;
  color: var(--ink-soft);
  max-width: 30ch;
  margin: 14px auto 0;
}
.script-name {
  font-family: var(--script);
  color: var(--burgundy);
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--body);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--btn-ink);
  background: var(--btn);
  border: none;
  border-radius: 999px;
  padding: 16px 30px;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .25s ease, background .25s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  box-shadow: none;
}
.btn--rose { background: var(--rose); }
.btn--block { display: block; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.hint { font-size: 14px; color: var(--ink-soft); margin-top: 12px; letter-spacing: .02em; }

/* =========================================================
   The Question — Yes / runaway No
   ========================================================= */
.q-meta {
  margin: 18px 0 8px;
  font-size: 16px;
  color: var(--ink-soft);
  letter-spacing: .02em;
}
.q-meta b { color: var(--ink); font-weight: 600; }
.q-actions {
  position: relative;
  width: 100%;
  min-height: 130px;
  margin-top: 26px;
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.btn-yes { min-width: 190px; }
.btn-no {
  position: relative;
  white-space: nowrap;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), left .28s ease, top .28s ease;
  z-index: 5;
}
.btn-no.is-loose {
  position: fixed;
  margin: 0;
  transition: left .35s cubic-bezier(.34,1.4,.5,1), top .35s cubic-bezier(.34,1.4,.5,1), transform .2s;
}

/* =========================================================
   Food picker
   ========================================================= */
.foods {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
  margin: 22px 0 0;
  padding: 16px 14px;
  background: rgba(255,255,255,.42);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
.chip {
  font-family: var(--body);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--hairline);
  border-radius: 999px;
  padding: 9px 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform .18s ease, background .2s, border-color .2s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--ticket-2); transform: translateY(-1px); }
.chip.is-on {
  background: var(--ticket);
  border-color: var(--ticket-2);
  color: #2b2f26;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.chip.is-random-pick {
  animation: pop .5s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes pop { 0%{transform: scale(.4); opacity: 0} 60%{transform: scale(1.12)} 100%{transform: scale(1); opacity: 1} }

.random-box {
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  border: 1.5px dashed var(--hairline);
  border-radius: var(--radius);
  background: rgba(255,255,255,.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.random-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.random-row .label { font-size: 17px; text-align: left; }
.random-row .label small { display:block; font-size: 13px; color: var(--ink-soft); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.stepper .count { width: 34px; text-align: center; font-size: 20px; font-weight: 700; font-family: var(--serif); }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--hairline); transition: .25s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; height: 24px; width: 24px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .25s; box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.switch input:checked + .track { background: var(--rose); }
.switch input:checked + .track::before { transform: translateX(22px); }
.count-tag { font-size: 14px; color: var(--ink-soft); margin-top: 4px; min-height: 20px; }

/* =========================================================
   TICKET
   ========================================================= */
.ticket-wrap {
  /* 主題色（預設：鼠尾草綠）*/
  --tk:  #AEB79E;
  --tk2: #9EA98C;
  --ti:  #35392E;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  perspective: 1200px;
}
.ticket-wrap[data-theme="sage"]     { --tk:#AEB79E; --tk2:#9EA98C; --ti:#35392E; }
.ticket-wrap[data-theme="rose"]     { --tk:#E1B6AF; --tk2:#D29E96; --ti:#4A2E2B; }
.ticket-wrap[data-theme="blush"]    { --tk:#EEC7CD; --tk2:#E3AFB8; --ti:#4A2E34; }
.ticket-wrap[data-theme="blue"]     { --tk:#A9BCC6; --tk2:#92A9B5; --ti:#293941; }
.ticket-wrap[data-theme="lavender"] { --tk:#BEB4CF; --tk2:#A99CC1; --ti:#372E46; }
.ticket-wrap[data-theme="gold"]     { --tk:#E5D6AF; --tk2:#D6C494; --ti:#4A3E26; }
.ticket {
  position: relative;
  width: 100%;
  max-width: 400px;
  display: flex;
  filter: drop-shadow(0 20px 40px rgba(44,42,36,.28));
  animation: fadeIn .6s both;
}
/* main body */
.ticket__main {
  position: relative;
  flex: 1;
  display: flex;
  background: linear-gradient(160deg, var(--tk) 0%, var(--tk2) 100%);
  color: var(--ti);
  border-radius: 14px 4px 4px 14px;
  padding: 18px 16px 18px 0;
  min-height: 200px;
  overflow: hidden;
}
.ticket__main::after { /* aged inner border */
  content:""; position:absolute; inset:8px; border:1px solid rgba(53,57,46,.28);
  border-radius: 8px; pointer-events:none;
}
.ticket__spine {
  writing-mode: vertical-rl;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: .22em;
  font-size: 19px;
  text-align: center;
  padding: 4px 3px;
  border-right: 1px dashed rgba(0,0,0,.28);
  margin: 6px 4px 6px 10px;
  color: var(--ti);
}
.ticket__content { flex: 1; padding: 4px 6px; text-align: left; }
.tk-eyebrow {
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: 10px;
  font-weight: 700;
  opacity: .7;
}
.tk-title {
  font-family: var(--hand);
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: .01em;
  margin: 2px 0 2px;
  min-height: 32px;
  font-weight: 700;
}
.tk-by { font-family: var(--hand); font-size: 17px; opacity: .85; margin-bottom: 10px; font-weight: 600; }
.tk-grid { display: flex; gap: 18px; margin-bottom: 10px; }
.tk-field .lbl {
  display: block;
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: 9px;
  font-weight: 700;
  opacity: .65;
}
.tk-field .val {
  font-family: var(--hand);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: .01em;
  min-height: 22px;
  display: inline-block;
}
.tk-note .val {
  font-size: 17px;
  font-weight: 600;
  display: block;
  white-space: normal;
  line-height: 1.5;
  word-break: break-word;
}

/* writing cursor / pen */
.write .pen {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--ticket-ink);
  margin-left: 1px;
  vertical-align: -2px;
  animation: blink .8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0 } }
.write .char { opacity: 0; }
.write .char.show { opacity: 1; animation: inkin .18s ease both; }
@keyframes inkin { from { opacity: 0; filter: blur(1px); transform: translateY(1px) } to { opacity: 1; filter: blur(0); transform: none } }

/* ---------- Stub (tear-off) ---------- */
.ticket__stub {
  position: relative;
  width: 74px;
  flex: none;
  background: linear-gradient(160deg, var(--tk) 0%, var(--tk2) 100%);
  color: var(--ti);
  border-radius: 4px 14px 14px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: grab;
  transform-origin: left center;
  transition: transform .5s cubic-bezier(.5,0,.2,1), opacity .5s;
  touch-action: none;
}
.ticket__stub::after {
  content:""; position:absolute; top:8px; bottom:8px; right:8px; left:6px;
  border:1px solid rgba(53,57,46,.28); border-radius: 8px; pointer-events:none;
}
/* perforation between main and stub */
.perf {
  position: relative;
  width: 0;
  flex: none;
  border-left: 2px dashed rgba(244,240,230,.85);
  margin: 6px 0;
  z-index: 3;
}
.perf::before, .perf::after {
  content:""; position:absolute; left:-11px; width:20px; height:20px;
  background: var(--paper); border-radius: 50%;
}
.perf::before { top: -13px; }
.perf::after  { bottom: -13px; }

.stub-arrow {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--ti);
  display: grid; place-items: center;
  font-size: 15px;
  animation: nudge 1.4s ease-in-out infinite;
}
@keyframes nudge { 0%,100%{ transform: translateX(0) } 50%{ transform: translateX(4px) } }
.stub-label {
  writing-mode: vertical-rl;
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: .22em;
  font-size: 10px;
  font-weight: 700;
  opacity: .75;
}

/* torn state */
.ticket.torn .ticket__stub {
  transform: translateX(30px) rotate(10deg);
  opacity: 0;
  pointer-events: none;
}
.ticket.torn .ticket__main { border-radius: 14px; }
.ticket.torn .perf { opacity: 0; }

.tear-hint {
  margin-top: 16px;
  font-family: var(--body);
  font-size: 16px;
  color: var(--ink-soft);
  letter-spacing: .02em;
  animation: fadeIn .6s both, floaty 2.4s ease-in-out infinite;
}
@keyframes floaty { 0%,100%{ transform: translateY(0) } 50%{ transform: translateY(-4px) } }

/* =========================================================
   Audio bar (revealed after tear) — horizontal, fig.2
   ========================================================= */
.audio-bar {
  width: 100%;
  max-width: 400px;
  margin-top: 18px;
  background: linear-gradient(160deg, var(--tk) 0%, var(--tk2) 100%);
  color: var(--ti);
  border-radius: 12px;
  padding: 14px 20px;
  display: none;
  align-items: center;
  gap: 14px;
  filter: drop-shadow(0 16px 30px rgba(44,42,36,.25));
  position: relative;
  /* 真實車票：左右兩側半圓齒孔 */
  -webkit-mask:
    radial-gradient(circle 6px at 0px 9px, #0000 6px, #000 6.5px) 0 0 / 100% 18px repeat-y,
    radial-gradient(circle 6px at 100% 9px, #0000 6px, #000 6.5px) 0 0 / 100% 18px repeat-y;
  -webkit-mask-composite: source-in;
          mask:
    radial-gradient(circle 6px at 0px 9px, #0000 6px, #000 6.5px) 0 0 / 100% 18px repeat-y,
    radial-gradient(circle 6px at 100% 9px, #0000 6px, #000 6.5px) 0 0 / 100% 18px repeat-y;
          mask-composite: intersect;
}
.audio-bar::after {
  content:""; position:absolute; inset:7px; border:1px solid rgba(53,57,46,.28);
  border-radius: 9px; pointer-events:none;
}
.audio-bar.show {
  display: flex;
  animation: tearIn .7s cubic-bezier(.34,1.3,.5,1) both;
}
@keyframes tearIn {
  from { opacity: 0; transform: translateY(-14px) rotate(-3deg) scale(.9); }
  to   { opacity: 1; transform: none; }
}
.play-btn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  border: none;
  background: var(--ti);
  color: var(--tk);
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s;
}
.play-btn:active { transform: scale(.92); }
.wave {
  flex: 1;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}
.wave span {
  flex: 1;
  min-width: 2px;
  height: 30%;
  background: rgba(53,57,46,.55);
  border-radius: 2px;
  transform-origin: center;
}
.audio-bar.playing .wave span { animation: bars .9s ease-in-out infinite; }
.wave span:nth-child(3n)   { animation-delay: .1s }
.wave span:nth-child(3n+1) { animation-delay: .25s }
.wave span:nth-child(4n)   { animation-delay: .4s }
@keyframes bars { 0%,100%{ transform: scaleY(.35) } 50%{ transform: scaleY(1.6) } }
.audio-time { font-family: var(--body); font-size: 13px; font-weight: 600; opacity: .7; min-width: 34px; text-align: right; }

/* =========================================================
   SETUP page
   ========================================================= */
.card {
  width: 100%;
  max-width: 460px;
  background: rgba(255,255,255,.5);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  text-align: left;
}
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field .req { color: var(--rose); }
.input, textarea.input {
  width: 100%;
  font-family: var(--body);
  font-size: 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  outline: none;
  transition: border-color .2s;
}
.input:focus { border-color: var(--ticket-2); }
textarea.input { resize: vertical; min-height: 64px; }
.row2 { display: flex; gap: 12px; }
.row2 .field { flex: 1; }

/* recorder */
.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px;
  border: 1.5px dashed var(--hairline);
  border-radius: var(--radius);
  background: var(--paper);
}
.mic-btn {
  width: 66px; height: 66px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--btn); color: var(--btn-ink);
  font-size: 26px; display: grid; place-items: center;
  transition: transform .15s, background .25s;
  box-shadow: var(--shadow-sm);
}
.mic-btn.recording { background: var(--burgundy); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(124,59,59,.4) } 50%{ box-shadow: 0 0 0 14px rgba(124,59,59,0) } }
.rec-status { font-size: 15px; color: var(--ink-soft); min-height: 22px; }
.rec-playback { width: 100%; margin-top: 4px; }
.rec-playback audio { width: 100%; }

/* result / link box */
.linkbox {
  width: 100%;
  background: var(--paper);
  border: 1.5px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  word-break: break-all;
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

/* colour swatches */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--sw);
  border: 2px solid rgba(0,0,0,.12);
  cursor: pointer;
  transition: transform .15s, box-shadow .2s;
  position: relative;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.is-on {
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink);
}
.swatch.is-on::after {
  content: "✓";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: rgba(0,0,0,.55); font-size: 16px; font-weight: 700;
}

/* small helper */
.center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.hidden { display: none !important; }
.spacer { height: 8px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: all .3s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
