:root {
  --night: #060a12;
  --ink: #0c1828;
  --ink-2: #13243a;
  --gold: #e9c46a;
  --gold-hi: #fbe7a8;
  --gold-lo: #b98a2e;
  --red: #c8102e;
  --red-hi: #e23a4e;
  --green: #2f8f6b;
  --snow: #f6f1e7;
  --muted: #9fb0c6;
  --serif-en: Didot, "Bodoni 72", "Bodoni MT", "Playfair Display", Georgia, serif;
  --serif-ja: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --mono: ui-monospace, Menlo, "SF Mono", Consolas, monospace;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  background: var(--night);
}
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  color: var(--snow);
  font-family: var(--sans);
  background:
    radial-gradient(120% 70% at 50% -10%, #1b3456 0%, rgba(27, 52, 86, 0) 60%),
    radial-gradient(90% 60% at 50% 115%, #10301f 0%, rgba(16, 48, 31, 0) 65%),
    var(--night);
  background-attachment: fixed;
  overflow: hidden;
}

canvas#snow, canvas#fx {
  position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
canvas#snow { z-index: 0; }
canvas#fx { z-index: 3; }

#app {
  position: relative; z-index: 1;
  height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}

.screen {
  position: absolute; inset: 0;
  padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  opacity: 0; visibility: hidden;
  transition: opacity .6s var(--ease-out), visibility 0s linear .6s;
  overflow-y: auto; overscroll-behavior: contain;
}
.screen.is-active { opacity: 1; visibility: visible; transition: opacity .6s var(--ease-out), visibility 0s; }

.kicker {
  font-family: var(--mono); font-size: 11px; letter-spacing: .32em; color: var(--gold);
  margin: 0 0 14px; padding-left: .32em;
}

/* 受信の前 */
.crest { width: min(52vw, 210px); aspect-ratio: 1; margin-bottom: 26px; filter: drop-shadow(0 0 24px rgba(233, 196, 106, .25)); }
.crest-svg { width: 100%; height: 100%; overflow: visible; }
.crest-ring { font-family: var(--mono); font-size: 9.5px; letter-spacing: 2.2px; fill: var(--gold); }
.crest-svg > text { animation: spin 60s linear infinite; transform-origin: 100px 100px; }
.flake { animation: breathe 4.5s ease-in-out infinite; transform-origin: 100px 100px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(1.06) rotate(8deg); opacity: .85; } }

.gate-title {
  font-family: var(--serif-ja); font-weight: 600; font-size: clamp(28px, 8.4vw, 38px); line-height: 1.35;
  margin: 0 0 10px; letter-spacing: .06em;
  background: linear-gradient(180deg, #fff 30%, var(--gold-hi) 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.gate-sub { margin: 0 0 34px; color: var(--muted); font-size: 15px; letter-spacing: .08em; }

.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 30px; border-radius: 999px; border: 1px solid rgba(233, 196, 106, .5);
  background: rgba(12, 24, 40, .7); color: var(--snow); font: 600 16px/1 var(--sans); letter-spacing: .08em;
  text-decoration: none; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform .12s var(--ease-out), filter .12s;
}
.btn:active { transform: scale(.96); filter: brightness(1.15); }
.btn-gold {
  color: #2a1a00; border: none;
  background: linear-gradient(135deg, var(--gold-hi), var(--gold) 45%, var(--gold-lo) 100%);
  box-shadow: 0 8px 30px rgba(233, 196, 106, .35), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.btn-ring {
  position: absolute; inset: -6px; border-radius: inherit; border: 1px solid rgba(233, 196, 106, .6);
  animation: ring 2.2s var(--ease-out) infinite; pointer-events: none;
}
@keyframes ring { 0% { transform: scale(.94); opacity: .9; } 100% { transform: scale(1.18); opacity: 0; } }
.btn-small { min-height: 44px; padding: 0 20px; font-size: 15px; }
.btn .ico { width: 20px; height: 20px; }
.btn-text {
  margin-top: 18px; background: none; border: 0; color: var(--muted); font: 14px var(--sans);
  padding: 10px 14px; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; touch-action: manipulation;
}

/* 照合 */
.term {
  width: min(100%, 340px); min-height: 7.6em; margin-bottom: 26px; text-align: left;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.75; color: #b9e6cf;
}
.term .ln { white-space: pre; overflow: hidden; }
.term .ok { color: var(--gold); }
.term .ng { color: var(--red-hi); }
.term .caret { display: inline-block; width: .6em; height: 1em; vertical-align: -2px; background: #b9e6cf; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.board {
  --size: min(68vw, 270px);
  position: relative; width: var(--size); height: var(--size);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  transition: gap .5s var(--ease-spring);
}
.board.joined { gap: 0; }
.tile {
  position: relative; display: grid; place-items: center;
  background:
    repeating-linear-gradient(45deg, rgba(233, 196, 106, .07) 0 6px, transparent 6px 12px),
    linear-gradient(160deg, var(--ink-2), var(--ink));
  border: 1px solid rgba(233, 196, 106, .45);
  opacity: 0;
}
.tile span { font-family: var(--serif-en); font-size: 30px; color: var(--gold); opacity: .9; }
.tile.in { opacity: 1; }
.tile.missing {
  opacity: 1; background: transparent; border: 1px dashed rgba(159, 176, 198, .4);
}
.tile.missing span { color: var(--muted); opacity: .5; font-size: 22px; }
.board.joined .tile { border-color: transparent; }
.board.gift .tile {
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, .25), transparent 55%),
    linear-gradient(160deg, #1f7a56, #0f4a33);
  transition: background .4s;
}
.board.gift .tile span { opacity: 0; transition: opacity .3s; }
.ribbon { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transform: scale(.6); pointer-events: none; }
.bow { position: absolute; left: 50%; top: 0; width: 46%; transform: translate(-50%, -62%) scale(0); transform-origin: 50% 80%; pointer-events: none; }
.board.gift .ribbon { opacity: 1; transform: none; transition: opacity .3s, transform .5s var(--ease-spring); }
.board.gift .bow { transform: translate(-50%, -62%) scale(1); transition: transform .6s .2s var(--ease-spring); }
.board.glow { box-shadow: 0 0 0 1px rgba(233, 196, 106, .6), 0 0 60px rgba(233, 196, 106, .45); }
.scan {
  position: absolute; left: -6%; right: -6%; height: 2px; top: 0; opacity: 0;
  background: linear-gradient(90deg, transparent, #7dffc4, transparent); box-shadow: 0 0 14px #7dffc4;
}
.board.scanning .scan { animation: scan 1s ease-in-out 1; }
@keyframes scan { 0% { top: 0; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { top: 100%; opacity: 0; } }

/* 完了 */
#complete { justify-content: flex-start; padding-top: max(48px, calc(env(safe-area-inset-top) + 28px)); }
.stamp-wrap { margin: 6px 0 22px; }
.stamp {
  margin: 0; display: inline-block; padding: 14px 22px 12px;
  font-family: var(--serif-en); font-weight: 700; font-size: clamp(34px, 10.5vw, 46px); line-height: .98; letter-spacing: .04em;
  color: var(--gold-hi); border: 3px double var(--gold); border-radius: 6px;
  text-shadow: 0 0 22px rgba(233, 196, 106, .55);
  transform: rotate(-4deg);
  opacity: 0;
}
.stamp.slam { animation: slam .55s var(--ease-out) forwards; }
@keyframes slam {
  0% { opacity: 0; transform: rotate(-12deg) scale(2.6); filter: blur(6px); }
  60% { opacity: 1; transform: rotate(-3deg) scale(.94); filter: blur(0); }
  100% { opacity: 1; transform: rotate(-4deg) scale(1); }
}
.congrats {
  margin: 0 0 10px; font-family: var(--serif-ja); font-weight: 600; font-size: clamp(22px, 6.6vw, 28px); line-height: 1.5; letter-spacing: .06em;
}
.congrats-sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.7; max-width: 22em; }
.rise { opacity: 0; transform: translateY(14px); }
.rise.on { opacity: 1; transform: none; transition: opacity .7s var(--ease-out), transform .7s var(--ease-out); }

.reward {
  width: min(100%, 340px); padding: 22px 20px 24px; border-radius: 18px;
  background: linear-gradient(160deg, rgba(25, 45, 72, .85), rgba(10, 20, 34, .9));
  border: 1px solid rgba(233, 196, 106, .35);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.reward-label { margin: 0; font-family: var(--mono); font-size: 11px; letter-spacing: .4em; color: var(--gold); padding-left: .4em; }
.reward-amount { margin: 8px 0 18px; font-family: var(--serif-en); font-size: 44px; font-weight: 700; color: #fff; }
.reward-amount .yen { display: block; font-family: var(--sans); font-size: 13px; letter-spacing: .2em; color: var(--muted); font-weight: 600; }
.reward-amount small { font-family: var(--serif-ja); font-size: 22px; margin-left: 2px; }
.btn-claim { width: 100%; }
.claim-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

.code-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; line-height: 1.6; }
.code-row { display: flex; gap: 8px; }
.code-row input {
  flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid rgba(233, 196, 106, .45);
  background: rgba(0, 0, 0, .35); color: #fff; font-size: 16px; padding: 0 14px; letter-spacing: .1em;
}
.code-row input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.code-msg { min-height: 1.4em; margin: 10px 0 0; font-family: var(--mono); font-size: 12px; letter-spacing: .1em; }
.code-msg.ng { color: var(--red-hi); }
.code-form.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.not-ready p { margin: 0 0 14px; font-size: 14px; line-height: 1.8; }
.not-ready .diag { margin: 14px 0 0; font-family: var(--mono); font-size: 10px; letter-spacing: .12em; color: rgba(159, 176, 198, .55); }

/* ミッション中 */
.prog-title { margin: 0 0 22px; font-family: var(--serif-ja); font-size: clamp(26px, 7.6vw, 32px); letter-spacing: .08em; font-weight: 600; }
.mini-board { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 132px; height: 132px; margin-bottom: 18px; }
.mini-board i {
  display: block; border: 1px dashed rgba(159, 176, 198, .45); border-radius: 2px; position: relative;
}
.mini-board i.got {
  border: 1px solid rgba(233, 196, 106, .6);
  background: repeating-linear-gradient(45deg, rgba(233, 196, 106, .14) 0 5px, transparent 5px 10px), var(--ink-2);
  box-shadow: 0 0 18px rgba(233, 196, 106, .25);
}
.mini-board i:not(.got)::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; opacity: .5;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 11V8a5 5 0 0110 0v3' stroke='%239fb0c6' stroke-width='2' fill='none'/%3E%3Crect x='5' y='11' width='14' height='10' rx='2' fill='%239fb0c6'/%3E%3C/svg%3E");
}
.prog-day { margin: 0 0 8px; font-family: var(--mono); font-size: 13px; letter-spacing: .25em; color: var(--gold); }
.prog-text { margin: 0 0 24px; font-size: 14.5px; line-height: 1.85; color: #d8dfe9; max-width: 22em; }
.count { padding: 14px 22px; border: 1px solid rgba(233, 196, 106, .3); border-radius: 14px; background: rgba(10, 20, 34, .6); margin-bottom: 20px; }
.count-label { margin: 0 0 4px; font-family: var(--mono); font-size: 10px; letter-spacing: .35em; color: var(--muted); padding-left: .35em; }
.count-val { margin: 0; font-family: var(--mono); font-size: 24px; letter-spacing: .06em; color: var(--gold-hi); font-variant-numeric: tabular-nums; }
.prog-hint { margin: 0; font-size: 12.5px; color: var(--muted); letter-spacing: .04em; }

/* 1〜3日目の通信 */
#daily { justify-content: flex-start; padding-top: max(40px, calc(env(safe-area-inset-top) + 22px)); --accent: var(--gold); }
#daily[data-motif="snow"] { --accent: #bfe3ff; }
#daily[data-motif="star"] { --accent: var(--gold-hi); }
#daily[data-motif="bell"] { --accent: #f2c46d; }
#daily .kicker { margin-bottom: 10px; color: var(--accent); }
.emblem { width: 96px; height: 96px; color: var(--accent); filter: drop-shadow(0 0 18px rgba(233, 196, 106, .3)); margin-bottom: 6px; }
.emblem-svg { width: 100%; height: 100%; overflow: visible; }
.emblem-ring { font-family: var(--mono); font-size: 7.2px; letter-spacing: 1.6px; fill: currentColor; }
.emblem-svg > text { animation: spin 40s linear infinite; transform-origin: 60px 60px; }
.motif { display: none; }
#daily[data-motif="snow"] .motif[data-motif="snow"],
#daily[data-motif="star"] .motif[data-motif="star"],
#daily[data-motif="bell"] .motif[data-motif="bell"] { display: inline; }
.emblem.pop { animation: pop .7s var(--ease-spring); }
@keyframes pop { 0% { transform: scale(.2) rotate(-40deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.motif[data-motif="bell"] { transform-origin: 60px 32px; }
.emblem.pop .motif[data-motif="bell"] { animation: ring-bell 1.4s .5s ease-in-out; }
@keyframes ring-bell { 15% { transform: rotate(14deg); } 35% { transform: rotate(-11deg); } 55% { transform: rotate(7deg); } 75% { transform: rotate(-4deg); } }
.codename { margin: 0 0 4px; font-family: var(--mono); font-size: 11px; letter-spacing: .22em; color: var(--muted); }
.stamp-wrap-sm { margin: 4px 0 10px; }
.stamp-sm { font-size: clamp(24px, 7.4vw, 30px); padding: 10px 16px 8px; border-color: var(--accent); color: #fff; }
.daily-headline { margin: 0 0 12px; font-family: var(--serif-ja); font-size: 19px; font-weight: 600; letter-spacing: .1em; }
.archive { margin: 0 0 12px; max-width: 22em; font-size: 12.5px; line-height: 1.7; color: #f3d98b; border: 1px dashed rgba(233, 196, 106, .45); border-radius: 10px; padding: 8px 12px; }
.dispatch {
  width: min(100%, 340px); text-align: left; padding: 14px 16px 14px; margin-bottom: 12px; border-radius: 14px;
  background: linear-gradient(160deg, rgba(25, 45, 72, .8), rgba(10, 20, 34, .85)); border: 1px solid rgba(233, 196, 106, .28);
}
.dispatch-head { margin: 0 0 8px; font-family: var(--mono); font-size: 10px; letter-spacing: .4em; color: var(--accent); }
.dispatch-lines p { margin: 0; font-family: var(--serif-ja); font-size: 15px; line-height: 1.85; color: #eef2f7; opacity: 0; transform: translateY(6px); }
.dispatch-lines p.on { opacity: 1; transform: none; transition: opacity .6s var(--ease-out), transform .6s var(--ease-out); }
.hint-card {
  width: min(100%, 340px); padding: 12px 16px; margin-bottom: 14px; border-radius: 14px; text-align: left;
  background: rgba(200, 16, 46, .12); border: 1px solid rgba(226, 58, 78, .45);
}
.hint-card.rise { transform: perspective(600px) rotateX(-70deg); transform-origin: top; }
.hint-card.rise.on { transform: none; }
.hint-label { margin: 0 0 4px; font-family: var(--mono); font-size: 10px; letter-spacing: .4em; color: var(--red-hi); }
.hint-text { margin: 0; font-size: 14px; line-height: 1.75; }
.count-sm { padding: 10px 18px; margin-bottom: 10px; }
.count-sm .count-val { font-size: 20px; }

.noscript { position: fixed; inset: auto 16px 24px; text-align: center; color: var(--snow); z-index: 5; }

.shake-screen { animation: quake .45s; }
@keyframes quake { 15% { transform: translate(-5px, 3px); } 35% { transform: translate(4px, -4px); } 55% { transform: translate(-3px, 2px); } 75% { transform: translate(2px, -1px); } }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.08); }
  .btn-text:hover { color: var(--snow); }
}

@media (prefers-reduced-motion: reduce) {
  .crest-svg > text, .flake, .btn-ring { animation: none; }
  .stamp.slam { animation-duration: .01s; }
  .shake-screen, .code-form.shake { animation: none; }
}

@media (max-height: 700px) {
  .crest { width: min(40vw, 150px); margin-bottom: 16px; }
  .gate-sub { margin-bottom: 22px; }
  .board { --size: min(58vw, 220px); }
  .reward-amount { font-size: 38px; }
}
