/* Ampoule Picker
   デザイン方針：project_08 Melo no Boutique に準拠
   （クリーム地・こげ茶文字・パステル少色・まるゴシック・角丸・細ボーダー） */

:root {
  --bg: #fdf9f2; /* クリーム */
  --ink: #3d2b22; /* こげ茶（基本文字色） */
  --pink: #f6cdd8;
  --pink-deep: #d98ba3;
  --mint: #cce8db;
  --mint-deep: #6faf93;
  --peach: #fbe3c9;
  --lemon: #f9ecb4;
  --line: #f0e4d6;
  --card: #ffffff;
  --muted: #a3948a;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic', sans-serif;
  font-weight: 400;
  line-height: 1.9;
  letter-spacing: 0.03em;
}

/* ---- ホームへ戻る（サイト上部の導線） ---- */
.home-bar {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.8rem 1.2rem 0;
  font-size: 0.85rem;
}
.home-bar a {
  color: var(--pink-deep);
  text-decoration: none;
}
.home-bar a:hover {
  text-decoration: underline;
}

/* ---- ヘッダー ---- */
.app-header {
  padding: 2.2rem 1.5rem 1.2rem;
  text-align: center;
}
.brand {
  margin: 0;
  font-family: 'Mochiy Pop One', 'Zen Maru Gothic', sans-serif;
  font-weight: 400;
  font-size: clamp(1.5rem, 6vw, 2.1rem);
  color: var(--pink-deep);
  letter-spacing: 0.08em;
}
.tagline {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--mint-deep);
}
.usage-link {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
}
.usage-link a {
  color: var(--pink-deep);
  text-decoration: none;
  border-bottom: 1px dotted var(--pink-deep);
  padding-bottom: 1px;
}
.usage-link a:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---- メイン ---- */
.app-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 1.2rem 4rem;
}

.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 1.1rem 1.2rem;
}

/* ---- コントロール ---- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.control-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.7rem;
}
.control-label {
  font-size: 0.82rem;
  color: var(--mint-deep);
  min-width: 4.4em;
}
.toolbar .sort-label {
  min-width: 0;
  margin-left: 0.3rem;
}
.search-input,
.select {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem 0.8rem;
  outline: none;
}
.search-input {
  flex: 1;
  min-width: 12rem;
}
.search-input:focus,
.select:focus {
  border-color: var(--pink-deep);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
/* 色相の「すべて」だけを1行目に孤立させる強制改行 */
.pill-break {
  flex-basis: 100%;
  height: 0;
  margin: 0;
}
.pill {
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.8rem;
  cursor: pointer;
  transition: all 0.12s ease;
}
.pill:hover {
  border-color: var(--pink);
}
.pill.is-active {
  background: var(--pink);
  border-color: var(--pink-deep);
  color: var(--ink);
}
/* 「指定なし」は選択中だけ「直感モードに切り替え」と同じライム/ミント色。
   非選択時は通常のピル色（元の色）のまま。 */
.pill-none.is-active {
  background: var(--mint);
  border-color: var(--mint-deep);
  color: var(--ink);
}
.pill .dot {
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  border-radius: 50%;
  margin-right: 0.35em;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--mint);
  border: 1.5px solid var(--mint-deep);
  border-radius: 12px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  transition: all 0.12s ease;
}
.btn:hover {
  filter: brightness(1.03);
}
.btn-ghost {
  background: var(--bg);
  border-color: var(--line);
  color: var(--muted);
}
.btn-more {
  display: block;
  margin: 1.4rem auto 0;
  background: var(--peach);
  border-color: #e6c39a;
  padding: 0.5rem 1.8rem;
}

/* ---- 現在モードの表示（直感／詳細を大きめに） ---- */
.mode-label {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.mode-now {
  font-family: 'Mochiy Pop One', 'Zen Maru Gothic', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
}
.mode-space {
  font-size: 0.82rem;
  color: var(--mint-deep);
}

/* ---- フィルタ領域（直感／詳細） ---- */
.filter-area {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  border-top: 1.5px dashed var(--line);
  padding-top: 0.9rem;
}

/* 詳細モードのコンテナ */
.detail-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem 1.6rem;
  align-items: flex-start;
}

/* ---- 詳細モード：横バー（2ピン） ---- */
.bars {
  flex: 1;
  min-width: 15rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding-top: 0.2rem;
}
.bar-wrap {
  width: 100%;
}
.bar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem; /* ▽マーカーがバー上に刺さる余白 */
}
.bar-name {
  font-size: 0.8rem;
  color: var(--mint-deep);
}
.bar-val {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bar-track {
  position: relative;
  height: 20px; /* 太さを伴うバー */
  border-radius: 999px;
  border: 1.5px solid var(--line);
  cursor: pointer;
  touch-action: none;
}
/* 選択範囲：ピンクで囲む */
.bar-sel {
  position: absolute;
  top: -1.5px;
  bottom: -1.5px;
  border: 2px solid var(--pink-deep);
  border-radius: 999px;
  background: rgba(217, 139, 163, 0.14);
  pointer-events: none;
}
.bar-thumb {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--pink-deep);
  transform: translateY(-50%);
  box-shadow: 0 1px 3px rgba(61, 43, 34, 0.25);
  cursor: grab;
  touch-action: none;
  z-index: 2; /* 選択色マーカーより前面に */
}
/* 選択色のこの軸での位置を刺す▽（バーの上＝外から下向き・色はその色） */
.bar-marker {
  position: absolute;
  top: -9px;
  margin-left: -6px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 9px solid var(--ink); /* 色はJSで選択色に差し替え */
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 0 1px rgba(61, 43, 34, 0.6));
}
.bar-thumb:active {
  cursor: grabbing;
}

/* ---- 詳細モード：色相リング（円形・0跨ぎOK） ---- */
.hue-wrap {
  position: relative;
  flex: none;
}
.hue-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    hsl(0, 85%, 55%),
    hsl(30, 85%, 55%),
    hsl(60, 85%, 55%),
    hsl(90, 85%, 55%),
    hsl(120, 85%, 55%),
    hsl(150, 85%, 55%),
    hsl(180, 85%, 55%),
    hsl(210, 85%, 55%),
    hsl(240, 85%, 55%),
    hsl(270, 85%, 55%),
    hsl(300, 85%, 55%),
    hsl(330, 85%, 55%),
    hsl(360, 85%, 55%)
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 27px), #000 calc(100% - 26px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 27px), #000 calc(100% - 26px));
}
.hue-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.hue-arc {
  fill: none;
  stroke: var(--pink-deep);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.95;
}
.hue-handle {
  fill: #fff;
  stroke: var(--pink-deep);
  stroke-width: 2.5;
  cursor: grab;
}
/* 選択色の色相位置を刺す▽（塗りはその色・白フチ＋影で視認性確保） */
.hue-marker {
  stroke: #fff;
  stroke-width: 1.5;
  stroke-linejoin: round;
  paint-order: stroke;
  pointer-events: none;
  filter: drop-shadow(0 0 1.5px rgba(61, 43, 34, 0.7));
}
.hue-val {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.82rem;
  color: var(--ink);
  text-align: center;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.hue-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}
.hue-caption {
  text-align: center;
  font-size: 0.78rem;
  color: var(--mint-deep);
  margin: 0;
}
.btn-hue-all {
  background: var(--mint);
  border-color: var(--mint-deep);
  padding: 0.3rem 1.2rem;
  font-size: 0.8rem;
}

/* ---- 詳細パネル ---- */
.detail {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.detail-swatch {
  width: 84px;
  height: 84px;
  flex: none;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 / 16px 16px;
}
.detail.is-empty .detail-swatch {
  opacity: 0.4;
}
.detail-body {
  flex: 1;
  min-width: 0;
}
.detail-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.detail-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.9rem;
  font-size: 0.9rem;
}
.detail-list > div {
  display: contents;
}
.detail-list dt {
  color: var(--mint-deep);
  font-size: 0.8rem;
}
.detail-list dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.hex-copy {
  font-family: 'Mochiy Pop One', monospace;
  font-size: 0.95rem;
  color: var(--pink-deep);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  letter-spacing: 0.06em;
}
.hex-copy:hover {
  text-decoration: underline;
}

/* ---- 件数表示 ---- */
.result-meta {
  margin: 1.2rem 0.2rem 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---- 並びソート（色一覧のすぐ上） ---- */
.sort-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.6rem;
  margin: 0 0.2rem 0.8rem;
}
.sort-bar .sort-label {
  min-width: 0;
}

/* ---- スウォッチ一覧 ---- */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.6rem;
}
.swatch {
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  background: var(--card);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.swatch:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(61, 43, 34, 0.12);
}
.swatch.is-selected {
  border-color: var(--pink-deep);
  box-shadow: 0 0 0 2px var(--pink);
}
.swatch-chip {
  height: 56px;
  width: 100%;
  display: block;
}
.swatch-code {
  display: block;
  padding: 0.25rem 0.1rem 0.3rem;
  font-size: 0.68rem;
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ---- SV空間（彩度×明度の2Dプロット） ---- */
.sv-space {
  position: relative;
  width: 100%; /* 一覧と同じ横幅いっぱいに広げる */
  aspect-ratio: 1 / 1;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  user-select: none; /* ドラッグ移動中に文字選択されないように */
}
.sv-plot {
  position: absolute;
  top: 22px;
  right: 18px;
  bottom: 32px;
  left: 40px;
  z-index: 1;
  background: #fffdf9;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden; /* ズームは枠内だけ（軸ラベルは外側なので常に見える） */
}
.sv-content {
  position: absolute;
  inset: 2.5%;
  --z: 1;
  transform-origin: 0 0; /* ズームの基準を左上に */
  /* S・V 10刻みのグリッド（ドットと一緒にズーム・パンする） */
  background-image: linear-gradient(to right, rgba(240, 228, 214, 0.7) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(240, 228, 214, 0.7) 1px, transparent 1px);
  background-size: 10% 10%;
}
.sv-title {
  position: absolute;
  font-size: 0.74rem;
  color: var(--mint-deep);
  z-index: 4; /* ズームしたプロットより前面に */
}
.sv-hint {
  position: absolute;
  top: 7px;
  right: 12px;
  font-size: 0.62rem;
  color: var(--muted);
  z-index: 4;
  pointer-events: none;
}
.sv-title-x {
  left: 40px;
  right: 18px;
  bottom: 9px;
  text-align: center;
}
.sv-title-y {
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
}
.sv-tick {
  position: absolute;
  font-size: 0.62rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  z-index: 4;
}
.tick-tl {
  top: 15px;
  left: 12px;
}
.tick-bl {
  bottom: 24px;
  left: 24px;
}
.tick-br {
  bottom: 13px;
  right: 16px;
}
.sv-color-dot {
  position: absolute;
  /* 位置は content のズームで動くが、ドット自体は 1/z で等倍を保つ（重なりを見るため） */
  transform: translate(-50%, -50%) scale(calc(1 / var(--z, 1)));
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 3px rgba(61, 43, 34, 0.28);
  cursor: pointer;
  transition: box-shadow 0.12s ease;
}
.sv-color-dot:hover {
  transform: translate(-50%, -50%) scale(calc(1.4 / var(--z, 1)));
  z-index: 10;
  box-shadow: 0 2px 8px rgba(61, 43, 34, 0.4);
}
.sv-color-dot.is-selected {
  box-shadow: 0 0 0 2.5px var(--pink-deep);
  z-index: 9;
}
.sv-sm {
  width: 11px;
  height: 11px;
}
.sv-md {
  width: 15px;
  height: 15px;
}
.sv-lg {
  width: 20px;
  height: 20px;
}

/* SV空間：同一位置の複数色を選ぶポップオーバー */
.sv-popover {
  position: fixed;
  z-index: 50;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(61, 43, 34, 0.22);
  padding: 0.6rem 0.7rem;
  max-width: 250px;
}
.sv-popover-title {
  font-size: 0.72rem;
  color: var(--mint-deep);
  margin-bottom: 0.45rem;
  font-variant-numeric: tabular-nums;
}
.sv-popover-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.3rem;
  max-height: 168px;
  overflow-y: auto;
}
.sv-popover-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.sv-popover-swatch:hover {
  border-color: var(--pink-deep);
  transform: scale(1.1);
}

/* ---- フッター ---- */
.app-footer {
  padding: 2rem 1.5rem 3rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}
.app-footer p {
  margin: 0.15rem 0;
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.6rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .swatch-grid {
    grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  }
  .swatch-chip {
    height: 46px;
  }
}
