/* KURIYAMA FURNITURE — 張地シミュレーター（iPad接客用） */
:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --ink: #2a2826;
  --ink-soft: #6b6660;
  --line: #dcd7cf;
  --line-soft: #ebe7e0;
  --accent: #8a6a48;
  --stage: #eeebe6;
  --radius: 2px;
  --panel-w: 400px;
  --tap: 44px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Helvetica Neue", Helvetica, Arial, "Yu Gothic", "Meiryo", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;                 /* 画面全体はスクロールさせない（アプリ風） */
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit; color: inherit;
  -webkit-appearance: none; appearance: none;
  touch-action: manipulation;       /* ダブルタップ拡大を防ぐ */
  cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- 全体レイアウト（横向き：左に写真、右に素材） ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "bar bar" "view panel";
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
  -webkit-user-select: none; user-select: none;
}

.bar {
  grid-area: bar;
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 14px 24px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.brand-name { font-size: 10px; letter-spacing: .3em; color: var(--ink-soft); white-space: nowrap; }
.brand-title { font-size: 17px; letter-spacing: .12em; white-space: nowrap; }
.product-name { font-size: 13px; letter-spacing: .1em; color: var(--ink-soft); white-space: nowrap; }

/* ---------- 写真エリア ---------- */
.view {
  grid-area: view;
  display: flex; flex-direction: column;
  min-height: 0;
  padding: 16px 20px calc(16px + var(--safe-b)) 24px;
  gap: 12px;
}
.stage {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--stage);
  overflow: hidden;
}
.stage canvas {
  display: block;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  -webkit-touch-callout: none;
}
.stage.is-zoom {
  display: block;
  overflow: auto; -webkit-overflow-scrolling: touch;
  cursor: grab;
}
.stage.is-zoom canvas { max-width: none; max-height: none; width: 220%; }

.stage-loading {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: rgba(246,244,240,.55); font-size: 13px; letter-spacing: .08em; color: var(--ink-soft);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.stage-loading.is-on { opacity: 1; }
.spinner {
  width: 16px; height: 16px; border: 1px solid var(--ink-soft); border-top-color: transparent;
  border-radius: 50%; -webkit-animation: spin .8s linear infinite; animation: spin .8s linear infinite;
}
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tools-spacer { flex: 1 1 auto; }
.tool {
  min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0 16px; font-size: 14px; letter-spacing: .04em;
  transition: border-color .15s, background .15s;
}
.tool:active { background: var(--line-soft); }
.tool[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tool-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tool-primary:active { background: #45413d; }

.link-btn {
  background: none; border: 0; padding: 8px 0; min-height: 36px;
  font-size: 13px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px;
}

/* 保存した組み合わせ */
.saved-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.saved-title { font-size: 12px; letter-spacing: .1em; color: var(--ink-soft); }
.saved-list {
  list-style: none; margin: 4px 0 0; padding: 10px 10px 4px 0;
  display: flex; gap: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.saved-item { position: relative; flex: 0 0 auto; }
.saved-open {
  display: block; width: 132px; padding: 0; border: 1px solid var(--line); background: var(--surface); text-align: left;
}
.saved-open[aria-current="true"] { border-color: var(--ink); }
.saved-open img { display: block; width: 100%; height: auto; }
.saved-open span { display: block; padding: 4px 6px; font-size: 11px; line-height: 1.35; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-del {
  position: absolute; top: -10px; right: -10px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; line-height: 1; padding: 0;
}

/* ---------- 素材パネル ---------- */
.panel {
  grid-area: panel;
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 20px 0;
}
.current { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.current-row {
  display: grid; grid-template-columns: 72px 36px minmax(0, 1fr); align-items: center; gap: 12px;
  min-height: 52px; padding: 6px 0; border: 0; background: none; text-align: left;
}
.current-row + .current-row { border-top: 1px solid var(--line-soft); }
.current-label { font-size: 12px; letter-spacing: .08em; color: var(--ink-soft); }
.current-row.is-target .current-label { color: var(--ink); font-weight: 600; }
.current-row.is-target .current-label::before { content: "● "; color: var(--accent); font-size: 9px; vertical-align: 2px; }
.current-swatch {
  width: 36px; height: 36px; background: var(--line-soft) center / cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.current-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.current-text strong { font-weight: 500; font-size: 15px; letter-spacing: .04em; }
.current-text span { font-size: 12px; color: var(--ink-soft); }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--ink); margin-top: 14px; flex: 0 0 auto;
}
.segmented button {
  min-height: var(--tap); background: transparent; border: 0; padding: 0 4px;
  font-size: 13px; letter-spacing: .02em;
}
.segmented button + button { border-left: 1px solid var(--ink); }
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--bg); }

.series-tabs {
  display: flex; gap: 6px; margin-top: 14px; flex: 0 0 auto;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px;
  scrollbar-width: none;
}
.series-tabs::-webkit-scrollbar { display: none; }
.series-tabs button {
  flex: 0 0 auto; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface);
  font-size: 13px; color: var(--ink-soft); white-space: nowrap;
}
.series-tabs button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.series-desc { margin: 8px 0 10px; font-size: 12px; color: var(--ink-soft); min-height: 1.6em; flex: 0 0 auto; }

.swatch-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  margin: 0 -20px; padding: 4px 20px calc(16px + var(--safe-b));
}
.swatches {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 16px 12px;
}
.swatch { display: block; width: 100%; background: none; border: 0; padding: 0; text-align: left; }
.swatch-img {
  display: block; width: 100%; padding-top: 100%;
  background: var(--line-soft) center / cover no-repeat;
  outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color .12s;
}
.swatch:active .swatch-img { opacity: .85; }
.swatch[aria-pressed="true"] .swatch-img { outline-color: var(--ink); }
.swatch-code { display: block; margin-top: 6px; font-size: 13px; letter-spacing: .02em; }
.swatch-series { display: block; font-size: 11px; color: var(--ink-soft); }

.panel-foot { margin-top: 24px; font-size: 11px; color: var(--ink-soft); }
.panel-foot p { margin: 0 0 4px; }

.error-box {
  margin: 8px 0; padding: 12px 14px; border: 1px solid #c9a79a; background: #fbf3f0;
  font-size: 13px; color: #6d3b2b;
}

/* ---------- 比較シート ---------- */
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 20;
  background: rgba(42,40,38,.45);
  display: flex; align-items: stretch; justify-content: center;
  padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l));
}
.sheet-inner {
  background: var(--bg); width: 100%; max-width: 1400px;
  display: flex; flex-direction: column; min-height: 0;
  padding: 18px 22px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 500; letter-spacing: .08em; }
.sheet-actions { display: flex; align-items: center; gap: 16px; }
.compare-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0;
}
.compare-grid li { background: var(--surface); border: 1px solid var(--line); }
.compare-grid img { display: block; width: 100%; height: auto; }
.compare-grid dl { margin: 0; padding: 8px 12px 10px; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.compare-grid dt { color: var(--ink-soft); }
.compare-grid dd { margin: 0; }

/* ---------- 縦向き・狭い画面：写真を上、素材を下 ---------- */
@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "bar" "view" "panel";
  }
  .view { padding: 12px 16px 10px; }
  .stage { flex: 0 0 auto; }
  .stage.is-zoom { height: 42vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding: 10px 16px 0; }
  .current { flex-direction: row; gap: 10px; padding-bottom: 8px; }
  .current-row {
    flex: 1 1 0; grid-template-columns: 30px minmax(0, 1fr); grid-template-rows: auto auto;
    gap: 2px 8px; min-height: 0; padding: 4px 0;
  }
  .current-row + .current-row { border-top: 0; border-left: 1px solid var(--line-soft); padding-left: 10px; }
  .current-label { grid-column: 1 / -1; }
  .current-swatch { width: 30px; height: 30px; }
  .current-text strong { font-size: 13px; }
  .current-text span { font-size: 11px; }
  .swatch-scroll { margin: 0 -16px; padding: 4px 16px calc(16px + var(--safe-b)); }
}
@media (max-width: 560px) {
  .brand-name { display: none; }
  .bar { padding: 10px 16px; }
  .tool { padding: 0 12px; font-size: 13px; }
  .tool-primary { width: 100%; }
  .tools-spacer { display: none; }
  .swatches { grid-template-columns: repeat(4, 1fr); gap: 12px 8px; }
  .current-label { font-size: 10px; }
}

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