/* ネイルデザインシミュレーター — Author: 井上康文
   モバイル/タブレット・タッチ最優先。淡い中立の下地で手と色見本が主役。1アクセント。 */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-warm: #f7f1ec;
  --text: #25211f;
  --muted: #8a817b;
  --muted-2: #b3aaa2;
  --primary: #a84f62;
  --primary-hv: #8f3f52;
  --primary-soft: #f6e7eb;
  --secondary: #7f9478;
  --secondary-soft: #edf2e9;
  --gold: #c8a96a;
  --border: #e7ddd6;
  --ok: #6f9e79;
  --warn: #c8975a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --pill: 999px;
  --btn-h: 48px;
  --tap: 44px;
  --sw-m: 52px;
  --sw-t: 56px;
  --shadow: 0 1px 3px rgba(43, 33, 31, .06);
  --shadow-card: 0 6px 22px rgba(60, 44, 40, .07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    system-ui, -apple-system, "Yu Gothic", "Meiryo", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
  overscroll-behavior-y: none;
}
button, input { font-family: inherit; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }
.hidden { display: none !important; }

.app { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: calc(70px + var(--safe-b)); }

/* ===== 手プレビュー（上部sticky） ===== */
.stage {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #fdfcfa 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}
.stage-inner {
  max-width: 620px; margin: 0 auto;
  padding: 8px 14px 10px;
  display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr);
  gap: 12px; align-items: center;
}
.hand-wrap {
  width: 100%; aspect-ratio: 4 / 5; max-height: 42dvh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 52% 34%, rgba(255,255,255,.96), rgba(255,255,255,.70) 56%, rgba(247,241,236,.62) 100%),
    linear-gradient(180deg, #fff, #f8f1ec);
  border: 1px solid rgba(231, 221, 214, .78);
  border-radius: 28px;
  box-shadow: 0 10px 34px rgba(90, 64, 54, .08);
  overflow: hidden;
}
.hand-wrap svg { width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* 相性フィードバック */
.verdict { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 11px 12px; box-shadow: var(--shadow-card); align-self: stretch; }
.verdict-top { display: flex; flex-direction: column; gap: 9px; }
.verdict-badge {
  display: inline-flex; align-self: flex-start; align-items: center;
  font-weight: 700; font-size: .9rem; padding: 5px 12px; border-radius: var(--pill);
  background: var(--surface-warm); color: var(--text); white-space: nowrap;
}
.verdict-badge[data-level="great"] { background: var(--secondary-soft); color: #486b41; }
.verdict-badge[data-level="good"]  { background: var(--primary-soft); color: var(--primary-hv); }
.verdict-badge[data-level="soso"]  { background: #f6ecdb; color: #97662a; }
.verdict-badge[data-level="risk"]  { background: #f6e7e4; color: #a2564c; }
.meters { display: grid; gap: 6px; }
.meter { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 8px; }
.meter-label { font-size: .72rem; color: var(--muted); letter-spacing: .02em; }
.meter-bar { position: relative; height: 7px; border-radius: var(--pill); background: var(--surface-warm); overflow: hidden; }
.meter-bar i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: var(--pill); transition: width .35s ease; }
#meterCohesion { background: linear-gradient(90deg, #d7a9b3, var(--secondary)); }
#meterTrend { background: linear-gradient(90deg, #e6cdb1, var(--primary)); }
.verdict-reasons { list-style: none; margin: 9px 0 0; padding: 0; display: grid; gap: 5px; }
.verdict-reasons li { font-size: .78rem; color: var(--muted); padding-left: 15px; position: relative; line-height: 1.5; }
.verdict-reasons li::before { content: ""; position: absolute; left: 2px; top: .55em; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.verdict-reasons li.good::before { background: var(--ok); }
.verdict-reasons li.warn::before { background: var(--warn); }
.verdict-fix { width: 100%; text-align: left; margin-top: 9px; font-size: .78rem; font-weight: 600; color: var(--primary-hv); background: var(--primary-soft); border: 0; border-radius: var(--radius-sm); padding: 10px 12px; line-height: 1.45; }

/* ===== パネル ===== */
.panel { max-width: 640px; width: 100%; margin: 0 auto; padding: 10px 14px 18px; }

.nailbar { display: flex; align-items: center; gap: 10px; padding: 4px 0 12px; }
.nailbar-label { font-size: .74rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.nailbar .chips { overflow-x: auto; scrollbar-width: none; }
.nailbar .chips::-webkit-scrollbar { display: none; }
.nailbar-status { margin-left: auto; flex: 0 0 auto; font-size: .7rem; color: var(--primary-hv); background: var(--primary-soft); border-radius: var(--pill); padding: 4px 9px; font-weight: 700; white-space: nowrap; }

.segbar { display: flex; gap: 4px; background: var(--surface-warm); border-radius: var(--pill); padding: 4px; margin-bottom: 14px; }
.seg { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: var(--pill); color: var(--muted); font-weight: 700; font-size: .82rem; }
.seg.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.section { display: grid; gap: 14px; }
.block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 13px 13px 15px; box-shadow: var(--shadow); }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.block-title { font-size: .92rem; font-weight: 700; letter-spacing: .02em; }
.hint { font-size: .68rem; color: var(--muted-2); }
.lead { font-size: .8rem; color: var(--muted); margin: 0 0 10px; line-height: 1.55; }
.selection-note { margin: 0 0 9px; padding: 9px 11px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-hv); font-size: .78rem; font-weight: 700; line-height: 1.45; }

/* chips */
.chips { display: flex; gap: 8px; flex-wrap: nowrap; }
.chips.wrap { flex-wrap: wrap; }
.scroll-x { overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; -ms-overflow-style: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.fade-x { -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent); mask-image: linear-gradient(90deg, #000 92%, transparent); }
.chip {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: var(--pill); font-size: .82rem; font-weight: 600; white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s, transform .06s;
}
.chip:active { transform: scale(.95); }
.chip.is-on { background: var(--text); color: #fff; border-color: var(--text); }
.chip.is-on.chip-accent { background: var(--primary); border-color: var(--primary); }
.chip .sw { width: 15px; height: 15px; border-radius: 5px; border: 1px solid rgba(0,0,0,.08); }
.quick-filter { margin-bottom: 9px; }
.quick-filter .chip { background: #fffaf7; border-color: #eadbd2; color: #705c54; }
.quick-filter .chip.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* search */
.search { width: 100%; min-height: var(--tap); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 13px; font-size: 16px; color: var(--text); background: var(--surface-warm); margin-bottom: 9px; }
.search:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); background: #fff; }
.section .chips.scroll-x { margin-bottom: 9px; }

/* swatches */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--sw-m), 1fr)); gap: 10px; max-height: 44dvh; overflow-y: auto; padding: 4px 3px 8px; margin-top: 4px; -webkit-overflow-scrolling: touch; scroll-padding-top: 8px; }
.swatch { border: 0; background: transparent; padding: 0; display: grid; gap: 4px; text-align: center; }
.swatch .dot { width: 100%; aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--border); position: relative; overflow: hidden; box-shadow: inset 0 -7px 13px rgba(0,0,0,.05); }
.swatch .dot::after { content: ""; position: absolute; left: 14%; top: 9%; width: 38%; height: 26%; background: rgba(255,255,255,.55); border-radius: 50%; filter: blur(2px); }
.swatch .dot.fin-matte::after { display: none; }
.swatch .dot.fin-matte { box-shadow: none; }
.swatch .dot.fin-sheer::before,
.swatch .dot.fin-jelly::before,
.swatch .dot.fin-milky::before,
.swatch .dot.fin-pearl::before,
.swatch .dot.fin-shimmer::before,
.swatch .dot.fin-glitter::before,
.swatch .dot.fin-chrome::before,
.swatch .dot.fin-magnet::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.swatch .dot.fin-sheer::before,
.swatch .dot.fin-jelly::before { background: linear-gradient(135deg, rgba(255,255,255,.52), rgba(255,255,255,.06)); }
.swatch .dot.fin-milky::before { background: rgba(255,255,255,.28); backdrop-filter: blur(1px); }
.swatch .dot.fin-pearl::before { background: radial-gradient(circle at 35% 28%, rgba(255,255,255,.72), rgba(255,255,255,.18) 48%, rgba(255,255,255,0) 76%); }
.swatch .dot.fin-shimmer::before { background-image: radial-gradient(rgba(255,255,255,.9) .8px, transparent 1.3px), linear-gradient(135deg, rgba(255,255,255,.45), rgba(255,255,255,0)); background-size: 9px 9px, 100% 100%; }
.swatch .dot.fin-glitter::before { background-image: radial-gradient(rgba(255,255,255,.95) 1px, transparent 1.4px); background-size: 6px 6px; }
.swatch .dot.fin-chrome::before { background: linear-gradient(135deg, rgba(255,255,255,.72), rgba(0,0,0,.14) 44%, rgba(255,255,255,.78) 58%, rgba(0,0,0,.18)); mix-blend-mode: screen; }
.swatch .dot.fin-magnet::before { background: linear-gradient(125deg, rgba(0,0,0,.18), rgba(255,255,255,.74) 46%, rgba(255,255,255,.80) 52%, rgba(0,0,0,.18)); opacity: .9; }
.swatch .nm { font-size: .62rem; color: var(--muted); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch.is-on .dot { outline: 2.5px solid var(--primary); outline-offset: 2px; }
.swatch:active .dot { transform: scale(.94); }
.swatches .empty { grid-column: 1/-1; color: var(--muted-2); font-size: .8rem; text-align: center; padding: 20px 0; }
.more-swatch { grid-column: 1 / -1; min-height: 46px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-warm); color: var(--muted); font-size: .78rem; font-weight: 700; }
.more-swatch:active { transform: scale(.99); }

/* must-use slots */
.mustuse-slots { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.slot { width: 56px; height: 56px; border-radius: 14px; border: 1.5px dashed var(--muted-2); background: var(--surface-warm); color: var(--muted-2); font-size: 1.4rem; display: grid; place-items: center; position: relative; overflow: hidden; flex: 0 0 auto; }
.slot.on { outline: 2px solid var(--primary); outline-offset: 1px; }
.slot.filled { border-style: solid; border-color: transparent; color: transparent; }
.slot .rm { position: absolute; top: 1px; right: 4px; font-size: .8rem; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.mustuse-hint { font-size: .68rem; color: var(--muted-2); margin: 9px 0 0; }
#btnMustUseGo { flex: 1 1 160px; min-height: var(--btn-h); }

/* buttons */
.btn { min-height: var(--btn-h); border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-warm); color: var(--text); font-weight: 700; font-size: .85rem; padding: 0 14px; }
.btn:active { transform: scale(.98); }
.btn-accent { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn:disabled { opacity: .45; }

/* ===== アクションバー ===== */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 8px; justify-content: center; padding: 8px 12px calc(8px + var(--safe-b)); background: rgba(251,250,248,.92); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.ab-btn { flex: 1 1 0; max-width: 210px; min-height: 48px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 700; font-size: .78rem; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.ab-btn:active { transform: scale(.98); }
.ab-primary { background: var(--text); color: #fff; border-color: var(--text); }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%) translateY(12px); background: var(--text); color: #fff; font-size: .82rem; padding: 11px 17px; border-radius: var(--pill); box-shadow: var(--shadow-card); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: 90vw; text-align: center; line-height: 1.5; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.nail-hit { cursor: pointer; }
.seg:focus-visible,
.chip:focus-visible,
.swatch:focus-visible .dot,
.slot:focus-visible,
.btn:focus-visible,
.ab-btn:focus-visible,
.more-swatch:focus-visible {
  outline: 3px solid rgba(168, 79, 98, .28);
  outline-offset: 2px;
}

/* ===== モバイル: セグメントで1画面1関心 ===== */
@media (max-width: 767px) {
  .stage-inner {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 12px 9px;
  }
  .hand-wrap {
    aspect-ratio: auto;
    height: clamp(248px, 39dvh, 330px);
    max-height: none;
    min-height: 0;
  }
  .verdict {
    padding: 9px 10px;
    border-radius: var(--radius-md);
  }
  .verdict-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }
  .verdict-reasons {
    max-height: 1.65em;
    overflow: hidden;
  }
  .nailbar { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
  .nailbar-label { padding-top: 10px; }
  .nailbar .chips { grid-column: 1 / -1; min-width: 0; }
  .nailbar-status { justify-self: end; margin-left: 0; }
  .section { display: none; }
  .section.is-active { display: grid; }
}

@media (max-width: 374px) {
  .hand-wrap { height: clamp(220px, 36dvh, 284px); border-radius: 22px; }
  .verdict-reasons { display: none; }
  .chip { padding: 0 12px; }
  .swatches { gap: 8px; }
}

/* ===== タブレット/PC: 2カラム・全部見せる ===== */
@media (min-width: 768px) {
  .app { flex-direction: row; padding-bottom: 0; }
  .stage { width: 55%; height: 100dvh; align-self: flex-start; border-bottom: 0; border-right: 1px solid var(--border); display: flex; align-items: center; }
  .stage-inner { grid-template-columns: 1fr; gap: 18px; padding: 26px; max-width: 460px; }
  .hand-wrap { max-height: 58dvh; }
  .panel { flex: 1; max-width: none; height: 100dvh; overflow-y: auto; padding: 22px 26px 96px; }
  .segbar { display: none; }
  .section { margin-bottom: 16px; }
  .swatches { max-height: 38dvh; grid-template-columns: repeat(auto-fill, minmax(var(--sw-t), 1fr)); }
  .actionbar { left: 55%; right: 0; background: rgba(251,250,248,.94); }
}
@media (min-width: 1180px) {
  .panel { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; align-content: start; }
  .panel .nailbar, .panel .segbar { grid-column: 1 / -1; }
  #sec-color { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
