/* TOTORUN デジタルスタンプカード（参加者向け）
   台紙の世界観に合わせた配色。外部フォント・外部画像は使わない（完全セルフホスト） */

:root {
  --cream: #fdf9ef;
  --cream-deep: #f6efdd;
  --green: #2e5e34;
  --green-light: #4a8351;
  --yellow: #f5c33b;
  --yellow-soft: #fdefc4;
  --navy: #1c2f56;
  --brown: #5a3327;
  --gray: #7c7768;
  --white: #fff;
  --radius: 20px;
  --radius-lg: 28px;
  --shadow: 0 6px 20px rgba(28, 47, 86, 0.1);
  --shadow-lift: 0 10px 28px rgba(28, 47, 86, 0.16);
  --font: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4", "BIZ UDPGothic",
    "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100%;
  background: var(--cream);
  color: var(--navy);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: anywhere;
}

body.is-locked {
  overflow: hidden;
}

img {
  display: block;
  max-width: 100%;
}

/* ---------- レイアウト ---------- */

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
}

.page-title {
  margin: 8px 0 10px;
  font-size: 1.35rem;
  line-height: 1.4;
  color: var(--green);
}

.lede {
  margin: 0 0 16px;
  color: var(--navy);
}

.section {
  margin-top: 28px;
  padding: 18px 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section__title {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--green);
}

.note {
  margin: 6px 0 0;
  font-size: 0.83rem;
  color: var(--gray);
  line-height: 1.6;
}

.callout {
  margin: 0;
  padding: 14px 16px;
  background: var(--yellow-soft);
  border: 2px dashed var(--yellow);
  border-radius: var(--radius);
  color: var(--brown);
  font-weight: 700;
}

.loading {
  padding: 80px 0;
  text-align: center;
  color: var(--gray);
}

.noscript {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  color: var(--brown);
}

/* ---------- ヘッダー（全画面共通・上部に固定） ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--cream);
  border-bottom: 1px solid var(--cream-deep);
  box-shadow: 0 2px 10px rgba(28, 47, 86, 0.07);
  padding-top: env(safe-area-inset-top);
}

.appbar__inner {
  position: relative; /* ドロップダウンの位置決めの基準 */
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 480px;
  min-width: 0;
  height: 56px;
  margin: 0 auto;
  padding: 0 8px 0 16px;
}

.appbar__mark {
  flex: none;
  color: var(--navy);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

/* 名前＋参加回数。未登録のときは hidden で消える */
.appbar__who {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.appbar__who[hidden] {
  display: none;
}

.appbar__name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; /* 長い名前は折り返さず「…」で省略 */
  color: var(--brown);
  font-size: 0.98rem;
  font-weight: 700;
}

.appbar__sep {
  flex: none;
  color: var(--gray);
  font-size: 0.8rem;
}

.appbar__count {
  flex: none;
  color: var(--green);
  font-size: 0.88rem;
  font-weight: 700;
}

.appbar__lap {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.5;
}

.appbar__lap[hidden] {
  display: none;
}

.appbar__burger {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  padding: 0;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--navy);
  font-family: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.appbar__burger[aria-expanded="true"] {
  background: var(--cream-deep);
}

.appbar__menu {
  position: absolute;
  right: 8px;
  top: calc(100% - 4px);
  z-index: 1;
  display: grid;
  gap: 2px;
  width: min(290px, calc(100vw - 32px));
  padding: 10px;
  border-radius: 18px;
  background: var(--white);
  box-shadow: var(--shadow-lift);
  animation: appbar-menu-in 0.16s ease-out both;
}

.appbar__menu[hidden] {
  display: none;
}

@keyframes appbar-menu-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.appbar-menu__item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--green);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.appbar-menu__item:active {
  background: var(--cream-deep);
}

.appbar-menu__note {
  margin: 4px 6px 2px;
  color: var(--gray);
  font-size: 0.76rem;
  line-height: 1.55;
}

/* 運営向けの区画。参加者には主役ではないので控えめに */
.appbar-menu__section {
  margin-top: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--cream-deep);
}

.appbar-menu__section .appbar-menu__item {
  color: var(--gray);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---------- ボタン・フォーム ---------- */

.btn {
  display: block;
  width: 100%;
  padding: 15px 18px;
  border: none;
  border-radius: 999px;
  background: var(--green);
  color: var(--white);
  font-family: inherit;
  font-size: 1.03rem;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn--yellow {
  background: var(--yellow);
  color: var(--brown);
}

.btn--ghost {
  background: var(--white);
  color: var(--green);
  border: 2px solid var(--green);
}

.btn--sub {
  padding: 12px 16px;
  font-size: 0.95rem;
}

.field {
  margin: 14px 0 0;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green);
}

.input {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--cream-deep);
  border-radius: 14px;
  background: var(--white);
  color: var(--navy);
  font-family: inherit;
  font-size: 1.05rem;
}

.input:focus {
  outline: none;
  border-color: var(--green-light);
}

.input--code {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  text-align: center;
  font-size: 1.15rem;
}

.error {
  margin: 8px 0 0;
  color: #b3402c;
  font-size: 0.9rem;
  font-weight: 700;
}

.form-actions {
  margin-top: 16px;
}

/* ---------- カード ---------- */

.card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--white);
  box-shadow: var(--shadow-lift);
  container-type: inline-size;
}

.card__base {
  width: 100%;
  height: auto;
}

.card__name {
  position: absolute;
  transform: translate(-50%, -100%);
  color: var(--brown);
  font-family: var(--font);
  font-weight: 700;
  font-size: 20px;
  font-size: 4.8cqw; /* 長い名前は card.js が測って縮める */
  line-height: 1.2;
  white-space: nowrap;
  max-width: 22%; /* 台紙の「名前」ラベルに重ならない範囲 */
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.stamp {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(46, 94, 52, 0.25));
}

.stamp--pop {
  animation: stamp-pop 0.52s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes stamp-pop {
  0% {
    transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(2.4);
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1);
    opacity: 1;
  }
}

.ripple {
  position: absolute;
  aspect-ratio: 1 / 1;
  border: 3px solid var(--green-light);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: stamp-ripple 0.6s ease-out 0.36s both;
}

@keyframes stamp-ripple {
  0% {
    transform: translate(-50%, -50%) scale(0.35);
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.9);
    opacity: 0;
  }
}

/* 座標調整用（?debug=1） */
.spot-label {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 2em;
  padding: 2px 4px;
  border-radius: 999px;
  background: rgba(28, 47, 86, 0.88);
  color: #fff;
  font-size: 12px;
  font-size: 3cqw;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

.debug-note {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--navy);
  color: var(--white);
  font-size: 0.85rem;
}

/* ---------- カード下のエリア ---------- */

.goal-banner {
  margin: 16px 0 0;
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--yellow) 0%, #ffe08a 100%);
  color: var(--brown);
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  box-shadow: var(--shadow);
}

/* 台紙のすぐ下の主役ボタン。ここを押すと「ポンッ」と押印される */
.stamp-btn {
  display: block;
  width: 100%;
  margin: 14px 0 0;
  padding: 16px 20px 14px;
  border: none;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #f2926a 0%, #e8734a 100%);
  color: var(--white);
  font-family: inherit;
  text-align: center;
  box-shadow: 0 10px 26px rgba(232, 115, 74, 0.34);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: stamp-btn-pulse 2.6s ease-in-out infinite;
}

.stamp-btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 12px rgba(232, 115, 74, 0.3);
  animation: none;
}

.stamp-btn__icon {
  display: block;
  font-size: 1.7rem;
  line-height: 1.2;
}

.stamp-btn__label {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stamp-btn__sub {
  display: block;
  margin-top: 2px;
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.94;
}

/* QRを読み終わっていて、あとは押すだけの状態 */
.stamp-btn--ready {
  background: linear-gradient(135deg, #f6a641 0%, #e8734a 100%);
}

@keyframes stamp-btn-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 10px 26px rgba(232, 115, 74, 0.34);
  }
  50% {
    transform: scale(1.022);
    box-shadow: 0 14px 32px rgba(232, 115, 74, 0.48);
  }
}

.reward-banner {
  display: block;
  width: 100%;
  margin: 16px 0 0;
  padding: 16px;
  border: 2px solid #e0a91f;
  border-radius: var(--radius);
  background: var(--yellow);
  color: var(--brown);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: left;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.reward-banner:active {
  transform: translateY(1px);
}

.reward-banner__sub {
  display: block;
  margin-top: 2px;
  font-size: 0.82rem;
  font-weight: 400;
}

/* ちょうど節目に到達した瞬間だけ、特典バナーを弾ませる */
.reward-banner--pop {
  animation: reward-pop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
}

@keyframes reward-pop {
  0% {
    transform: scale(1);
    box-shadow: var(--shadow);
  }
  40% {
    transform: scale(1.07);
    box-shadow: 0 12px 30px rgba(224, 169, 31, 0.6);
  }
  70% {
    transform: scale(0.985);
  }
  100% {
    transform: scale(1);
    box-shadow: var(--shadow);
  }
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--cream-deep);
  color: var(--brown);
  font-size: 0.88rem;
  font-weight: 700;
}

.badge__emoji {
  font-size: 1.15rem;
}

.reward-list {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.reward-list li {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--yellow-soft);
  color: var(--brown);
  font-weight: 700;
}

.reward-owner {
  margin: 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--cream-deep);
  text-align: center;
}

.reward-owner__label {
  display: block;
  font-size: 0.8rem;
  color: var(--gray);
}

.reward-owner__name {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brown);
}

.staff-hint {
  margin: 14px 0 0;
  color: var(--green);
  font-weight: 700;
  text-align: center;
}

/* ---------- トースト ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(440px, calc(100% - 24px));
  pointer-events: none;
}

.toast {
  padding: 13px 16px;
  border-radius: 16px;
  background: rgba(28, 47, 86, 0.94);
  color: var(--white);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  box-shadow: var(--shadow-lift);
  animation: toast-in 0.28s ease-out both;
}

.toast--out {
  animation: toast-out 0.28s ease-in both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- モーダル ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(28, 47, 86, 0.5);
}

.modal[hidden] {
  display: none;
}

.modal__panel {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  border-radius: var(--radius-lg);
  background: var(--cream);
  box-shadow: var(--shadow-lift);
  animation: modal-in 0.24s ease-out both;
}

.modal__panel--full {
  width: 100%;
  max-width: none;
  min-height: 100%;
  max-height: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.modal--full {
  padding: 0;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

.modal__title {
  margin: 0 0 12px;
  font-size: 1.2rem;
  color: var(--green);
  text-align: center;
}

.modal__body {
  margin-bottom: 20px;
}

.modal__code {
  margin: 0;
  padding: 18px 10px;
  border: 3px dashed var(--green);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--navy);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-align: center;
  word-break: break-all;
}

/* ---------- QRスキャナ（全画面） ---------- */

.scan {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background: rgba(12, 22, 40, 0.96);
  color: var(--white);
}

.scan__inner {
  display: grid;
  gap: 16px;
  width: min(440px, 100%);
}

.scan__hint {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
}

.scan__hint--warn {
  color: var(--yellow);
}

.scan__stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #000;
}

.scan__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan__guide {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 66%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.scan__fallback {
  margin: 0;
  padding: 24px 20px;
  color: var(--white);
  font-size: 0.95rem;
  line-height: 1.8;
  text-align: center;
}

/* ---------- 紙吹雪 ---------- */

.confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -8vh;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift, 0px), 112vh, 0) rotate(680deg);
    opacity: 0.85;
  }
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }
  .ripple {
    display: none;
  }
  .stamp--pop,
  .toast,
  .toast--out,
  .modal__panel,
  .stamp-btn,
  .reward-banner--pop,
  .appbar__menu {
    animation: none;
  }
}
