:root {
  color-scheme: dark;
  --bg: #14140f;
  --panel: #1e1e18;
  --line: #34332c;
  --fg: #eae7e0;
  --dim: #9a968c;
  --accent: #c9a86a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 system-ui, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
}
.dim { color: var(--dim); }

.hd { padding: 16px 16px 10px; }
.hd h1 { font-size: 19px; margin: 0; letter-spacing: .04em; }
.hd h1 span { color: var(--dim); font-weight: 400; font-size: 14px; }
.hd p { margin: 4px 0 0; font-size: 12px; }

.wrap { padding: 0 12px 32px; }

/* ---------------------------------------------------------------- 3D */
.stage { position: relative; }
model-viewer {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  background: linear-gradient(#232320, #16160f);
  border: 1px solid var(--line);
  border-radius: 10px;
  --poster-color: transparent;
}
#ar-launcher {
  position: fixed; left: -9999px; top: 0;
  width: 1px; height: 1px; border: 0; pointer-events: none;
}
.loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 13px; pointer-events: none;
}
.loading[hidden] { display: none; }

/* ------------------------------------------------------------ 操作列 */
.panel { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  appearance: none; border: 0; background: var(--panel); color: var(--dim);
  font: inherit; padding: 9px 18px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #191509; font-weight: 700; }

button.ar {
  appearance: none; border: 1px solid var(--accent); border-radius: 8px;
  background: transparent; color: var(--accent);
  font: inherit; font-weight: 700; padding: 9px 16px; cursor: pointer;
  margin-left: auto;
}
button.ar:active { background: #ffffff14; }
.note { font-size: 12px; margin: 8px 0 0; }

/* ------------------------------------------------------- 選択中の張地 */
.cur {
  display: flex; gap: 10px; align-items: center;
  margin: 14px 0 10px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.chip {
  width: 30px; height: 30px; flex: none; border-radius: 5px;
  border: 1px solid #ffffff30; background: #444;
}
.cur-name { font-weight: 700; }
.cur .dim { font-size: 12px; }

/* ------------------------------------------------------------ 張地一覧 */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.tab {
  appearance: none; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--dim);
  font: inherit; font-size: 12px; padding: 5px 14px; cursor: pointer; white-space: nowrap;
}
.tab.on { border-color: var(--accent); color: var(--accent); }

.fabrics h3 { font-size: 13px; margin: 16px 0 2px; }
.fabrics .meta { font-size: 11px; margin: 0 0 8px; }
.swgrid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.sw {
  appearance: none; padding: 0; cursor: pointer;
  aspect-ratio: 1; border-radius: 6px;
  border: 1px solid var(--line);
  background-size: cover; background-position: center;
}
.sw.on { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* ------------------------------------------------------------- PC 幅 */
@media (min-width: 900px) {
  .hd { padding: 22px 32px 12px; }
  .wrap {
    display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(360px, 1fr);
    gap: 24px; padding: 0 32px 24px; align-items: start;
  }
  model-viewer { aspect-ratio: 16 / 10; }
  .panel { margin-top: 0; }
  .fabrics { max-height: 46vh; overflow-y: auto; padding-right: 6px; }
  .swgrid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 7px; }
}

/* 高さのある PC ウィンドウでは、ビューポートを使い切る 1 画面レイアウトにする。
   3D ビューを縦いっぱいに取り、張地一覧は右カラム内でスクロールさせて下端の余白を消す。*/
@media (min-width: 900px) and (min-height: 600px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; overflow: hidden; }
  .hd { flex: none; }
  .wrap { flex: 1 1 auto; min-height: 0; align-items: stretch; }

  .stage { display: flex; min-height: 0; }
  model-viewer { aspect-ratio: auto; height: 100%; }

  .panel { display: flex; flex-direction: column; min-height: 0; }
  .cur { margin: 12px 0 8px; }
  .tabs { flex: none; }
  .fabrics { flex: 1 1 auto; max-height: none; min-height: 0; }
  .fabrics h3 { margin-top: 12px; }
}
