:root {
  --bg-base: #0e0f13;
  --bg-surface: #161820;
  --bg-elevated: #1e212c;
  --bg-input: #12141b;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-photo: #38bdf8;
  --accent-photo-soft: rgba(56, 189, 248, 0.16);
  --accent-illustration: #c084fc;
  --accent-illustration-soft: rgba(192, 132, 252, 0.16);

  --accent: var(--accent-photo);
  --accent-soft: var(--accent-photo-soft);
  --accent-text: #09131c;

  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.18);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body[data-room="illustration"] {
  --accent: var(--accent-illustration);
  --accent-soft: var(--accent-illustration-soft);
  --accent-text: #160a22;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

[hidden] {
  display: none !important;
}

.app-shell {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(92px + var(--safe-bottom));
}

/* =========================================
   最上部：ブラウザタブ風ヘッダー
   ========================================= */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 0;
  background-color: #090a0d;
  border-bottom: 1px solid var(--border-subtle);
}

.room-tabs {
  display: flex;
  flex: 1;
  gap: 6px;
  align-items: flex-end;
}

.room-tab {
  position: relative;
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px 12px 0 0;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-bottom: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.room-tab .tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  opacity: 0.45;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.room-tab[data-category="photo"] .tab-dot {
  background-color: var(--accent-photo);
}

.room-tab[data-category="illustration"] .tab-dot {
  background-color: var(--accent-illustration);
}

.room-tab.is-active {
  background-color: var(--bg-base);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  margin-bottom: -1px;
  padding-bottom: 1px;
}

.room-tab.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 2.5px;
  border-radius: 0 0 4px 4px;
  background-color: var(--accent);
}

.room-tab.is-active .tab-dot {
  opacity: 1;
  transform: scale(1.15);
}

.tab-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-secondary);
}

.room-tab.is-active .tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.icon-btn:active {
  transform: scale(0.93);
  background-color: rgba(255, 255, 255, 0.08);
}

.settings-btn {
  margin-bottom: 4px;
  flex-shrink: 0;
}

/* =========================================
   検索・お気に入り・タグフィルター
   ========================================= */
.controls-bar {
  position: sticky;
  top: calc(54px + var(--safe-top));
  z-index: 25;
  background: linear-gradient(180deg, var(--bg-base) 85%, rgba(14, 15, 19, 0));
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  height: 42px;
  padding: 0 10px 0 12px;
  transition: border-color 0.18s ease;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 8px;
}

.search-box input {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-primary);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.clear-search-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-secondary);
}

.fav-filter-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition: all 0.18s ease;
}

.fav-filter-btn.is-active {
  background-color: var(--gold-soft);
  border-color: rgba(251, 191, 36, 0.45);
  color: var(--gold);
}

.fav-filter-btn.is-active svg {
  fill: var(--gold);
}

.tag-filter-bar {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tag-filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex-shrink: 0;
  height: 31px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all 0.15s ease;
}

.filter-chip.is-active {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* =========================================
   メイン：2列グリッドカード
   ========================================= */
.main-content {
  flex: 1;
  padding: 2px 12px 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 560px) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
}

.prompt-card {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
  transition: transform 0.14s ease, border-color 0.18s ease;
}

.prompt-card:active {
  transform: scale(0.975);
}

.prompt-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 15, 19, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.14s ease, color 0.14s ease, background-color 0.14s ease;
}

.card-fav-btn:active {
  transform: scale(0.88);
}

.card-fav-btn.is-fav {
  color: var(--gold);
  background: rgba(14, 15, 19, 0.75);
}

.card-fav-btn.is-fav svg {
  fill: var(--gold);
}

.card-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 24px 8px 8px;
  background: linear-gradient(180deg, rgba(14, 15, 19, 0) 0%, rgba(14, 15, 19, 0.86) 100%);
  pointer-events: none;
}

.card-tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow: hidden;
}

.card-tag {
  font-size: 10.5px;
  line-height: 1.2;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: rgba(248, 250, 252, 0.92);
  white-space: nowrap;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 空状態 */
.empty-state {
  text-align: center;
  padding: 72px 24px 48px;
  color: var(--text-secondary);
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-desc {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

/* =========================================
   フローティング「＋」ボタン
   ========================================= */
.fab-add {
  position: fixed;
  right: max(20px, calc(50% - 340px + 20px));
  bottom: calc(22px + var(--safe-bottom));
  z-index: 40;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background-color: var(--accent);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.fab-add:active {
  transform: scale(0.92);
}

/* =========================================
   ボトムシート風モーダル
   ========================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 6, 9, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.16s ease-out;
}

.modal-sheet {
  width: 100%;
  max-width: 640px;
  max-height: 90dvh;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-sheet-tall {
  max-height: 94dvh;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  margin: 9px auto 2px;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 10px 18px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sheet-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

.detail-body {
  padding-bottom: 20px;
}

.sheet-footer {
  padding-top: 4px;
}

.sticky-footer {
  padding: 12px 16px calc(14px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* フォーム要素 */
.form-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.auto-tag-hint {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 500;
}

.segment-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background-color: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.segment-btn {
  height: 36px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.16s ease;
}

.segment-btn.is-active {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* 画像ピッカー */
.image-picker {
  display: block;
  border-radius: var(--radius-md);
  border: 1.5px dashed var(--border-strong);
  background-color: var(--bg-input);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.18s ease;
}

.image-picker:active {
  border-color: var(--accent);
}

.image-picker-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 16px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.image-picker-placeholder small {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 400;
}

.image-preview-wrap {
  position: relative;
  width: 100%;
  max-height: 240px;
  background: #0a0b0e;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview-wrap img {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
}

.image-meta-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(14, 15, 19, 0.78);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.image-change-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(14, 15, 19, 0.78);
  color: var(--text-secondary);
}

/* テキスト入力 */
.prompt-textarea,
.text-input {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.16s ease;
}

.prompt-textarea {
  resize: vertical;
  min-height: 98px;
  line-height: 1.55;
}

.prompt-textarea:focus,
.text-input:focus {
  border-color: var(--accent);
}

.prompt-textarea::placeholder,
.text-input::placeholder {
  color: var(--text-muted);
}

/* タグチップ一覧（選択用） */
.tag-chips-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 12px;
}

.tag-pool-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0;
}

.selectable-chip {
  height: 33px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  transition: all 0.14s ease;
}

.selectable-chip.is-selected {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.new-tag-row {
  display: flex;
  gap: 8px;
}

.new-tag-row .text-input {
  flex: 1;
  height: 40px;
  padding: 0 12px;
}

/* ボタン */
.primary-btn {
  width: 100%;
  height: 48px;
  border-radius: var(--radius-md);
  background-color: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

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

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.copy-hero-btn {
  height: 52px;
  font-size: 15.5px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.secondary-btn {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.14s ease, transform 0.12s ease;
}

.secondary-btn:active {
  transform: scale(0.97);
  background-color: rgba(255, 255, 255, 0.12);
}

.small-btn {
  height: 40px;
  width: auto;
  padding: 0 20px;
  font-size: 13.5px;
}

.text-action-btn {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  padding: 2px 6px;
}

.file-btn-label {
  width: 100%;
  height: 46px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.danger-outline-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(248, 113, 113, 0.38);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
}

/* =========================================
   詳細モーダル専用
   ========================================= */
.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.room-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.fav-action-btn.is-fav {
  color: var(--gold);
}

.fav-action-btn.is-fav svg {
  fill: var(--gold);
}

.danger-icon-btn:active {
  color: var(--danger);
}

.detail-image-box {
  width: 100%;
  max-height: 40dvh;
  background-color: #090a0d;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-image-box img {
  max-width: 100%;
  max-height: 40dvh;
  object-fit: contain;
  display: block;
}

.detail-prompt-box {
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  user-select: text;
}

.inline-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* =========================================
   設定モーダル
   ========================================= */
.stats-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-item {
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-subtitle {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.settings-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}

.danger-zone {
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

/* =========================================
   トースト通知
   ========================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 200;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(24, 27, 36, 0.96);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  animation: toastIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(28px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toastIn {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
