/* DotQR Studio - green accent, PC first, responsive */
:root{
  --bg:#f6faf7;
  --panel:#ffffff;
  --text:#132019;
  --muted:#5a6b61;
  --line:rgba(19,32,25,0.12);
  --shadow:0 14px 35px rgba(0,0,0,.08);
  --accent:#19c37d;
  --accent2:#0ea36a;
  --danger:#ff4d4f;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --radius:18px;
}

[data-theme="dark"]{
  --bg:#08110d;
  --panel:#0c1712;
  --text:#e9fff3;
  --muted:#9db6a8;
  --line:rgba(233,255,243,0.12);
  --shadow:0 18px 45px rgba(0,0,0,.35);
  --accent:#2ae08f;
  --accent2:#19c37d;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: radial-gradient(1000px 600px at 10% 10%, rgba(25,195,125,.18), transparent 55%),
              radial-gradient(1000px 700px at 90% 15%, rgba(25,195,125,.14), transparent 60%),
              var(--bg);
  color:var(--text);
}

.topbar{
  position:sticky;
  top:0;
  z-index:10;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  padding:16px 18px;
  border-bottom:1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(10px);
}

.brand{ display:flex; align-items:center; gap:12px; min-width:260px; }
.logoMark{
  width:42px; height:42px; border-radius:14px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.9), rgba(255,255,255,0) 50%),
    linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent2) 70%, #0a5));
  box-shadow: 0 12px 22px rgba(25,195,125,.22);
  position:relative;
}
.logoMark:after{
  content:"";
  position:absolute; inset:10px;
  border-radius:10px;
  border:2px solid rgba(255,255,255,.8);
}

.brandName{ font-weight:820; letter-spacing:0.2px; }
.brandSub{ font-size:12px; color:var(--muted); margin-top:2px; }

.topActions{ display:flex; gap:10px; }

.btn{
  appearance:none;
  border:none;
  cursor:pointer;
  padding:12px 14px;
  border-radius:14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color:#062016;
  font-weight:750;
  box-shadow: 0 10px 22px rgba(25,195,125,.24);
}
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(0px); filter:saturate(0.95); }
.btn.ghost{
  background: transparent;
  color: var(--text);
  border:1px solid var(--line);
  box-shadow:none;
}
.btn.small{ padding:10px 12px; border-radius:12px; }

.layout{
  display:grid;
  grid-template-columns: 520px 1fr;
  gap:18px;
  padding:18px;
  max-width: 1240px;
  margin: 0 auto;
}

.panel, .preview{
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border:1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.panel{
  padding:18px;
}

.preview{
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.panelTitle{
  margin:0 0 14px 0;
  font-size:16px;
  letter-spacing:0.2px;
}

.subTitle{
  margin: 0 0 10px 0;
  font-size:13px;
  color: var(--muted);
  letter-spacing:0.2px;
}

.field{ margin-bottom:14px; }
.label{ display:block; font-size:12px; color:var(--muted); margin-bottom:8px; }

.input{
  width:100%;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--text);
  outline:none;
}
.input:focus{ border-color: color-mix(in srgb, var(--accent) 70%, var(--line)); box-shadow: 0 0 0 4px rgba(25,195,125,.14); }

.input.file{ padding:10px 12px; }
.input.select{ padding:10px 12px; }

.row{ display:flex; gap:10px; align-items:center; }
.row-between{ justify-content:space-between; }

.hint{
  font-size:12px;
  color: var(--muted);
  margin-top:6px;
  line-height:1.4;
}

.grid2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}

.rangeRow{
  display:flex;
  align-items:center;
  gap:10px;
}
.rangeRow input[type="range"]{ flex: 1; }

.pill{
  min-width:90px;
  text-align:center;
  padding:10px 10px;
  border-radius:14px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.06);
  font-family: var(--mono);
  font-size:12px;
}

.divider{
  height:1px;
  background: var(--line);
  margin: 16px 0;
}

.check{
  display:flex;
  align-items:center;
  gap:10px;
  user-select:none;
  font-size:13px;
  color: var(--text);
}
.check input{ accent-color: var(--accent); }

.mono{ font-family: var(--mono); }

.segmented{
  display:flex;
  background: rgba(255,255,255,.06);
  border:1px solid var(--line);
  border-radius:14px;
  overflow:hidden;
}
.seg{
  flex:1;
  padding:10px 8px;
  border:none;
  background: transparent;
  color: var(--muted);
  cursor:pointer;
  font-weight:700;
}
.seg.is-active{
  background: linear-gradient(135deg, rgba(25,195,125,.25), rgba(25,195,125,.12));
  color: var(--text);
}

.previewHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.status{
  font-size:12px;
  color: var(--muted);
  border:1px solid var(--line);
  padding:8px 10px;
  border-radius:999px;
  background: rgba(255,255,255,.06);
}

.stage{
  position: relative;
  border-radius: 18px;
  border:1px solid var(--line);
  overflow:hidden;
  min-height: 420px;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#fff;
}
.stage.checker{
  background:
    linear-gradient(45deg, rgba(0,0,0,.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.06) 75%);
  background-size: 26px 26px;
  background-position: 0 0, 0 13px, 13px -13px, -13px 0px;
}
.stage.white{ background:#fff; }
.stage.dark{ background:#0b0b0b; }
.stage.custom{ background: var(--custom-bg, #fff); }

#qrCanvas{
  width: min(520px, 86vw);
  height: auto;
  image-rendering: pixelated;
}

.previewMeta{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.metaItem{
  font-size:12px;
  color: var(--muted);
  border:1px solid var(--line);
  padding:10px 12px;
  border-radius:14px;
  background: rgba(255,255,255,.06);
}
.metaLabel{ color: var(--text); font-weight:750; margin-right:6px; }


.footNote{
  border:1px dashed color-mix(in srgb, var(--accent) 55%, var(--line));
  background: rgba(25,195,125,.07);
  padding:12px 12px;
  border-radius: 16px;
  color: color-mix(in srgb, var(--text) 90%, var(--muted));
  font-size:12px;
  line-height:1.5;
}

.crossPad{
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 160px;
  border-radius: 18px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.06);
  position:relative;
  overflow:hidden;
}
.crossLine{
  position:absolute;
  background: rgba(25,195,125,.28);
  border-radius: 999px;
}
.crossLine.h{ left:10px; right:10px; height:2px; top:50%; transform: translateY(-50%); }
.crossLine.v{ top:10px; bottom:10px; width:2px; left:50%; transform: translateX(-50%); }

.knob{
  width: 18px;
  height: 18px;
  border-radius: 999px;
  position:absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 18px rgba(25,195,125,.24);
  border: 2px solid rgba(255,255,255,.9);
  cursor: grab;
}
.knob:active{ cursor: grabbing; }

.footer{
  padding: 18px;
  text-align:center;
  color: var(--muted);
  font-size:12px;
}

/* Responsive */
@media (max-width: 1080px){
  .layout{ grid-template-columns: 1fr; }
  .panel{ order:2; }
  .preview{ order:1; }
  .topbar{ position:relative; }
}

@media (max-width: 520px){
  .grid2{ grid-template-columns: 1fr; }
  .topActions{ flex-direction:column; }
  .btn{ width:100%; }
}


/* ===== Mask Overlay (SAFE ADD) ===== */
#previewStage{ position: relative; }
#maskCanvas{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  pointer-events:none;
}
#maskCanvas.is-edit{
  pointer-events:auto;
  cursor: crosshair;
}


/* ===== Sticky preview (SAFE ADD) ===== */
.layout{
  align-items: start;
}

@media (min-width: 1081px){
  .layout{
    height: calc(100vh - 78px);
  }
  .panel{
    max-height: calc(100vh - 78px - 36px);
    overflow: auto;
    overscroll-behavior: contain;
  }
  .preview{
    position: sticky;
    top: 18px;
    height: calc(100vh - 78px - 36px);
    align-self: start;
  }
}


/* ===== Philosophiam CTA (under preview meta) ===== */
.philoCta{
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.05);
  overflow: hidden;
}
.philoCtaLink{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 12px 14px;
  text-decoration:none;
  color: var(--text);
}
.philoCtaTitle{
  font-weight: 850;
  letter-spacing: .02em;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(25,195,125,.12);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  color: color-mix(in srgb, var(--accent) 85%, var(--text));
  font-size: 12px;
  flex: 0 0 auto;
}
.philoCtaSub{
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 auto;
  min-width: 0;
}
.philoCtaIcon{
  font-size: 14px;
  opacity: .65;
  flex: 0 0 auto;
}
.philoCtaLink:hover{ background: rgba(25,195,125,.06); }
.philoCtaLink:active{ background: rgba(25,195,125,.10); }

/* CTA center fix (no layout break) */
.philo-cta a{
  min-height:72px;
  justify-content:center;
}


/* ===== PC fixes ===== */
/* philo CTA padding (PC) */
@media (min-width: 768px){
  .philoCtaLink{
    padding-top: 10px;
    padding-bottom: 15px;
  }
  .panelTitle{
    margin-bottom: 0;
  }
}

/* ===== SP fixes ===== */
/* Move topActions under logo on mobile */
@media (max-width: 767px){
  .topbar{
    flex-direction: column;
    align-items: flex-start;
  }
  .topActions{
    width: 100%;
    margin-top: 10px;
    justify-content: flex-start;
  }

  /* Match mobile background to PC tone */
  body{
    background:
      radial-gradient(800px 520px at 10% 10%, rgba(25,195,125,.16), transparent 55%),
      radial-gradient(800px 560px at 90% 15%, rgba(25,195,125,.12), transparent 60%),
      var(--bg);
  }
}


/* Space Pixel Map logo replacement */
.brandLogo{
  display:block;
  height:42px;
  width:auto;
  object-fit:contain;
}

/* ===== Legal Accordion (SAFE ADD) ===== */
.legalAccordion{border:1px solid var(--line);border-radius:14px;margin-top:10px;background:rgba(255,255,255,.04);}
.legalAccordion summary{cursor:pointer;padding:12px 14px;font-weight:700;list-style:none;}
.legalAccordion summary::-webkit-details-marker{display:none;}
.legalAccordion[open] summary{border-bottom:1px solid var(--line);}
.legalBody{padding:14px;font-size:12px;line-height:1.6;color:var(--muted);}
.legalBody h4{margin:12px 0 6px;font-size:12px;color:var(--text);}
.legalBody ul{padding-left:18px;}
.legalMeta{margin-top:12px;font-size:11px;color:var(--muted);}


/* ==== Safari PC Responsive FIX (SAFE, UI/UX NO CHANGE) ==== */
@supports (-webkit-touch-callout: none) {
  .topbar{
    position: relative;
    backdrop-filter: none;
  }
  .layout{
    grid-template-columns: 1fr !important;
  }
  .panel, .preview{
    transform: translateZ(0);
  }
  canvas{
    max-width: 100%;
    height: auto;
  }
}
