:root{
  --bg: #231e33;
  --bg-soft: #2d2540;
  --panel: #2a233d;
  --panel-line: #3d3456;
  --ember: #d1b9eb;
  --ember-dim: #8a6ec8;
  --cloud: #d1b9eb;
  --cloud-dim: #9a86b8;
  --text: #e6dcf5;
  --text-dim: #9a86b8;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Space Grotesk', sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}
@media (prefers-color-scheme: light){
  :root{
    --bg: #fdf6ff;
    --bg-soft: #ffffff;
    --panel: #f9f0ff;
    --panel-line: #e8d5f2;
    --ember: #8a6ec8;
    --ember-dim: #9b7ec8;
    --cloud: #8a6ec8;
    --cloud-dim: #6d4c8a;
    --text: #4a3b5a;
    --text-dim: #8a6ea8;
  }
}
*{ box-sizing: border-box; }
html,body{ margin:0; background:var(--bg); color:var(--text); font-family:var(--display); }
.wrap{ max-width: 1180px; margin: 0 auto; padding: 2.6rem 1.4rem 4rem; }

header.hero{ margin-bottom: 2.2rem; }
header.hero h1{
  font-size: clamp(2rem, 4.4vw, 3.1rem);
  margin: 0 0 .35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.05;
}
header.hero h1 .ring-o{
  display:inline-block;
  color: var(--bg);
  background: var(--ember);
  border-radius: 50%;
  width: .82em; height: .82em;
  text-align:center;
  transform: translateY(0.03em);
}
header.hero p{
  color: var(--text-dim);
  max-width: 62ch;
  font-size: 1.02rem;
  line-height: 1.55;
  margin: 0;
}

.layout{
  display:grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1.6rem;
  align-items:start;
}
@media (max-width: 880px){
  .layout{ grid-template-columns: 1fr; }
}

.panel{
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 1.4rem 1.4rem 1.6rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
@media (prefers-color-scheme: light){
  .panel{ box-shadow: 0 4px 24px rgba(139,110,200,0.08); }
}

.field{ margin-bottom: 1.35rem; }
.field:last-child{ margin-bottom: 0; }
.field label{
  display:flex; justify-content:space-between; align-items:baseline;
  font-size: .84rem; color: var(--text-dim); margin-bottom: .5rem;
  font-family: var(--mono);
}
.field label span.val{ color: var(--cloud); font-weight: 600; }

.seg{
  display:flex; background:var(--bg-soft); border:1px solid var(--panel-line);
  border-radius: 10px; overflow:hidden;
}
.seg button{
  flex:1; padding:.62rem .5rem; border:none; background:transparent; color:var(--text-dim);
  font-family: var(--display); font-size:.92rem; cursor:pointer; font-weight:600;
  transition: background .15s, color .15s;
}
.seg button.active{ background: var(--ember); color:#1e1a2e; }
@media (prefers-color-scheme: light){
  .seg button.active{ color:#ffffff; }
}
.seg button:not(.active):hover{ color: var(--text); }

input[type=range]{
  width:100%; appearance:none; height:4px; border-radius:2px;
  background: linear-gradient(90deg, var(--ember-dim), var(--ember));
  outline:none; margin: .3rem 0;
}
input[type=range]::-webkit-slider-thumb{
  appearance:none; width:16px; height:16px; border-radius:50%;
  background: var(--ember); border: 2px solid var(--bg-soft); cursor:pointer;
  box-shadow: 0 0 0 3px rgba(209,185,235,.22);
}
input[type=range]::-moz-range-thumb{
  width:16px; height:16px; border-radius:50%;
  background: var(--ember); border: 2px solid var(--bg-soft); cursor:pointer;
}
@media (prefers-color-scheme: light){
  input[type=range]::-webkit-slider-thumb{ box-shadow: 0 0 0 3px rgba(139,110,200,.18); }
}

input[type=text], input[type=number], select{
  width:100%; background: var(--bg-soft); border:1px solid var(--panel-line);
  color: var(--text); border-radius: 8px; padding: .55rem .7rem;
  font-family: var(--mono); font-size: .92rem;
}
input[type=text]:focus, input[type=number]:focus, select:focus{
  outline: none; border-color: var(--ember-dim);
  box-shadow: 0 0 0 2px rgba(209,185,235,.18);
}
@media (prefers-color-scheme: light){
  input[type=text]:focus, input[type=number]:focus, select:focus{
    box-shadow: 0 0 0 2px rgba(209,185,235,.35);
  }
}

.presets{ display:flex; gap:.5rem; flex-wrap:wrap; }
.presets button{
  flex:1; min-width: 90px;
  background: var(--bg-soft); border:1px solid var(--panel-line); color: var(--text);
  padding: .5rem .4rem; border-radius: 8px; font-family: var(--mono); font-size: .78rem;
  cursor:pointer; transition: border-color .15s, color .15s;
}
.presets button:hover{ border-color: var(--ember); color: var(--ember); }

.hint{
  font-family: var(--mono); font-size: .74rem; color: var(--text-dim);
  margin-top: .55rem; line-height:1.45;
}

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

.right-col{ display:flex; flex-direction:column; gap:1.6rem; }

.preview-panel canvas{
  width:100%; aspect-ratio: 1 / 1; max-height: 380px;
  display:block; border-radius: 10px; background: var(--bg-soft);
  border: 1px solid var(--panel-line);
}
.preview-caption{
  display:flex; justify-content:space-between; align-items:center; gap:.8rem; flex-wrap:wrap;
  color: var(--text-dim);
  font-family: var(--mono); font-size: .78rem; margin-top: .6rem;
}
.preview-caption b{ color: var(--cloud); font-weight:600; }
#viewLabel{ color: var(--text-dim); font-size: .76rem; }

.output-head{
  display:flex; justify-content:space-between; align-items:center; gap: .8rem; flex-wrap:wrap;
  margin-bottom: .9rem;
}
.output-head h2{ font-size: 1.05rem; margin:0; color: var(--text); }
.output-actions{ display:flex; gap:.55rem; }
.btn{
  font-family: var(--display); font-weight:600; font-size:.88rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--panel-line);
  background: var(--bg-soft); color: var(--text); cursor:pointer;
  transition: transform .1s, border-color .15s, background .15s;
}
.btn:hover{ border-color: var(--cloud-dim); }
.btn:active{ transform: scale(.97); }
.btn.primary{
  background: var(--ember-dim); color:#ffffff; border-color: var(--ember-dim);
}
.btn.primary:hover{ background: #9b7ec8; border-color:#9b7ec8; }
@media (prefers-color-scheme: light){
  .btn.primary{ background: #8a6ec8; border-color:#8a6ec8; }
  .btn.primary:hover{ background: #9b7ec8; border-color:#9b7ec8; }
}

textarea#output{
  width:100%; min-height: 220px; max-height: 340px; resize: vertical;
  background: #1c182d; color: #e6dcf5; border: 1px solid var(--panel-line);
  border-radius: 10px; padding: 1rem; font-family: var(--mono); font-size: .82rem;
  line-height: 1.55; overflow-x:auto; white-space: pre;
}
@media (prefers-color-scheme: light){
  textarea#output{
    background: #ffffff; color: #4a3b5a; border-color: #e8d5f2;
  }
}

.filename-row{ display:flex; gap:.6rem; align-items:center; margin-top: .8rem; }
.filename-row span{ color: var(--text-dim); font-family: var(--mono); font-size:.82rem; white-space:nowrap; }

.toast{
  position: fixed; bottom: calc(1.4rem + env(safe-area-inset-bottom, 0px)); left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ember); color:#1e1a2e; padding: .6rem 1.1rem; border-radius: 8px;
  font-family: var(--display); font-weight:600; font-size:.85rem;
  opacity:0; pointer-events:none; transition: opacity .2s, transform .2s;
}
@media (prefers-color-scheme: light){
  .toast{ background: #8a6ec8; color:#ffffff; }
}
.toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }

.footnote{
  margin-top: 1.6rem; color: var(--text-dim); font-size: .84rem; line-height:1.6;
  max-width: 74ch;
}
.footnote code{
  background: var(--bg-soft); border:1px solid var(--panel-line); border-radius:5px;
  padding: .05rem .35rem; font-family: var(--mono); font-size: .82em; color: var(--cloud);
}

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