/* AR Size Visualizer — shared by ar-size-visualizer.html and ar-size-visualizer-en.html */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Palette extracted from the room photo ── */
  --bg:          #f6f4f0;   /* warm wall white        */
  --surface:     #ffffff;   /* pure panel white       */
  --surface2:    #eeebe5;   /* soft linen             */
  --border:      #dedad2;   /* warm light divider     */
  --accent:      #6e9e7a;   /* sage green (plant)     */
  --accent2:     #4f7a5c;   /* deep sage              */
  --wood:        #c49a5a;   /* honey wood floor/legs  */
  --text:        #2a2724;   /* warm near-black        */
  --text-muted:  #8c8278;   /* warm mid-gray          */
  --shadow:      rgba(42,39,36,0.08);
  --radius:      12px;
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', 'Yu Gothic', Meiryo, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 20px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  box-shadow: 0 1px 6px var(--shadow);
}
.logo {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--wood));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(110,158,122,0.35);
}
.header-text { flex: 1; min-width: 0; }   /* lets the tagline wrap early on narrow screens */
header h1 { font-size: 1.05rem; font-weight: 700; color: var(--text); }
header p  { font-size: 0.76rem; color: var(--text-muted); margin-top: 1px; }
#about-button {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.78rem; font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#about-button:hover { border-color: var(--accent); color: var(--text); background: #f0f7f2; }
#about-button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ── Main layout ── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── 3-D viewer — room photo as background ── */
.viewer-wrap {
  flex: 1;
  position: relative;
  background-image: url('../img/room-bg.webp');
  background-size: cover;
  background-position: center bottom;
  min-height: 0;
}
/* Subtle vignette so the 3-D object reads clearly */
.viewer-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 70%,
    transparent 40%,
    rgba(230,225,218,0.25) 100%);
  pointer-events: none;
}
model-viewer {
  width: 100%;
  height: 100%;
  --poster-color: transparent;
  background-color: transparent;
}
/* model-viewer's built-in AR button would double up with #ar-button on AR-capable phones */
model-viewer::part(default-ar-button) { display: none; }

/* AR launch button — lives outside <model-viewer> so it is shown on every
   device; on non-AR devices it opens the QR / mail share dialog instead */
#ar-button {
  position: absolute;
  bottom: 20px;
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 26px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(110,158,122,0.50);
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
#ar-button:hover  { opacity: 0.92; transform: translateX(-50%) translateY(-2px); }
#ar-button:active { transform: translateX(-50%) translateY(0); }
#ar-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ── Dialog (AR share on non-AR devices) ── */
#ar-share-modal {
  margin: auto;              /* re-centre: the global reset zeroes the UA margin */
  border: none;
  border-radius: 18px;
  padding: 0;
  width: min(92vw, 400px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 60px rgba(42,39,36,0.28);
}
#ar-share-modal::backdrop { background: rgba(42,39,36,0.45); backdrop-filter: blur(3px); }
.modal-body { padding: 24px 24px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 1.02rem; font-weight: 700; line-height: 1.4; flex: 1; }
.modal-close {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 1.1rem; line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-text { font-size: 0.86rem; line-height: 1.65; color: var(--text-muted); }
.modal-text strong { color: var(--text); font-weight: 600; }
.ar-share-qr {
  align-self: center;
  width: 188px; height: 188px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ar-share-qr svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }
.ar-share-url {
  text-align: center;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}
.ar-share-mail {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 0.92rem; font-weight: 600;
  text-decoration: none;
  box-shadow: 0 4px 18px rgba(110,158,122,0.40);
}
.ar-share-mail:hover { opacity: 0.92; }
.ar-share-mail svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ── About section (bottom of the panel; the header button scrolls here) ── */
#about { scroll-margin-top: 8px; }
#about.flash { animation: about-flash 1.2s ease-out; }
@keyframes about-flash { 0% { background: #eaf3ec; } 100% { background: var(--surface); } }
.about-text { font-size: 0.82rem; line-height: 1.7; color: var(--text-muted); }
.about-text strong { color: var(--text); font-weight: 600; }
.about-block { display: flex; flex-direction: column; gap: 6px; }
.about-block h3 {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em;
  color: var(--accent2);
}
.about-block a { color: var(--accent2); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.about-block a:hover { color: var(--accent); }
.about-steps { padding-left: 1.3em; display: flex; flex-direction: column; gap: 4px; }
.about-steps li::marker { color: var(--accent2); font-weight: 700; }
.about-faq details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fdf9f4;
  padding: 0 10px;
}
.about-faq details + details { margin-top: 5px; }
.about-faq summary {
  cursor: pointer;
  padding: 8px 0;
  font-size: 0.8rem; font-weight: 600; color: var(--text);
  list-style: none;
  display: flex; align-items: center; gap: 6px;
}
.about-faq summary::-webkit-details-marker { display: none; }
.about-faq summary::before {
  content: '';
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--accent2); border-bottom: 1.5px solid var(--accent2);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.about-faq details[open] summary::before { transform: rotate(45deg); }
.about-faq details p { padding: 0 0 10px; }
.about-operator { font-size: 0.9rem; color: var(--text); font-weight: 600; }

/* Loading overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(246,244,240,0.78);
  backdrop-filter: blur(6px);
  z-index: 5;
  transition: opacity 0.3s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Control panel ── */
.panel {
  width: 304px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow: -2px 0 12px var(--shadow);
}

.section {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.section-title {
  font-size: 0.75rem;   /* <h2> styled as a small caption */
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* "Next section" arrow — appended by JS to every section but the last.
   Desktop hides it (the whole panel is visible); on the short mobile panel it
   tells first-time visitors that more settings sit below the fold. */
.section-next {
  display: none;
  align-self: center;
  align-items: center; justify-content: center;
  width: 34px; height: 34px;
  margin: -2px 0 -8px;             /* keep section heights close to what they were */
  border: none; border-radius: 50%;
  background: rgba(110,158,122,0.14);
  color: var(--accent2);
  cursor: pointer;
  animation: section-next-bob 1.4s ease-in-out infinite;
}
.section-next svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.section-next:hover { background: rgba(110,158,122,0.24); }
@keyframes section-next-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(5px); }
}
@media (prefers-reduced-motion: reduce) {
  .section-next { animation: none; }
}

/* ── Shape grid ── */
.shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.shape-btn {
  padding: 10px 6px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  color: var(--text-muted);
  font-size: 0.79rem;
  line-height: 1.4;
}
/* Fixed line box so a larger glyph never shifts the label below it */
.shape-btn .icon { font-size: 1.55rem; line-height: 2.2rem; display: block; margin-bottom: 3px; }
/* 🔺's glyph ink is only ~45% of its em box (the others fill theirs), so it
   needs roughly 2.2x the font-size to read at the same height. The fixed
   2.2rem line box keeps the label below it from shifting. */
.shape-btn .icon.icon-sm { font-size: 3.3rem; line-height: 2.2rem; }
.shape-btn:hover {
  border-color: var(--accent);
  background: #f0f7f2;
  color: var(--text);
}
.shape-btn.active {
  border-color: var(--accent);
  background: #eaf3ec;
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(110,158,122,0.15);
}

/* ── Size inputs ── */
.unit-row { display: flex; gap: 4px; }
.unit-btn {
  padding: 4px 13px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  cursor: pointer;
  font-size: 0.79rem;
  color: var(--text-muted);
  transition: all 0.15s;
}
.unit-btn.active {
  background: #eaf3ec;
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 600;
}

.dim-rows { display: flex; flex-direction: column; gap: 9px; }

.dim-row {
  display: grid;
  grid-template-columns: 58px 1fr 60px;
  align-items: center;
  gap: 8px;
}
.dim-row label { font-size: 0.79rem; color: var(--text-muted); }
.dim-row input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.dim-num-wrap { display: flex; align-items: center; gap: 4px; }
.dim-num-wrap input[type=number] {
  width: 44px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 5px;
  font-size: 0.82rem;
  font-family: monospace;
  -moz-appearance: textfield;
  appearance: textfield;
}
.dim-num-wrap input[type=number]::-webkit-inner-spin-button,
.dim-num-wrap input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
.dim-num-wrap .unit-tag { font-size: 0.72rem; color: var(--text-muted); width: 20px; }

.dim-row.disabled { opacity: 0.3; pointer-events: none; }

.size-badge {
  background: #fdf9f4;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.81rem;
  color: var(--text-muted);
  text-align: center;
}
.size-badge strong { color: var(--text); font-family: monospace; }

/* ── Color ── */
.color-row { display: flex; align-items: center; gap: 12px; }
#pickr-el { width: 40px; height: 40px; border-radius: 10px; }
.color-hex { font-family: monospace; font-size: 0.88rem; color: var(--text); }

/* ── Material ── */
.presets-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
.preset-btn {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.77rem;
  cursor: pointer;
  transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--text); background: #f0f7f2; }
.preset-btn.active {
  background: #eaf3ec;
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 600;
}

.slider-group { display: flex; flex-direction: column; gap: 8px; }
.slider-row { display: flex; flex-direction: column; gap: 4px; }
.slider-header { display: flex; justify-content: space-between; font-size: 0.79rem; }
.slider-header span:first-child { color: var(--text-muted); }
.slider-val { color: var(--accent2); font-family: monospace; font-weight: 600; }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* ── AR section ── */
.ar-info {
  font-size: 0.77rem;
  color: var(--text-muted);
  line-height: 1.65;
  background: #fdf9f4;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}
.ar-platforms { display: flex; gap: 7px; margin-top: 8px; flex-wrap: wrap; }
.ar-platform-tag {
  font-size: 0.71rem;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
}

/* Pickr overrides — light theme */
.pickr .pcr-button { border-radius: 10px !important; }
.pcr-app { box-shadow: 0 8px 32px rgba(42,39,36,0.14) !important; border-radius: 14px !important; }

/* ── Dimension overlay ── */
/* Corner-dot hotspots: invisible anchors used only for SVG line coordinates */
.hotspot-dot { display: none; }

/* Dimension label hotspots */
.hotspot-dim {
  position: absolute;
  background: rgba(255,255,255,0.90);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(42,39,36,0.14);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  padding: 3px 8px;
  pointer-events: none;
  white-space: nowrap;
  transform: translate3d(-50%, -50%, 0);
  /* hide labels when hotspot faces away from camera */
  --min-hotspot-opacity: 0;
}
.hotspot-dim:empty { display: none; }

/* SVG overlay for dimension lines */
#dim-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.dim-line {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  opacity: 0.9;
}
.dim-line.hidden { display: none; }

/* Show/Hide dimensions toggle — floated inside the viewer */
#dim-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: all 0.15s;
  user-select: none;
}
#dim-toggle:hover { color: var(--text); border-color: var(--accent); }
#dim-toggle.on { color: var(--accent2); border-color: var(--accent); background: rgba(234,243,236,0.95); }
#dim-toggle .dim-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.15s;
}
#dim-toggle.on .dim-dot { background: var(--accent); }

/* ── Responsive ── */
@media (max-width: 660px) {
  header { gap: 10px; padding: 10px 14px; }
  #about-button { padding: 7px 10px; font-size: 0.74rem; }
  .main { flex-direction: column-reverse; }
  .viewer-wrap { flex: 1; min-height: 40vh; }
  /* Panel is deliberately short (~1.5 sections) so the 3-D area gets the
     rest of the screen; operating a control re-centers its section
     (centerActiveSection() in the JS, which uses the same 660px breakpoint). */
  .panel {
    width: 100%;
    flex-shrink: 0;
    height: clamp(190px, 40vh, 340px);
    border-left: none;
    border-top: 1px solid var(--border);
    overscroll-behavior: contain;
  }
  .section-next { display: flex; }
}
/* Phones: icon-only so the title keeps a single line (the label is the
   button's title/aria-label) */
@media (max-width: 480px) {
  #about-button { padding: 8px; }
  #about-button span { display: none; }
  #about-button svg { width: 18px; height: 18px; }
}
