:root {
  --site-header-h: 90px;
  --studio-accent: #7c3aed;
  --studio-bg: #e8ecf1;
  --studio-card: #ffffff;
  --studio-ink: #1a1d24;
  --studio-muted: #6b7380;
}
@media (max-width: 720px) {
  :root { --site-header-h: 74px; }
}

body.case-studio-page {
  margin: 0;
  background: var(--studio-bg);
  overflow: hidden;
}

.case-studio {
  display: grid;
  grid-template-columns: min(300px, 28vw) minmax(0, 0.92fr) minmax(0, 1.18fr);
  gap: 14px;
  padding: 14px;
  height: calc(100vh - var(--site-header-h));
  max-height: calc(100vh - var(--site-header-h));
  overflow: hidden;
  box-sizing: border-box;
}

.decorate-panel {
  background: var(--studio-card);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(18, 20, 26, 0.08);
  padding: 18px 16px 16px;
  overflow-y: auto;
  min-height: 0;
  height: 100%;
}

.decorate-panel h1 {
  margin: 0 0 4px;
  font-family: var(--font-display, Syne, sans-serif);
  font-size: 26px;
  letter-spacing: -0.04em;
}

.decorate-panel .sub {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--studio-muted);
  line-height: 1.4;
}

.acc {
  border-top: 1px solid #e4e8ee;
}
.acc > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--studio-ink);
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after {
  content: "›";
  font-size: 18px;
  font-weight: 400;
  color: #98a1ad;
  transform: rotate(0deg);
  transition: transform 0.15s;
}
.acc[open] > summary::after { transform: rotate(90deg); }
.acc-body { padding: 0 2px 14px; }

.preview-banner {
  display: block;
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  background: #fff4ec;
  border: 2px solid #ff4d00;
  border-radius: 8px;
  color: #5c2a00;
}
.preview-banner[hidden] { display: none !important; }
.preview-banner a { color: #ff4d00; font-weight: 700; }

.field-lab {
  display: block;
  font-size: 11px;
  color: var(--studio-muted);
  margin: 6px 0 4px;
}

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

#coverStyle {
  width: 100%;
  margin: 4px 0 8px;
  padding: 8px 10px;
  border: 1px solid #dde2e8;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: #fafbfc;
}

.color-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.color-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  border: 1px solid #dde2e8;
  border-radius: 8px;
  background: #fafbfc;
}
.color-grid input[type=color] {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--studio-ink);
  border-radius: 4px;
  background: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin: 6px 0;
}
.check-row input { accent-color: var(--studio-accent); width: 16px; height: 16px; }
.array-mode { margin-top: 10px; }

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--studio-muted);
}
.slider-row input[type=range] {
  width: 100%;
  accent-color: var(--studio-accent);
}

.pos-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.pos-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
}
.pos-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
}

.pattern-select-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pattern-select-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #d5dbe3;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--studio-ink);
  text-align: left;
  cursor: pointer;
}
.pattern-select-btn canvas {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #dde2e8;
  background: #f3f5f7;
  flex: 0 0 32px;
}
.pattern-select-btn span:first-of-type { flex: 1; min-width: 0; }
.pattern-chevron {
  color: #98a1ad;
  font-size: 18px;
  transform: rotate(90deg);
}

#patternControls.inactive {
  opacity: 0.45;
  pointer-events: none;
}
.pos-lab { margin-top: 10px; }

select, input[type=text], input[type=search], input[type=file], input[type=number] {
  width: 100%;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid #d5dbe3;
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
}

input[type=text] {
  font-size: 16px;
  letter-spacing: 0.4px;
}

.print-size {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f3f5f7;
  border: 1px solid #dde2e8;
  font-size: 11px;
  font-weight: 600;
}
.print-size strong { color: #ff4d00; }

.mm-tag {
  display: block;
  font-size: 11px;
  color: var(--studio-muted);
  margin-top: 4px;
}

.mini-h {
  margin: 14px 0 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--studio-muted);
}

.note {
  margin: 10px 0;
  padding: 10px;
  font-size: 11px;
  line-height: 1.45;
  color: #1a3a5c;
  background: #eef6ff;
  border-radius: 8px;
}

.panel-actions { margin-top: 8px; }

button {
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.full { width: 100%; margin-top: 8px; }
.btn-primary {
  background: var(--studio-accent);
  color: #fff;
  border-color: var(--studio-accent);
  padding: 13px 12px;
  font-size: 14px;
}
.btn-dl { background: var(--studio-ink); color: #fff; border-color: var(--studio-ink); }
.btn-ghost {
  background: #fff;
  color: var(--studio-ink);
  border-color: #d5dbe3;
}

.credits-bar {
  margin-top: 10px;
  padding: 8px;
  border-radius: 8px;
  font-size: 11px;
  background: rgba(124, 58, 237, 0.1);
  color: #4c1d95;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.status { margin-top: 8px; font-size: 12px; min-height: 28px; color: var(--studio-muted); }
.status.err { color: #c0392b; }
.status.ok { color: #1e7a46; }
.spinner {
  display: inline-block;
  width: 13px; height: 13px; margin-right: 6px;
  border: 2px solid #c5ccd4;
  border-top-color: var(--studio-accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--studio-card);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(18, 20, 26, 0.08);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
}
.card-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
}

.layer-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.layer-tab {
  flex: 1;
  margin: 0;
  padding: 7px 8px;
  font-size: 11px;
  background: #f3f5f7;
  color: var(--studio-ink);
  border-color: #c5ccd4;
}
.layer-tab.active {
  background: var(--studio-accent);
  color: #fff;
  border-color: var(--studio-accent);
}

#caseText {
  text-transform: none;
  letter-spacing: 0.4px;
  font-size: 16px;
}

.plate-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 24px 24px;
  background: #fff;
  position: relative;
}

.plate-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(18, 20, 26, 0.06);
  padding: 12px;
}

#backplateCanvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  background: transparent;
}

.plate-empty {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  color: #8b95a3;
  gap: 8px;
  box-sizing: border-box;
  padding: 12px;
}
.plate-empty[hidden] { display: none !important; }
.plate-empty p {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  max-width: 160px;
  line-height: 1.35;
}

.plate-tools {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 6px;
}
.plate-tools button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d5dbe3;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-size: 16px;
}

#viewer {
  flex: 1;
  min-height: 0;
  background: #dfe5ec;
}
#viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-rotate {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 12px;
  background: rgba(255,255,255,0.92);
  border: 1px solid #d5dbe3;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.viewer-rotate.active {
  background: var(--studio-accent);
  color: #fff;
  border-color: var(--studio-accent);
}
.rot-ico { font-size: 15px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 12, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none !important; }

.modal-card {
  width: min(720px, 96vw);
  max-height: 86vh;
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.2);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-x {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  background: #f3f5f7;
  border: 2px solid #c5ccd4;
  border-radius: 6px;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.pattern-tile {
  border: 2px solid #dde2e8;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  padding: 0;
  text-align: left;
}
.pattern-tile:hover { border-color: var(--studio-accent); }
.pattern-tile.active { border-color: var(--studio-accent); box-shadow: 0 0 0 2px rgba(124,58,237,0.25); }
.pattern-tile canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}
.pattern-tile span {
  display: block;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
}

.gen-box {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #dde2e8;
}
.gen-box h3 { margin: 0 0 6px; font-size: 14px; }
.gen-preview {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 10px auto;
  border: 2px solid #c5ccd4;
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 1100px) {
  body.case-studio-page { overflow: auto; }
  .case-studio {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .decorate-panel {
    height: auto;
    max-height: none;
  }
  .plate-panel { height: min(72vh, 640px); }
  .viewer-panel { height: min(72vh, 640px); }
  #viewer { min-height: 280px; }
}
