/* ==========================================================================
   CSS Variables & Theme Setup
   ========================================================================== */
:root {
  /* Font Families */
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Common Transitions */
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Box Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.2);
}

/* Light Theme Variables */
.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --accent-primary: #6366f1; /* Indigo */
  --accent-secondary: #3b82f6; /* Blue */
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
  
  --border-color: rgba(226, 232, 240, 0.8);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-blur: 12px;
  
  --card-hover-border: rgba(99, 102, 241, 0.3);
  
  --error-bg: #fef2f2;
  --error-text: #ef4444;
  --error-border: #fecaca;
}

/* Dark Theme Variables */
.dark-theme {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  
  --accent-primary: #818cf8; /* Light Indigo */
  --accent-secondary: #60a5fa; /* Light Blue */
  --accent-gradient: linear-gradient(135deg, #818cf8 0%, #60a5fa 100%);
  
  --border-color: rgba(37, 99, 235, 0.1);
  --glass-bg: rgba(17, 24, 39, 0.7);
  --glass-border: rgba(255, 255, 255, 0.05);
  --glass-blur: 16px;
  
  --card-hover-border: rgba(129, 140, 248, 0.4);
  
  --error-bg: rgba(239, 68, 68, 0.1);
  --error-text: #fca5a5;
  --error-border: rgba(239, 68, 68, 0.2);
}

/* ==========================================================================
   Base Styles & Reset
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

/* Scrollbar Style */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   Layout & Container
   ========================================================================== */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  gap: 30px;
  min-height: 100vh;
}

/* ==========================================================================
   UI Components: Glassmorphism & Cards
   ========================================================================== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
}

.card {
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(99, 102, 241, 0.4);
  opacity: 0.95;
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--accent-primary);
  color: var(--accent-primary);
}
.btn-outline:hover {
  background: var(--accent-primary);
  color: #ffffff;
}

.btn-loader {
  animation: spin 1s linear infinite;
}

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

/* ==========================================================================
   Header Section
   ========================================================================== */
.app-header {
  text-align: center;
  margin-bottom: 10px;
}

.header-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  color: var(--accent-primary);
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.5));
}

.app-header h1 {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 400;
}

/* ==========================================================================
   Feed Input Section
   ========================================================================== */
.input-group-container {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.input-group {
  position: relative;
  flex: 1;
}

.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.input-group input {
  width: 100%;
  padding: 14px 16px 14px 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-body);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Preset Tags */
.preset-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.preset-label {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.preset-label i {
  width: 14px;
  height: 14px;
}

.preset-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tag:hover, .tag.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

/* ==========================================================================
   Control Bar (Search & Options)
   ========================================================================== */
.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
}

.search-box {
  position: relative;
  max-width: 320px;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Dropdown/Select Styling */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 36px 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.select-wrapper select:focus {
  border-color: var(--accent-primary);
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-30%) rotate(45deg);
  width: 5px;
  height: 5px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  pointer-events: none;
}

/* Layout and Theme Toggle Buttons */
.layout-toggle {
  display: flex;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: calc(var(--radius-sm) - 2px);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toggle-btn:hover {
  color: var(--text-primary);
}

.toggle-btn.active {
  background: var(--bg-secondary);
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

#themeToggleBtn {
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

#themeToggleBtn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Show/hide icons depending on active theme */
.light-theme .sun-icon { display: none; }
.light-theme .moon-icon { display: block; }
.dark-theme .sun-icon { display: block; }
.dark-theme .moon-icon { display: none; }

/* ==========================================================================
   Feed Meta & Information
   ========================================================================== */
.feed-meta {
  margin: 10px 0;
  animation: fadeIn 0.4s ease-out;
}

.feed-meta h2 {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ==========================================================================
   Articles Grid / List Layout
   ========================================================================== */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Article Card Style */
.article-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.article-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-hover-border);
  box-shadow: var(--shadow-md);
}

.card-image-wrapper {
  position: relative;
  width: 100%;
  padding-top: 52%; /* 1.91:1 Aspect Ratio */
  background: var(--bg-tertiary);
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-normal);
}

.article-card:hover .card-image {
  transform: scale(1.05);
}

.card-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.card-meta-item i {
  width: 12px;
  height: 12px;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 10px;
}

.card-title a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.card-title a:hover {
  color: var(--accent-primary);
}

.card-description {
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 18px;
  flex: 1;
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: auto;
}

.read-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary);
  text-decoration: none;
  transition: gap var(--transition-fast);
}

.read-more:hover {
  gap: 10px;
}

/* ==========================================================================
   List View Custom Overrides
   ========================================================================== */
.feed-list .article-card {
  flex-direction: row;
  min-height: 140px;
}

.feed-list .card-image-wrapper {
  width: 240px;
  height: auto;
  padding-top: 0;
  border-bottom: none;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
}

.feed-list .card-body {
  padding: 16px 24px;
}

.feed-list .card-description {
  -webkit-line-clamp: 2;
}

/* List view responsivness: fallback to grid-like on small mobile */
@media (max-width: 768px) {
  .feed-list .article-card {
    flex-direction: column;
  }
  .feed-list .card-image-wrapper {
    width: 100%;
    padding-top: 52%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}

/* ==========================================================================
   Status Containers (Loading, Error)
   ========================================================================== */
.status-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  animation: fadeIn 0.3s ease-out;
}

.status-container p {
  margin-top: 16px;
  color: var(--text-secondary);
}

.error-card {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  max-width: 500px;
  margin: 40px auto;
  padding: 32px;
}

.error-icon {
  width: 48px;
  height: 48px;
  color: var(--error-text);
  margin-bottom: 16px;
}

.error-card h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--error-text);
}

.error-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0;
  margin-bottom: 24px;
}

/* Spinner Ripple Effect */
.spinner-ripple {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.spinner-ripple div {
  position: absolute;
  border: 4px solid var(--accent-primary);
  opacity: 1;
  border-radius: 50%;
  animation: spinner-ripple-anim 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.spinner-ripple div:nth-child(2) {
  animation-delay: -0.5s;
}

@keyframes spinner-ripple-anim {
  0% {
    top: 36px;
    left: 36px;
    width: 0;
    height: 0;
    opacity: 0;
  }
  4.9% {
    top: 36px;
    left: 36px;
    width: 0;
    height: 0;
    opacity: 0;
  }
  5% {
    top: 36px;
    left: 36px;
    width: 0;
    height: 0;
    opacity: 1;
  }
  100% {
    top: 0px;
    left: 0px;
    width: 72px;
    height: 72px;
    opacity: 0;
  }
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  margin-top: auto;
  text-align: center;
  padding-top: 40px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   Iframe Embedding / Embed Mode (.embed-mode)
   ========================================================================== */
body.embed-mode {
  background-color: var(--bg-primary); /* テーマ標準の背景色（ライトなら薄いグレー、ダークなら深紺色） */
}

.embed-mode .app-container {
  padding: 10px; /* 最小限の余白 */
  gap: 16px;
  min-height: auto;
}

/* 埋め込みモード時に不要な要素を隠す */
.embed-mode #appHeader,
.embed-mode #inputSection,
.embed-mode #appFooter,
.embed-mode #themeToggleBtn {
  display: none !important;
}

/* 埋め込み時のカード背景 */
.embed-mode .article-card {
  box-shadow: none;
}
.embed-mode .glass {
  background: var(--bg-secondary); /* ぼかしが親サイトの背景と干渉するのを防ぐ */
}

/* ==========================================================================
   Responsive adjustments
   ========================================================================== */
@media (max-width: 640px) {
  .app-container {
    padding: 20px 12px;
    gap: 20px;
  }

  .app-header h1 {
    font-size: 2rem;
  }

  .input-group-container {
    flex-direction: column;
  }

  .control-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px;
  }

  .search-box {
    max-width: 100%;
  }

  .controls-right {
    justify-content: space-between;
  }
}
