/* ============================================================
   ts-memory-popup.css — Takumi Senpai · Memory Submission Slide-In
   Path: /css/ts-memory-popup.css
   Load on: all quest article pages (after style.css)

   Design language: Documentary · Quiet urgency · Archive fragment
   Prefix: ts-popup- (collision-safe)
   ============================================================ */

/* ════════════════════════════════════════════════════════════
   ROOT VARS (local — inherits from parent if available)
   ════════════════════════════════════════════════════════════ */
:root {
  --ts-popup-accent:      #c9a84c;
  --ts-popup-accent-dim:  rgba(201,168,76,0.15);
  --ts-popup-accent-mid:  rgba(201,168,76,0.35);
  --ts-popup-bg:          rgba(10, 8, 6, 0.82);
  --ts-popup-border:      rgba(201,168,76,0.14);
  --ts-popup-text:        rgb(240, 236, 228);
  --ts-popup-text-muted:  rgba(240, 236, 228, 0.48);
  --ts-popup-text-faint:  rgba(240, 236, 228, 0.22);
  --ts-popup-shadow:      0 24px 64px rgba(0,0,0,0.72), 0 4px 16px rgba(0,0,0,0.5);
  --ts-popup-duration:    0.55s;
  --ts-popup-ease:        cubic-bezier(0.22, 1, 0.36, 1);
}

/* ════════════════════════════════════════════════════════════
   CARD WRAPPER
   ════════════════════════════════════════════════════════════ */
.ts-popup-card {
  position: fixed;
  z-index: 9900;

  /* Desktop: bottom-right */
  bottom: 32px;
  right: 32px;
  width: 320px;

  background: var(--ts-popup-bg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);

  border: 1px solid var(--ts-popup-border);
  border-top: 2px solid var(--ts-popup-accent);

  padding: 28px 26px 26px;
  box-shadow: var(--ts-popup-shadow);

  /* Entry animation — transform origin bottom-right */
  transform: translateY(24px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    transform var(--ts-popup-duration) var(--ts-popup-ease),
    opacity   var(--ts-popup-duration) var(--ts-popup-ease);

  /* Grain overlay via pseudo-element */
  overflow: hidden;
}

/* Grain texture */
.ts-popup-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

/* Subtle scan line */
.ts-popup-card::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(201,168,76,0.5) 35%,
    rgba(201,168,76,0.9) 50%,
    rgba(201,168,76,0.5) 65%,
    transparent 100%
  );
  animation: ts-popup-scan 4s ease-in-out infinite 1.5s;
  opacity: 0;
  z-index: 1;
}

@keyframes ts-popup-scan {
  0%   { opacity: 0; top: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 0.6; }
  100% { opacity: 0; top: 100%; }
}

/* Visible state */
.ts-popup-card.ts-popup--visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ════════════════════════════════════════════════════════════
   CLOSE BUTTON
   ════════════════════════════════════════════════════════════ */
.ts-popup-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 10;

  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;

  font-family: 'Space Mono', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ts-popup-text-muted);

  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.2s ease;
}

.ts-popup-close:hover {
  color: var(--ts-popup-text);
}

.ts-popup-close-icon {
  display: block;
  width: 14px;
  height: 14px;
  position: relative;
}

.ts-popup-close-icon::before,
.ts-popup-close-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: currentColor;
  transform-origin: center;
  transition: background 0.2s ease;
}

.ts-popup-close-icon::before { transform: rotate(45deg); }
.ts-popup-close-icon::after  { transform: rotate(-45deg); }

/* ════════════════════════════════════════════════════════════
   CARD CONTENT — RELATIVE STACKING
   ════════════════════════════════════════════════════════════ */
.ts-popup-inner {
  position: relative;
  z-index: 2;
}

/* ── Eyebrow ── */
.ts-popup-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Mono', monospace;
  font-size: 0.43rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ts-popup-accent);
  opacity: 0.8;
  margin-bottom: 14px;
}

.ts-popup-eyebrow::before {
  content: '';
  display: block;
  width: 16px;
  height: 1px;
  background: var(--ts-popup-accent-mid);
  flex-shrink: 0;
}

/* ── Body copy ── */
.ts-popup-body {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: 0.975rem;
  font-weight: 400;
  line-height: 1.72;
  letter-spacing: 0.01em;
  color: rgba(240, 236, 228, 0.78);
  margin-bottom: 22px;
  font-style: italic;
}

/* ── Divider ── */
.ts-popup-rule {
  width: 32px;
  height: 1px;
  background: var(--ts-popup-accent-mid);
  margin: 0 0 20px;
}

/* ── CTA Button ── */
.ts-popup-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;

  background: transparent;
  border: 1px solid var(--ts-popup-accent-mid);
  cursor: pointer;
  padding: 10px 18px 10px 16px;

  font-family: 'Space Mono', monospace;
  font-size: 0.56rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ts-popup-accent);

  position: relative;
  overflow: hidden;
  transition:
    border-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease;
}

/* Hover fill sweep */
.ts-popup-cta::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--ts-popup-accent-dim);
  transform: translateX(-102%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 0;
}

.ts-popup-cta:hover::before {
  transform: translateX(0);
}

.ts-popup-cta:hover {
  border-color: rgba(201,168,76,0.6);
  box-shadow: 0 0 0 2px rgba(201,168,76,0.07);
}

.ts-popup-cta-text {
  position: relative;
  z-index: 1;
}

.ts-popup-cta-arrow {
  position: relative;
  z-index: 1;
  display: block;
  width: 14px;
  height: 1px;
  background: var(--ts-popup-accent-mid);
  flex-shrink: 0;
  transition: width 0.22s ease, background 0.22s ease;
}

.ts-popup-cta-arrow::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 5px;
  height: 5px;
  border-right: 1px solid var(--ts-popup-accent-mid);
  border-top: 1px solid var(--ts-popup-accent-mid);
  transform: translateY(-50%) rotate(45deg);
  transition: border-color 0.22s ease;
}

.ts-popup-cta:hover .ts-popup-cta-arrow {
  width: 20px;
  background: var(--ts-popup-accent);
}

.ts-popup-cta:hover .ts-popup-cta-arrow::after {
  border-color: var(--ts-popup-accent);
}

/* ── Case ref stamp (decorative bottom-right) ── */
.ts-popup-ref {
  position: absolute;
  bottom: -4px;
  right: 0;
  font-family: 'Space Mono', monospace;
  font-size: 0.38rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ts-popup-text-faint);
  user-select: none;
  pointer-events: none;
}

/* ════════════════════════════════════════════════════════════
   EXIT ANIMATION
   ════════════════════════════════════════════════════════════ */
.ts-popup-card.ts-popup--hiding {
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.35s ease-in,
    opacity   0.30s ease-in;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE
   ════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .ts-popup-card {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 2px solid var(--ts-popup-accent);
    padding: 22px 22px 32px;
    border-radius: 0;

    /* Mobile: rise from bottom */
    transform: translateY(100%);
  }

  .ts-popup-card.ts-popup--visible {
    transform: translateY(0);
  }

  .ts-popup-card.ts-popup--hiding {
    transform: translateY(100%);
    opacity: 1; /* override opacity fade on mobile — just slide out */
  }

  .ts-popup-body {
    font-size: 0.92rem;
  }
}

/* ════════════════════════════════════════════════════════════
   INLINE FORM VIEW
   フォーム展開後のビュー — ts-popup- プレフィックスで衝突回避
   ════════════════════════════════════════════════════════════ */

/* フォームビューのラッパー */
.ts-popup-form-view {
  position: relative;
  z-index: 2;
}

/* ── フォームヘッダー ── */
.ts-popup-form-header {
  margin-bottom: 18px;
}

.ts-popup-form-sub {
  font-family: 'Space Mono', monospace;
  font-size: 0.42rem;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--ts-popup-text-muted);
  margin-top: 4px;
}

/* ── フォーム行 ── */
.ts-popup-form-row {
  margin-bottom: 14px;
}

.ts-popup-form-label {
  display: block;
  font-family: 'Space Mono', monospace;
  font-size: 0.46rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(240,236,228,0.55);
  margin-bottom: 6px;
}

.ts-popup-form-label span {
  color: var(--ts-popup-accent);
}

.ts-popup-form-optional {
  font-size: 0.40rem;
  color: var(--ts-popup-text-faint);
  letter-spacing: 0.12em;
}

/* ── Input / Textarea ── */
.ts-popup-form-input,
.ts-popup-form-textarea {
  width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(201,168,76,0.16);
  outline: none;
  padding: 9px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 0.66rem;
  line-height: 1.6;
  letter-spacing: 0.03em;
  color: var(--ts-popup-text);
  caret-color: var(--ts-popup-accent);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
  -webkit-appearance: none;
  border-radius: 0;
}

.ts-popup-form-input:focus,
.ts-popup-form-textarea:focus {
  border-color: rgba(201,168,76,0.50);
  box-shadow: 0 0 0 2px rgba(201,168,76,0.07);
}

.ts-popup-form-input::placeholder,
.ts-popup-form-textarea::placeholder {
  color: rgba(240,236,228,0.18);
  letter-spacing: 0.04em;
}

.ts-popup-form-textarea {
  resize: vertical;
  min-height: 72px;
}

/* ── Tiny-memory checkbox ── */
.ts-popup-tiny-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 16px;
  margin-top: 4px;
}

.ts-popup-tiny-cb {
  /* visually hidden — custom box used */
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ts-popup-tiny-box {
  flex-shrink: 0;
  display: block;
  width: 13px;
  height: 13px;
  border: 1px solid rgba(201,168,76,0.30);
  background: transparent;
  margin-top: 1px;
  position: relative;
  transition: border-color 0.18s, background 0.18s;
}

.ts-popup-tiny-box::after {
  content: '';
  position: absolute;
  top: 2px; left: 3px;
  width: 6px; height: 4px;
  border-left: 1px solid var(--ts-popup-accent);
  border-bottom: 1px solid var(--ts-popup-accent);
  transform: rotate(-45deg);
  opacity: 0;
  transition: opacity 0.15s;
}

.ts-popup-tiny-cb:checked + .ts-popup-tiny-box {
  border-color: var(--ts-popup-accent);
  background: rgba(201,168,76,0.10);
}

.ts-popup-tiny-cb:checked + .ts-popup-tiny-box::after {
  opacity: 1;
}

.ts-popup-tiny-text {
  font-family: 'Space Mono', monospace;
  font-size: 0.44rem;
  letter-spacing: 0.12em;
  line-height: 1.7;
  color: rgba(240,236,228,0.38);
  text-transform: uppercase;
}

/* ── Error ── */
.ts-popup-form-error {
  display: none;
  font-family: 'Space Mono', monospace;
  font-size: 0.46rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c94c4c;
  margin-bottom: 12px;
}

/* ── Submit button ── */
.ts-popup-submit {
  width: 100%;
  background: var(--ts-popup-accent);
  color: #0a0806;
  border: none;
  outline: none;
  padding: 12px 18px;
  font-family: 'Space Mono', monospace;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s ease, opacity 0.18s ease;
  margin-bottom: 10px;
}

.ts-popup-submit:hover:not(:disabled) {
  background: #e0be62;
}

.ts-popup-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Disclaimer ── */
.ts-popup-form-disclaimer {
  font-family: 'Space Mono', monospace;
  font-size: 0.40rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ts-popup-text-faint);
  line-height: 1.8;
  text-align: center;
}

/* ════════════════════════════════════════════════════════════
   SUCCESS STATE
   ════════════════════════════════════════════════════════════ */
.ts-popup-form-success {
  padding: 8px 0 4px;
  text-align: center;
}

.ts-popup-success-stamp {
  display: inline-block;
  font-family: 'Space Mono', monospace;
  font-size: clamp(1.0rem, 3vw, 1.4rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ts-popup-accent);
  border: 2px solid var(--ts-popup-accent);
  padding: 7px 22px 5px;
  transform: rotate(-2deg);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.4);
  margin-bottom: 18px;
  display: inline-block;
}

.ts-popup-success-text {
  font-family: 'Space Mono', monospace;
  font-size: 0.58rem;
  line-height: 1.85;
  letter-spacing: 0.06em;
  color: rgba(240,236,228,0.52);
}

/* ════════════════════════════════════════════════════════════
   CARD HEIGHT TRANSITION — フォーム展開時に高さを滑らかに変える
   ════════════════════════════════════════════════════════════ */
.ts-popup-card {
  transition:
    transform var(--ts-popup-duration) var(--ts-popup-ease),
    opacity   var(--ts-popup-duration) var(--ts-popup-ease),
    max-height 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 520px; /* フォーム展開後の最大高さに余裕を持って設定 */
  overflow-y: auto;  /* フォームが長い場合はスクロール可能 */
}

/* ── スクロールバーを目立たなくする ── */
.ts-popup-card::-webkit-scrollbar {
  width: 3px;
}
.ts-popup-card::-webkit-scrollbar-track {
  background: transparent;
}
.ts-popup-card::-webkit-scrollbar-thumb {
  background: rgba(201,168,76,0.2);
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE OVERRIDES FOR FORM VIEW
   ════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .ts-popup-card {
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ts-popup-form-input,
  .ts-popup-form-textarea {
    font-size: 16px; /* iOS Safari のズーム防止 */
  }
}