:root{
  --tg-bg: #0f0f10;
  --tg-secondary-bg: #17181a;
  --tg-text: #ffffff;
  --tg-hint: #8a8a8f;
  --tg-link: #62aaff;
  --tg-button: #2ea6ff;
  --tg-button-text: #ffffff;
  --border: #2a2b2e;
}

*{box-sizing:border-box;}

html,body{height:100%;}

body{
  margin:0;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  font-size:17px;
  background:var(--tg-bg);
  color:var(--tg-text);
  display:flex;
  flex-direction:column;
  overflow-x:hidden;
}

header{
  padding:12px 18px 0;
  flex:0 0 auto;
}

header .step-label{
  font-size:16px;
  color:var(--tg-hint);
}

main{
  flex:1 1 auto;
  min-height:0;
  padding:10px 18px 0;
  display:flex;
  flex-direction:column;
}

.step{
  display:none;
  flex:1 1 auto;
  min-height:0;
  flex-direction:column;
}
.step.active{display:flex;}

/* Preview sits at the top and takes the slack; every control is pinned to the
   bottom of the screen, within thumb reach on a phone. */
.stage{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding-bottom:14px;
}

.controls{
  flex:0 0 auto;
  display:flex;
  flex-direction:column;
  gap:12px;
  padding-bottom:18px;
}

.preview-wrap{
  width:100%;
  max-width:min(480px, 100%);
  max-height:100%;
  border-radius:18px;
  overflow:hidden;
  background:var(--tg-secondary-bg);
}

/* Square canvas scaled uniformly — never stretched, so the preview matches
   the exported image pixel for pixel. */
.preview-wrap canvas{
  width:100%;
  height:auto;
  max-height:100%;
  aspect-ratio:1/1;
  object-fit:contain;
  display:block;
  margin:0 auto;
}

.upload-box{
  border:2px dashed var(--tg-hint);
  border-radius:18px;
  padding:30px 18px;
  text-align:center;
  color:var(--tg-hint);
  font-size:18px;
  cursor:pointer;
  display:block;
}
.upload-box input{display:none;}

.field-label{
  font-size:16px;
  color:var(--tg-hint);
  display:block;
}

.field-error{
  font-size:15px;
  color:#ff6b6b;
}

input[type="text"], textarea{
  width:100%;
  background:var(--tg-secondary-bg);
  border:1px solid var(--border);
  color:var(--tg-text);
  border-radius:14px;
  padding:16px 18px;
  font-size:19px;
  font-family:inherit;
}
textarea{resize:none;line-height:1.35;}

input[type="text"]:focus, textarea:focus{
  outline:none;
  border-color:var(--tg-button);
}

.slider-block{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.slider-block .row{
  display:flex;
  justify-content:space-between;
  font-size:16px;
  color:var(--tg-hint);
}

/* Thumbless finger-sized slider: the filled portion of the track is the value
   indicator, so there is no small hit target to aim at. */
.slider{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:60px;
  border-radius:30px;
  border:1px solid var(--border);
  background:
    linear-gradient(to right,
      var(--tg-button) 0 var(--fill,50%),
      var(--tg-secondary-bg) var(--fill,50%) 100%);
  outline:none;
  cursor:pointer;
  touch-action:none;
}
.slider::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:1px;
  height:60px;
  background:transparent;
  border:none;
}
.slider::-moz-range-thumb{
  width:1px;
  height:60px;
  background:transparent;
  border:none;
}
.slider::-moz-range-track{
  background:transparent;
  height:60px;
}

footer{
  flex:0 0 auto;
  padding:0 18px calc(16px + env(safe-area-inset-bottom));
  background:var(--tg-bg);
  display:flex;
  gap:12px;
}

button{
  flex:1;
  border:none;
  border-radius:16px;
  padding:19px;
  font-size:18px;
  font-weight:600;
  font-family:inherit;
  cursor:pointer;
}

button.primary{
  background:var(--tg-button);
  color:var(--tg-button-text);
}
button.secondary{
  background:var(--tg-secondary-bg);
  color:var(--tg-text);
}
button:disabled{
  opacity:0.4;
  cursor:not-allowed;
}

.export-results{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  display:flex;
  flex-direction:column;
  gap:20px;
  padding-bottom:18px;
}
.notice{
  background:var(--tg-secondary-bg);
  border:1px solid var(--border);
  border-radius:14px;
  padding:14px 16px;
  font-size:16px;
  line-height:1.4;
  color:var(--tg-text);
}
.notice.error{
  border-color:#ff6b6b;
  color:#ff9b9b;
}
.send-btn{
  width:100%;
  flex:none;
}
.export-item{
  display:flex;
  flex-direction:column;
  gap:10px;
  align-items:center;
}
.export-item img{
  width:100%;
  max-width:480px;
  border-radius:18px;
}
.export-item a{
  display:block;
  width:100%;
  max-width:480px;
  text-align:center;
  background:var(--tg-button);
  color:var(--tg-button-text);
  text-decoration:none;
  padding:17px 18px;
  border-radius:16px;
  font-size:18px;
  font-weight:600;
}
