/* ── Pale Color Themes ── */
:root, [data-theme="light"] {
  --bg: #fdfcfa;
  --surface: #ffffff;
  --border: #ede8e0;
  --border2: #ddd6ca;
  --text: #3a3530;
  --text2: #6a6058;
  --muted: #a89e94;
  --accent: #b89a7a;
  --accent-hover: #a08868;
  --accent-text: #ffffff;
  --tag-bg: #faf7f2;
  --tag-border: #e8e0d4;
  --tag-active-bg: #b89a7a;
  --tag-active-text: #ffffff;
  --btn-disabled: #ddd6ca;
  --placeholder-text: #d0c8bc;
  --header-bg: #ffffff;
  --sidebar-bg: #fdfcfa;
  --canvas-bg: #faf8f4;
  --chip-bg: #b89a7a;
  --selected-bg: #faf7f2;
}

[data-theme="gray"] {
  --bg: #f0ece6;
  --surface: #f8f5f0;
  --border: #e0d8ce;
  --border2: #cec6ba;
  --text: #3a3530;
  --text2: #5a5248;
  --muted: #988e84;
  --accent: #a08868;
  --accent-hover: #907858;
  --accent-text: #ffffff;
  --tag-bg: #ece8e0;
  --tag-border: #d8d0c4;
  --tag-active-bg: #a08868;
  --tag-active-text: #ffffff;
  --btn-disabled: #cec6ba;
  --placeholder-text: #beb6aa;
  --header-bg: #f8f5f0;
  --sidebar-bg: #f0ece6;
  --canvas-bg: #eae6de;
  --chip-bg: #a08868;
  --selected-bg: #e8e4dc;
}

[data-theme="dark"] {
  --bg: #1e1c18;
  --surface: #28261e;
  --border: #383428;
  --border2: #484438;
  --text: #f0ece4;
  --text2: #c0b8a8;
  --muted: #807868;
  --accent: #c8aa88;
  --accent-hover: #d8ba98;
  --accent-text: #1e1c18;
  --tag-bg: #302c22;
  --tag-border: #484438;
  --tag-active-bg: #c8aa88;
  --tag-active-text: #1e1c18;
  --btn-disabled: #383428;
  --placeholder-text: #383428;
  --header-bg: #242018;
  --sidebar-bg: #1e1c18;
  --canvas-bg: #1a1810;
  --chip-bg: #c8aa88;
  --selected-bg: #2c2820;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Meiryo', 'メイリオ', 'Hiragino Sans', 'ヒラギノ角ゴ ProN', 'Yu Gothic', 'YuGothic', sans-serif;
  font-size: 14px;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ── Header ── */
header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--border);
  padding: 0 20px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
  transition: background 0.3s;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

/* ヘッダーを全幅の背景にしつつ中身を1000px固定 */
.header-wrap {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--header-bg);
  border-bottom: 2px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

.header-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 15px;
  font-weight: bold;
  color: var(--text);
  letter-spacing: 0.02em;
}

.header-title span { color: var(--accent); }

/* Theme switcher */
.theme-switcher {
  display: flex;
  gap: 3px;
  background: var(--bg);
  border: 1.5px solid var(--border2);
  border-radius: 8px;
  padding: 3px;
}

.theme-btn {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1.5px solid transparent;
  cursor: pointer;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-btn:hover { border-color: var(--accent); }
.theme-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.theme-btn .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.2);
}

.theme-btn[data-theme-target="light"] .dot { background: #fffdf7; }
.theme-btn[data-theme-target="gray"]  .dot { background: #f0ede8; }
.theme-btn[data-theme-target="dark"]  .dot { background: #1a1510; }

/* Mobile menu button */
.menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border2);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.2s;
}

.menu-btn:hover { border-color: var(--accent); }

.menu-btn span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: background 0.2s;
}

/* ── Layout wrapper ── */
.layout-wrap {
  max-width: 1000px;
  margin: 0 auto;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  height: calc(100vh - 54px);
}

/* ── Sidebar ── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  transition: background 0.3s, border-color 0.3s;
}

.sidebar-section-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: bold;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.tag-group { margin-bottom: 10px; }

.tag-group-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tag-group-title::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
}

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

.tag {
  padding: 4px 10px;
  border: 1.5px solid var(--tag-border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text2);
  background: var(--tag-bg);
  font-family: inherit;
  line-height: 1.4;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

.tag.active {
  background: var(--tag-active-bg);
  border-color: var(--tag-active-bg);
  color: var(--tag-active-text);
  font-weight: bold;
}

.selected-box {
  background: var(--selected-bg);
  border: 1.5px dashed var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: flex-start;
  transition: background 0.3s, border-color 0.3s;
}

.selected-chip {
  padding: 3px 10px;
  background: var(--chip-bg);
  color: var(--accent-text);
  border-radius: 6px;
  font-size: 11px;
  font-weight: bold;
}

.empty-hint {
  font-size: 12px;
  color: var(--placeholder-text);
  align-self: center;
  transition: color 0.3s;
}

.generate-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: var(--accent-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.04em;
  box-shadow: 0 3px 10px rgba(184, 154, 122, 0.25);
}

.generate-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(184, 154, 122, 0.3);
}

.generate-btn:active:not(:disabled) { transform: translateY(0); }
.generate-btn:disabled { background: var(--btn-disabled); cursor: not-allowed; box-shadow: none; }

/* ── Canvas ── */
.canvas {
  padding: 20px;
  overflow-y: auto;
  background: var(--canvas-bg);
  transition: background 0.3s;
}

.placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--placeholder-text);
}

.placeholder-graphic {
  display: flex;
  gap: 6px;
}

.placeholder-graphic span {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  opacity: 0.3;
}

.placeholder p { font-size: 13px; }

/* loading */
.loading {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-dots {
  display: flex;
  gap: 6px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { background: #d4a882; animation-delay: 0s; }
.loading-dots span:nth-child(2) { background: #a8c4a0; animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { background: #a0b8d0; animation-delay: 0.3s; }
.loading-dots span:nth-child(4) { background: #c4a8c0; animation-delay: 0.45s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}

.loading p { font-size: 12px; color: var(--muted); }

/* ── Result ── */
.result-header {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: 10px;
  border-left: 4px solid var(--accent);
}

.result-keywords {
  font-size: 15px;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 4px;
}

.result-description {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.7;
}

.pattern-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pattern-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  transition: background 0.3s, border-color 0.3s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.pattern-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.pattern-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--text);
}

.pattern-type {
  font-size: 10px;
  color: var(--accent);
  font-weight: bold;
  background: var(--tag-bg);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--tag-border);
  letter-spacing: 0.05em;
}

.color-blocks {
  display: grid;
  grid-template-columns: 1fr 2fr 2fr 1.5fr;
  border-radius: 8px;
  overflow: hidden;
  height: 88px;
  margin-bottom: 8px;
}

.color-block {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 7px 9px;
  cursor: pointer;
  transition: filter 0.15s;
}

.color-block:hover { filter: brightness(0.92); }

.color-block-role {
  font-size: 9px;
  margin-bottom: 2px;
  opacity: 0.8;
  font-weight: bold;
  letter-spacing: 0.03em;
}

.color-block-hex {
  font-size: 11px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
}

.gradient-bar {
  height: 26px;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.pattern-poem {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text2);
  line-height: 1.8;
  font-style: italic;
  padding: 8px 4px;
  border-top: 1px solid var(--border);
}

/* ── Footer ── */
footer {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.8;
  background: var(--bg);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: bold;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(184, 154, 122, 0.35);
}

.toast.show { opacity: 1; transform: translateY(0); }

.error-box {
  padding: 14px 16px;
  background: #fff5f0;
  border: 1.5px solid #ffb088;
  border-radius: 10px;
  font-size: 13px;
  color: #c04020;
  line-height: 1.7;
}

[data-theme="dark"] .error-box {
  background: #2a1810;
  border-color: #5a2810;
  color: #ff9060;
}

/* ── Mobile overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

/* ── Responsive ── */
@media (max-width: 680px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 54px);
  }

  .sidebar {
    position: fixed;
    top: 54px;
    left: -280px;
    width: 280px;
    height: calc(100vh - 54px);
    z-index: 160;
    border-right: 2px solid var(--accent);
    transition: left 0.3s ease, background 0.3s;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }

  .canvas {
    min-height: calc(100vh - 54px);
    padding: 16px;
  }

  .menu-btn { display: flex; }

  .color-blocks {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    height: 140px;
  }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
