/* Euportia ログインゲート
   デザイン言語: Apple の Fluid Interfaces + Emil Kowalski の design engineering。
   - 押した瞬間に反応する（:active scale）
   - 入場は scale(0.98)+opacity から、強めの ease-out、300ms 以下
   - 動きはすべて transform / opacity のみ */

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --gate-bg: #f5f5f7;
  --card-bg: rgba(255, 255, 255, 0.82);
  --card-border: rgba(0, 0, 0, 0.06);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #1d9bf0;
  --accent-press: #1478b8;
  --field-bg: rgba(0, 0, 0, 0.045);
  --field-border: rgba(0, 0, 0, 0.1);
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(0, 0, 0, 0.08);
  --jt-secondary-button-bg: #ffffff;
  --jt-secondary-button-text: #1d1d1f;
  --jt-secondary-button-border: rgba(60, 60, 67, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --gate-bg: #0d0d0f;
    --card-bg: rgba(28, 28, 30, 0.82);
    --card-border: rgba(255, 255, 255, 0.08);
    --text: #f5f5f7;
    --muted: #98989d;
    --accent: #1d9bf0;
    --accent-press: #45b7ff;
    --field-bg: rgba(255, 255, 255, 0.06);
    --field-border: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 40px rgba(0, 0, 0, 0.5);
    --jt-secondary-button-bg: #1c1c1e;
    --jt-secondary-button-text: #f5f5f7;
    --jt-secondary-button-border: rgba(255, 255, 255, 0.14);
  }
}

/* 設定画面で固定テーマを選んだ場合は端末設定より優先する。 */
:root[data-jt-theme="light"] {
  --gate-bg: #f5f5f7;
  --card-bg: rgba(255, 255, 255, 0.82);
  --card-border: rgba(0, 0, 0, 0.06);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #1d9bf0;
  --accent-press: #1478b8;
  --field-bg: rgba(0, 0, 0, 0.045);
  --field-border: rgba(0, 0, 0, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(0, 0, 0, 0.08);
  --jt-secondary-button-bg: #ffffff;
  --jt-secondary-button-text: #1d1d1f;
  --jt-secondary-button-border: rgba(60, 60, 67, 0.18);
}

:root[data-jt-theme="dark"] {
  --gate-bg: #0d0d0f;
  --card-bg: rgba(28, 28, 30, 0.82);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --muted: #98989d;
  --accent: #1d9bf0;
  --accent-press: #45b7ff;
  --field-bg: rgba(255, 255, 255, 0.06);
  --field-border: rgba(255, 255, 255, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 40px rgba(0, 0, 0, 0.5);
  --jt-secondary-button-bg: #1c1c1e;
  --jt-secondary-button-text: #f5f5f7;
  --jt-secondary-button-border: rgba(255, 255, 255, 0.14);
}

/* ── 共通オーロラ背景（ゲートとアプリで共有） ── */

body { background: var(--gate-bg); }

#jt-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

#jt-bg i {
  position: absolute;
  width: 52vmax;
  height: 52vmax;
  border-radius: 50%;
  filter: blur(64px);
  will-change: transform;
}

#jt-bg i:nth-child(1) {
  top: -18vmax; left: -14vmax;
  background: radial-gradient(circle, rgba(10, 132, 255, 0.32), transparent 65%);
  animation: drift-a 26s ease-in-out infinite alternate;
}
#jt-bg i:nth-child(2) {
  top: 30%; right: -20vmax;
  background: radial-gradient(circle, rgba(191, 90, 242, 0.22), transparent 65%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
#jt-bg i:nth-child(3) {
  bottom: -22vmax; left: 12%;
  background: radial-gradient(circle, rgba(100, 210, 255, 0.26), transparent 65%);
  animation: drift-c 24s ease-in-out infinite alternate;
}

@keyframes drift-a { to { transform: translate3d(9vmax, 7vmax, 0) scale(1.12); } }
@keyframes drift-b { to { transform: translate3d(-8vmax, -6vmax, 0) scale(1.08); } }
@keyframes drift-c { to { transform: translate3d(6vmax, -8vmax, 0) scale(1.15); } }

/* アプリ本体はオーロラの上に載せる（背景は skin が透過化する） */
#root { position: relative; z-index: 1; }

/* ── 未ログイン操作の共通ログインモーダル ── */
#jt-auth-modal[hidden] { display: none !important; }

#jt-auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--gate-bg) 42%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
}

.auth-modal-frame {
  position: relative;
  width: min(520px, 100%);
  height: min(760px, calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow: visible;
  border: 0;
  background: transparent;
  transform: translateY(0) scale(1);
  animation: auth-modal-in 220ms var(--ease-out) both;
}

@keyframes auth-modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#auth-modal-content {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

@media (max-width: 560px) {
  #jt-auth-modal { padding-left: 8px; padding-right: 8px; }
  .auth-modal-frame {
    height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-modal-frame { animation: none; }
}

/* ── ゲート全景 ─────────────────────────────── */

/* hidden 属性を author CSS の display:flex より優先させる
   （これがないと透明なゲートが残って全タップを吸ってしまう） */
#jt-gate[hidden] { display: none !important; }

#jt-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* オーロラを透かす薄い被膜 */
  background: color-mix(in srgb, var(--gate-bg) 45%, transparent);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-y: auto;
}

#jt-gate.gate-leave {
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}

.gate-card {
  width: 100%;
  max-width: 360px;
  padding: 40px 32px 24px;
  border-radius: 24px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  text-align: center;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out);
}

@starting-style {
  .gate-card {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

/* 閲覧モード用の閉じるボタン（カード右上） */
.gate-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--field-bg);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}

.gate-close:active { transform: scale(0.92); }

.gate-close[hidden] { display: none; }

.gate-card { position: relative; }

.gate-logo {
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  animation: field-in 300ms var(--ease-out) backwards 0ms;
}

.gate-title {
  margin: 14px 0 2px;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
  animation: field-in 300ms var(--ease-out) backwards 40ms;
}

.gate-tagline {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  animation: field-in 300ms var(--ease-out) backwards 70ms;
}

.gate-badge {
  display: inline-block;
  margin: 0 0 22px;
  padding: 5px 12px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--field-bg);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  animation: field-in 300ms var(--ease-out) backwards 100ms;
}

.gate-badge-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  vertical-align: -2px;
  margin-right: 5px;
}

/* ── セグメントコントロール ─────────────────── */

.seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  margin-bottom: 20px;
  border-radius: 12px;
  background: var(--field-bg);
}

.seg-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 9px;
  background: var(--card-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  transform: translateX(0);
  transition: transform 200ms var(--ease-out);
}

.seg[data-mode="signup"] .seg-thumb { transform: translateX(100%); }

.seg-btn {
  position: relative;
  z-index: 1;
  padding: 8px 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 150ms ease;
}

.seg-btn.is-active { color: var(--text); }

/* ── フォーム ───────────────────────────────── */

.field {
  display: block;
  margin-bottom: 12px;
  text-align: left;
}

.field[hidden] { display: none; }
#btn-signup-resend[hidden] { display: none; }

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  font: inherit;
  font-size: 16px; /* 16px 未満だと iOS Safari がフォーカス時に自動ズームする */
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.field-hint {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.field-hint[hidden] { display: none; }

/* フィールドの入場スタガー（初回のみ・装飾） */
#view-auth .field:nth-child(1), #view-lock .field:nth-child(1), #view-password .field:nth-child(1) { animation: field-in 260ms var(--ease-out) backwards 40ms; }
#view-auth .field:nth-child(2) { animation: field-in 260ms var(--ease-out) backwards 90ms; }

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

/* ── ボタン ─────────────────────────────────── */

.btn {
  position: relative;
  width: 100%;
  padding: 12px 16px;
  margin-top: 6px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active { background: var(--accent-press); }

.btn[disabled] { cursor: default; opacity: 0.8; }

.btn .btn-spinner {
  display: none;
  position: absolute;
  right: 14px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 480ms linear infinite;
}

.btn.is-busy .btn-spinner { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── テキスト類 ─────────────────────────────── */

.gate-error {
  margin: 2px 0 8px;
  font-size: 13px;
  color: var(--danger);
  text-align: left;
  opacity: 1;
  transition: opacity 150ms ease;
}

.gate-error[hidden] { display: none; }

.gate-note {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  text-align: left;
}

.gate-consents {
  display: grid;
  gap: 9px;
  margin: 4px 0 12px;
  padding: 12px;
  border: 1px solid var(--card-border);
  border-radius: 13px;
  background: color-mix(in srgb, var(--field-bg) 70%, transparent);
  text-align: left;
}

.gate-consents[hidden], #recovery-confirm[hidden] { display: none; }

.gate-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
  text-align: left;
}

.gate-check input { width: 17px; height: 17px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.gate-check a { color: var(--accent); font-weight: 650; }
.gate-check-danger { margin: 4px 0 10px; color: var(--danger); }
.recovery-warning { margin-bottom: 16px; }

.gate-guest {
  display: inline-block;
  margin-top: 18px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}

.gate-guest:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .gate-guest:hover { background: var(--field-bg); }
}

.gate-guest-sub { color: var(--muted); font-weight: 400; }

.lock-hello {
  margin: 4px 0 2px;
  font-size: 17px;
  font-weight: 600;
}

.lock-email {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
}

.gate-foot {
  margin: 22px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.gate-foot a { color: inherit; }

/* ── 同期ステータスピル ─────────────────────── */

#jt-pill-wrap {
  position: fixed;
  /* 右上配置: アプリ下部のタブバーと重ならない。ノッチも回避 */
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 900;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
}

#jt-pill-wrap[hidden] { display: none !important; }

#jt-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card-bg);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}

#jt-pill:active { transform: scale(0.96); }

/* モバイル(ログイン後): 状態ドットだけの最小表示。タップで従来のメニュー */
#jt-pill.pill-mini {
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

#jt-pill.pill-mini #pill-text { display: none; }

/* ダークでの視認性: ピルの背景を持ち上げ、ドットに発光リング */
@media (prefers-color-scheme: dark) {
  #jt-pill {
    background: rgba(44, 44, 46, 0.92);
    border-color: rgba(255, 255, 255, 0.18);
  }
  .pill-dot {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.22), 0 0 8px currentColor;
  }
  .pill-dot { color: #30d158; }
  .pill-dot[data-state="syncing"] { color: #ff9f0a; }
  .pill-dot[data-state="error"] { color: #ff6b70; }
}

/* 未ログイン（閲覧モード）: はっきりしたログインボタンにする */
#jt-pill.pill-cta {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

#jt-pill.pill-cta .pill-dot { display: none; }

/* 未ログイン時は同期状態ではなく、常に明確なログイン導線として表示 */
#jt-pill.pill-cta {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

#jt-pill.pill-cta .pill-dot { display: none; }

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #30d158;
  transition: background-color 200ms ease;
}

.pill-dot[data-state="syncing"] { background: #ff9f0a; }
.pill-dot[data-state="error"]   { background: var(--danger); }
.pill-dot[data-state="guest"]   { background: #98989d; }

#jt-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: var(--card-bg);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: var(--shadow);
  transform-origin: top right; /* トリガー（右上ボタン）起点で開く */
  opacity: 1;
  transform: scale(1);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

#jt-panel[hidden] { display: none; }

@starting-style {
  #jt-panel { opacity: 0; transform: scale(0.95); }
}

.panel-title {
  margin: 6px 10px 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
}

.panel-email {
  margin: 0 10px 8px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.panel-entitlements {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 8px 8px;
}

.panel-entitlements span {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--field-bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.panel-btn {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 120ms ease;
}

.panel-link { text-decoration: none; }

.panel-btn:active { transform: scale(0.98); }

@media (hover: hover) and (pointer: fine) {
  .panel-btn:hover { background: var(--field-bg); }
}

.panel-danger { color: var(--danger); }

/* ゲート内の全ボタン: ダブルタップズーム由来のタップ遅延を無効化 */
#jt-gate button,
#jt-pill-wrap button {
  touch-action: manipulation;
}

/* ── アクセシビリティ ───────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .gate-card, #jt-panel { transition: opacity 200ms ease; transform: none; }
  @starting-style {
    .gate-card, #jt-panel { transform: none; }
  }
  #view-auth .field, #view-lock .field { animation: none; }
  .gate-logo, .gate-title, .gate-tagline, .gate-badge { animation: none; }
  #jt-bg i { animation: none; }
  .btn:active, .gate-guest:active, #jt-pill:active, .panel-btn:active { transform: none; }
  .seg-thumb { transition: none; }
}
