/* ===============================
   CSS Variables & Reset
   =============================== */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --secondary: #10b981;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #334155;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

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

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* UI elements use system font */
.header,
.mode-tabs,
.controls,
.font-selector,
.footer,
button,
select,
label,
input,
textarea,
.font-card-header,
.switch-header,
.overlay-controls,
.overlay-legend {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

/* ===============================
   Header
   =============================== */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  color: white;
  padding: 2rem;
  text-align: center;
}

.logo {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.tagline {
  opacity: 0.9;
  font-size: 0.95rem;
}

/* ===============================
   Main Layout
   =============================== */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* ===============================
   Mode Tabs
   =============================== */
.mode-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  padding: 0.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.mode-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.mode-tab:hover {
  background: var(--bg);
  color: var(--text);
}

.mode-tab.active {
  background: var(--primary);
  color: white;
}

.tab-icon {
  font-size: 1.1rem;
}

/* ===============================
   Controls
   =============================== */
.controls {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
}

.control-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

#sample-text {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--transition);
}

#sample-text:focus {
  outline: none;
  border-color: var(--primary);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

select {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
  transition: border-color var(--transition);
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

input[type="color"] {
  width: 100%;
  height: 40px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* ===============================
   Font Selector
   =============================== */
.font-selector {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.font-selector h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

.font-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.font-checkbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.font-checkbox:hover {
  border-color: var(--primary);
}

.font-checkbox.checked {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  border-color: var(--primary);
}

.font-checkbox input {
  display: none;
}

.font-checkbox .checkmark {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.font-checkbox.checked .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.font-checkbox.checked .checkmark::after {
  content: '✓';
  color: white;
  font-size: 12px;
  font-weight: bold;
}

.font-checkbox .font-info {
  flex: 1;
  min-width: 0;
}

.font-checkbox .font-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.font-checkbox .font-type {
  font-size: 0.75rem;
  color: var(--text-light);
}

.selector-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text);
}

.btn-small:hover {
  background: var(--border);
}

/* ===============================
   Compare Area - Grid Mode
   =============================== */
.compare-area {
  min-height: 300px;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.font-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: all var(--transition);
}

.font-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.font-card-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--border);
}

.font-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.font-card-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

.font-card-body {
  padding: 1.5rem;
  transition: all var(--transition);
}

.font-card-text {
  word-break: break-word;
  line-height: 1.8;
}

/* ===============================
   Compare Area - Switch Mode
   =============================== */
.switch-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.switch-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--border);
}

.switch-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.switch-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch-font-name {
  font-size: 1.25rem;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}

.switch-counter {
  font-size: 0.85rem;
  color: var(--text-light);
}

.switch-body {
  padding: 2rem;
  min-height: 200px;
  transition: all var(--transition);
}

.switch-text {
  word-break: break-word;
  line-height: 1.8;
}

.switch-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.switch-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}

.switch-dot.active {
  background: var(--primary);
  transform: scale(1.2);
}

.switch-dot:hover:not(.active) {
  background: var(--text-light);
}

/* ===============================
   Compare Area - Overlay Mode
   =============================== */
.overlay-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.overlay-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.overlay-select-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.overlay-select-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
}

.overlay-select-group select {
  min-width: 180px;
}

.overlay-opacity-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.overlay-opacity-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
}

.overlay-opacity-group input[type="range"] {
  width: 120px;
}

.overlay-body {
  position: relative;
  min-height: 200px;
}

.overlay-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2rem;
  word-break: break-word;
  line-height: 1.8;
  transition: opacity var(--transition);
  /* 文字を正確に重ねるための設定 */
  letter-spacing: 0;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

.overlay-layer.base {
  position: relative;
}

.overlay-layer.top {
  position: absolute;
  pointer-events: none;
}

.overlay-legend {
  display: flex;
  gap: 1.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

/* ===============================
   Compare Area - Blog Mode
   =============================== */
.blog-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.blog-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--border);
}

.blog-select-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.blog-select-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
}

.blog-select-group select {
  min-width: 180px;
}

.blog-font-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.blog-font-name {
  font-weight: 600;
  color: var(--primary);
}

.blog-font-type {
  font-size: 0.8rem;
  color: var(--text-light);
  background: var(--bg);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.blog-preview {
  max-width: 800px;
  margin: 0 auto;
  padding: 3rem;
  background: #fff;
  line-height: 1.9;
}

.blog-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.blog-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.blog-category {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
}

.blog-date {
  font-size: 0.85rem;
  color: var(--text-light);
}

.blog-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 1rem;
  color: var(--text);
}

.blog-lead {
  font-size: 1.1rem;
  color: var(--text-light);
  line-height: 1.8;
}

.blog-body h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary);
  color: var(--text);
}

.blog-body h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 1.5rem 0 1rem;
  color: var(--text);
}

.blog-body p {
  margin-bottom: 1.25rem;
  color: var(--text);
}

.blog-quote {
  margin: 2rem 0;
  padding: 1.5rem 2rem;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.blog-quote p {
  margin: 0;
  font-style: italic;
  color: var(--text);
}

.blog-list {
  margin: 1rem 0 1.5rem;
  padding-left: 1.5rem;
}

.blog-list li {
  margin-bottom: 0.5rem;
  color: var(--text);
}

.blog-list li::marker {
  color: var(--primary);
}

.blog-code {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  background: #1e293b;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.blog-code code {
  font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9rem;
  color: #e2e8f0;
}

@media (max-width: 768px) {
  .blog-preview {
    padding: 1.5rem;
  }

  .blog-title {
    font-size: 1.5rem;
  }

  .blog-body h2 {
    font-size: 1.25rem;
  }

  .blog-font-info {
    margin-left: 0;
    width: 100%;
  }
}

/* ===============================
   Footer
   =============================== */
.footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
  font-size: 0.85rem;
}

/* ===============================
   Empty State
   =============================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-light);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 1rem;
}

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

.font-card {
  animation: fadeIn 0.3s ease forwards;
}

.font-card:nth-child(1) { animation-delay: 0.05s; }
.font-card:nth-child(2) { animation-delay: 0.1s; }
.font-card:nth-child(3) { animation-delay: 0.15s; }
.font-card:nth-child(4) { animation-delay: 0.2s; }
.font-card:nth-child(5) { animation-delay: 0.25s; }
.font-card:nth-child(6) { animation-delay: 0.3s; }
.font-card:nth-child(7) { animation-delay: 0.35s; }
.font-card:nth-child(8) { animation-delay: 0.4s; }

/* ===============================
   Responsive
   =============================== */
@media (max-width: 768px) {
  .main {
    padding: 1rem;
  }

  .mode-tabs {
    flex-direction: column;
  }

  .mode-tab {
    justify-content: flex-start;
  }

  .control-row {
    grid-template-columns: 1fr 1fr;
  }

  .font-checkboxes {
    grid-template-columns: 1fr;
  }

  .overlay-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .overlay-opacity-group {
    margin-left: 0;
  }

  .switch-font-name {
    min-width: auto;
    font-size: 1rem;
  }
}
