/* Capture PWA — Thino の密度感を基準にしたダークテーマ */
:root {
  --bg: #0e1116;
  --card: #171c23;
  --card-border: #232a33;
  --nested: #10151b;
  --text: #e6e9ee;
  --muted: #8b949e;
  --faint: #5c6670;
  --accent: #3b82f6;
  --accent-press: #2f6fd6;
  --amber: #d29922;
  --green: #3fb950;
  --danger: #f85149;
  --radius: 14px;
  --radius-s: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 属性は display 指定を持つどの要素にも必ず勝つ（display:flex 等による上書き事故の構造的防止） */
[hidden] { display: none !important; }

html { background: var(--bg); overscroll-behavior-y: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  /* CJK↔英数字に八分アキ（Safari 18.4+/Chrome 140+。非対応環境では無視される） */
  text-autospace: normal;
  font-size: 15px;
  line-height: 1.65;
  padding-bottom: env(safe-area-inset-bottom);
  touch-action: pan-y; /* 全体のピンチズームを無効化（拡大は画像モーダル内のみ） */
}
.card-img { cursor: zoom-in; }

/* ── ヘッダー ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
#notifBtn.enabled { color: var(--accent); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  color: var(--muted); background: none; border: none; cursor: pointer;
}
.iconbtn:active { background: var(--card); color: var(--text); }

/* 下部の固定 UI（モード切替・FAB）にカードが隠れないよう余白を確保 */
#app { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(110px + env(safe-area-inset-bottom)); }

/* ── 初回セットアップ ── */
.token-screen { padding: 18vh 16px 0; text-align: center; }
.token-screen h1 { font-size: 22px; margin-bottom: 10px; }
.token-screen p { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.token-screen input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-s);
  border: 1px solid var(--card-border); background: var(--card); color: var(--text);
  font-size: 15px; margin-bottom: 12px;
}
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }

button.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 22px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
button.primary:active { background: var(--accent-press); }
button.primary:disabled { opacity: 0.4; }

/* ── 投稿オーバーレイ（FAB から開く） ── */
.compose-overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(58px + env(safe-area-inset-top)) 14px 0;
}
.compose-backdrop {
  position: absolute; inset: 0; background: #000a;
  opacity: 0; transition: opacity 0.22s ease;
}
.composer {
  position: relative; width: 100%; max-width: 640px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 10px 14px 10px;
  opacity: 0; transform: translateY(12px) scale(0.97);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.compose-overlay.open .compose-backdrop { opacity: 1; }
.compose-overlay.open .composer { opacity: 1; transform: none; }
.composer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 -4px 2px 0;
}
.compose-title { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.03em; }
.composer.request-mode { border-color: color-mix(in srgb, var(--accent) 40%, var(--card-border)); }
.composer.request-mode .compose-title { color: var(--accent); }

/* ── 下部固定バー（表示フィルタ兼投稿モード） ── */
.bottombar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 20;
}
.mode-switch {
  display: inline-flex; gap: 2px; padding: 3px;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: 999px; box-shadow: 0 8px 24px #000a, 0 2px 6px #0007;
}
.mode-btn {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 14px; font-weight: 600; padding: 9px 28px; border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active { background: var(--nested); color: var(--text); box-shadow: 0 1px 4px #0006; }
#modeRequest.active { color: var(--accent); }

/* ── 新規投稿 FAB ── */
.fab {
  position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  box-shadow: 0 8px 24px #000a, 0 2px 8px #0007;
  /* ベースに transform を持たせて独自レイヤーに固定する（下部トグルと同条件）。
     これがないと iOS がスクロール再調整時に fixed 要素を一瞬ずれて描画する */
  transform: translateZ(0);
  transition: transform 0.15s ease, background 0.15s;
}
.fab:active { transform: translateZ(0) scale(0.92); background: var(--accent-press); }
.composer textarea {
  width: 100%; background: none; border: none; resize: none; outline: none;
  color: var(--text); font-size: 16px; line-height: 1.6; font-family: inherit;
  max-height: 40vh; caret-color: var(--accent);
}
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }
.attach { color: var(--muted); cursor: pointer; }
.attach-preview { position: relative; margin: 8px 0 2px; width: fit-content; }
.attach-preview img {
  max-height: 120px; max-width: 100%; border-radius: var(--radius-s);
  border: 1px solid var(--card-border); display: block;
}
.attach-remove {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: #000c; color: #fff;
  font-size: 14px; cursor: pointer; line-height: 1;
}
.queue-badge { font-size: 11px; color: var(--amber); margin-right: 12px; }

/* ── タイムライン ── */
.timeline { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.card {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 0;
  animation: cardIn 0.25s ease;
}
.card-body {
  position: relative; z-index: 1;
  padding: 12px 14px 13px; background: var(--card);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.card-body.dragging { transition: none; }
.card-delete {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 0;
  width: 84px; border: none; background: var(--danger); color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card-time { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.card-status { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.card-status.pulled { background: var(--green); opacity: 0.55; }
.card-status.pending { background: var(--faint); }
.pill-new {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent);
  padding: 1px 8px 2px; border-radius: 999px; line-height: 1.5;
}
.card-origin { font-size: 11px; color: var(--faint); margin-left: auto; }

.card-text { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.card-text a { color: var(--accent); text-decoration: none; }
.card-text a:active { text-decoration: underline; }

.card-img {
  margin-top: 10px; border-radius: var(--radius-s); border: 1px solid var(--card-border);
  max-width: 100%; max-height: 320px; display: block;
}
.card-img.loading { width: 120px; height: 90px; background: var(--nested); }

/* ── 依頼カード ── */
.pill-req {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  padding: 1px 8px 2px; border-radius: 999px; line-height: 1.5;
}
.pill-req.queued { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.pill-req.pending { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pill-req.processing { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.pill-req.processing::before {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--amber); margin-right: 5px; vertical-align: 1px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }
.pill-req.done { color: var(--green); background: color-mix(in srgb, var(--green) 13%, transparent); }
.pill-req.failed { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }

.req-result {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 11px 14px;
  background: var(--nested); border: 1px solid color-mix(in srgb, var(--green) 25%, var(--card-border));
  border-radius: 12px; text-decoration: none; color: var(--text);
}
.req-result .req-result-title {
  font-size: 14px; font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.req-result .req-result-open { margin-left: auto; flex: none; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.req-error { margin-top: 8px; font-size: 12.5px; color: var(--danger); word-break: break-word; }

/* ── X（ツイート）埋め込みカード ── */
.tweet {
  display: block; margin-top: 10px; padding: 12px 14px;
  background: var(--nested); border: 1px solid var(--card-border);
  border-radius: 12px; text-decoration: none; color: var(--text);
}
.tweet-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.tweet-avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; background: var(--card-border); }
.tweet-names { min-width: 0; line-height: 1.3; }
.tweet-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tweet-handle { font-size: 12.5px; color: var(--muted); }
.tweet-x {
  margin-left: auto; flex: none; color: var(--muted); font-weight: 700; font-size: 15px;
  font-family: -apple-system, sans-serif;
}
.tweet-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.tweet-media { margin-top: 9px; border-radius: 9px; max-width: 100%; max-height: 280px; display: block; border: 1px solid var(--card-border); }
.tweet-foot { display: flex; gap: 16px; margin-top: 9px; font-size: 12px; color: var(--muted); }
.tweet-foot .likes::before { content: "♥ "; color: #f91880; }
.tweet-foot .replies::before { content: "💬 "; font-size: 11px; }
.tweet.failed { color: var(--muted); font-size: 13px; }

/* ── OGP 埋め込みカード（X 以外のリンク） ── */
.ogp {
  display: flex; align-items: stretch; gap: 12px; margin-top: 10px; padding: 12px 14px;
  background: var(--nested); border: 1px solid var(--card-border);
  border-radius: 12px; text-decoration: none; color: var(--text);
}
.ogp-text { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.ogp-site { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ogp-title {
  font-weight: 600; font-size: 14px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ogp-desc {
  font-size: 12.5px; color: var(--muted); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ogp-thumb {
  width: 76px; height: 76px; flex: none; align-self: center;
  border-radius: 9px; object-fit: cover; border: 1px solid var(--card-border);
  background: var(--card-border);
}

/* ── その他 URL のリンクチップ ── */
.linkchip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  margin-top: 8px; margin-right: 6px; padding: 5px 12px;
  background: var(--nested); border: 1px solid var(--card-border); border-radius: 999px;
  color: var(--accent); font-size: 13px; text-decoration: none;
}
.linkchip .domain { color: var(--muted); font-size: 11.5px; flex: none; }
.linkchip .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── pull to refresh（コンポーザーとカード群の間が開き、そこにスピナーが出る） ── */
.ptr-gap {
  height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.ptr-gap.settling { transition: height 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
.ptr-gap svg { opacity: 0; }
.ptr-gap.armed { color: var(--accent); }
/* 注意: ここに transform:none !important を書くと、!important が CSS アニメーション
   より優先されて spin が動かなくなる。インラインの引っ張り回転は JS 側で除去する */
.ptr-gap.spinning svg { opacity: 1; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── カードのインライン編集（New はタップで直接編集） ── */
.card-edit textarea {
  width: 100%; min-height: 96px; padding: 14px 13px;
  background: var(--nested); border: 1px solid var(--card-border); border-radius: var(--radius-s);
  color: var(--text); font: inherit; line-height: 1.7; outline: none; caret-color: var(--accent);
}
.card-edit-row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
button.ghost { background: none; border: none; color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 10px; }

/* ── 画像拡大モーダル ── */
.img-modal {
  position: fixed; inset: 0; z-index: 200; background: #000e;
  display: flex; align-items: center; justify-content: center;
  touch-action: none; /* モーダル内は自前ジェスチャ（ピンチ/パン）が全権を持つ */
}
.img-modal img {
  max-width: 100vw; max-height: 100vh; display: block;
  transform-origin: 0 0; will-change: transform;
  user-select: none; -webkit-user-drag: none;
}
.img-modal-close {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  width: 38px; height: 38px; border-radius: 50%; border: none; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: #ffffff22; color: #fff; cursor: pointer;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.img-modal-close svg { display: block; }

/* ── フッター・トースト ── */
.sentinel { text-align: center; padding: 20px 0 8px; color: var(--faint); font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #21262d; color: var(--text); border: 1px solid var(--card-border);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 100;
  box-shadow: 0 6px 24px #0008; white-space: nowrap;
}
.toast button { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 13px; margin-left: 10px; cursor: pointer; }
