/* =============================================================
   botchitter — 基本スタイル・テーマ・レイアウト・共通UI (style.css)
============================================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

/* ライトテーマ */
:root {
  --bg: #F7F7F4;
  --card: #FFFFFF;
  --quote-bg: #EFEFEA;
  --quote-hover: #E8E8E2;
  --reply-bg: #F0F0EB;
  --text-primary: #181817;
  --text-secondary: #76766E;
  --text-tertiary: #B4B4AC;
  --line: #E4E4DE;
  --header-bg: rgba(247, 247, 244, 0.92);
  --btn-bg: #181817;
  --btn-text: #F7F7F4;
  --danger: #D9534F;
  --tag: #4F6F96;
  --tag-bg: rgba(79, 111, 150, 0.16);
  --heat-0: #E6E6E0;
  --mood-1: #4E6A9E;
  --mood-2: #8FA8CF;
  --mood-3: #BDBDB3;
  --mood-4: #E3BE63;
  --mood-5: #E5864A;
  --mood-none: #D3D3CB;
  --hover-overlay: rgba(0, 0, 0, 0.03);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

/* ダークテーマ */
[data-theme="dark"] {
  --bg: #141413;
  --card: #1C1C1A;
  --quote-bg: #222220;
  --quote-hover: #2B2B28;
  --reply-bg: #1F1F1D;
  --text-primary: #ECECE6;
  --text-secondary: #94948C;
  --text-tertiary: #5E5E58;
  --line: #282826;
  --header-bg: rgba(20, 20, 19, 0.92);
  --btn-bg: #ECECE6;
  --btn-text: #141413;
  --danger: #FF6B6B;
  --tag: #8EAAD0;
  --tag-bg: rgba(142, 170, 208, 0.22);
  --heat-0: #252523;
  --mood-1: #6382BD;
  --mood-2: #8A9FC2;
  --mood-3: #7A7A72;
  --mood-4: #CDAA55;
  --mood-5: #DC7C42;
  --mood-none: #3A3A37;
  --hover-overlay: rgba(255, 255, 255, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --card: #1C1C1A;
    --quote-bg: #222220;
    --quote-hover: #2B2B28;
    --reply-bg: #1F1F1D;
    --text-primary: #ECECE6;
    --text-secondary: #94948C;
    --text-tertiary: #5E5E58;
    --line: #282826;
    --header-bg: rgba(20, 20, 19, 0.92);
    --btn-bg: #ECECE6;
    --btn-text: #141413;
    --danger: #FF6B6B;
    --tag: #8EAAD0;
    --tag-bg: rgba(142, 170, 208, 0.22);
    --heat-0: #252523;
    --mood-1: #6382BD;
    --mood-2: #8A9FC2;
    --mood-3: #7A7A72;
    --mood-4: #CDAA55;
    --mood-5: #DC7C42;
    --mood-none: #3A3A37;
    --hover-overlay: rgba(255, 255, 255, 0.04);
  }
}

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  height: 100%;
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* iOS Safari 自動ズーム防止：フォントサイズ16px以上を徹底 */
input,
textarea,
select {
  font-size: 16px !important;
}

/* iPhone等でキーボード表示中、入力位置がキーボードの後ろに隠れないようスクロール余白を確保 */
body:has(.composer-textarea:focus),
body:has(.detail-composer-textarea:focus),
body.keyboard-open {
  padding-bottom: 50vh !important;
}

.viewport {
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: calc(24px + env(safe-area-inset-left, 0px));
  padding-right: calc(24px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

/* ヘッダー: iPhone Dynamic Island / ノッチ (Safe Area Insets) 対応 */
header {
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  margin-left: calc(-24px - env(safe-area-inset-left, 0px));
  margin-right: calc(-24px - env(safe-area-inset-right, 0px));
  padding-left: calc(24px + env(safe-area-inset-left, 0px));
  padding-right: calc(24px + env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 20;
  border-bottom: 1px solid var(--line);
}

.header-left,
.header-right {
  height: 56px;
  display: flex;
  align-items: center;
}

.header-left {
  gap: 12px;
}

.header-right {
  gap: 14px;
}

.btn-back {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.btn-back.show {
  display: flex;
  align-items: center;
}
.btn-back svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.logo-mark {
  width: auto;
  height: 18px;
  color: var(--text-primary);
  opacity: 0.82;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease;
  flex-shrink: 0;
}
.logo:hover .logo-mark {
  opacity: 1;
  transform: rotate(-6deg) scale(1.05);
}
.logo:active .logo-mark {
  transform: scale(0.92);
}

.header-date {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}
.header-date:hover {
  color: var(--text-primary);
  background: var(--hover-overlay);
}

.header-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background-color 0.15s;
}
.header-icon-btn:hover {
  color: var(--text-primary);
  background: var(--hover-overlay);
}
.header-icon-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

/* 基本アニメーション */
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInTweet {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 削除確認ダイアログ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
  transform: translateZ(0);
  will-change: opacity;
}
.confirm-overlay.open {
  display: flex;
  opacity: 1;
}

.confirm-dialog {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
  width: 88%;
  max-width: 320px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
  animation: scaleIn 0.2s var(--ease-out);
  transform: translateZ(0);
}

.confirm-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-confirm-cancel {
  background: transparent;
  border: none;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-confirm-cancel:hover {
  color: var(--text-primary);
  background: var(--hover-overlay);
}

.btn-confirm-danger {
  background: var(--danger);
  color: #FFFFFF;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-confirm-danger:hover {
  opacity: 0.88;
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  color: var(--text-primary);
  border: 1px solid var(--line);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
  z-index: 2000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ホーム画面追加の案内（iOS Safari のタブで開いた時だけ） */
.install-hint {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.install-hint.show {
  display: flex;
}

/* メニュー（テーマ・バックアップ等） */
.menu-dialog {
  padding: 6px 0;
  overflow: hidden;
}

.menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  color: var(--text-primary);
  padding: 13px 20px;
  cursor: pointer;
}
button.menu-item:hover {
  background: var(--hover-overlay);
}
.menu-item + .menu-item {
  border-top: 1px solid var(--line);
}

.menu-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: default;
}

.menu-item-label {
  font-size: 14px;
  color: var(--text-primary);
}

/* テーマ切り替え（太陽・月） */
.segmented-control {
  display: inline-flex;
  align-items: center;
  background: var(--quote-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}
.segmented-btn:hover {
  color: var(--text-primary);
}
.segmented-btn.is-active {
  background: var(--card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* バックアップ（書き出し・読み込み） */
.menu-action-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.menu-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--quote-bg);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}
.menu-action-btn:hover {
  background: var(--quote-hover);
  border-color: var(--text-tertiary);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
