/* Tee Designer — mobile-first studio tool */
:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --panel: #241f1b;
  --panel-2: #2c261f;
  --line: #3d342c;
  --ink: #f6efe4;
  --muted: #b7a89a;
  --accent: #c45a34;
  --accent-2: #c4a46a;
  --danger: #e07060;
  --ok: #86a56f;
  --warn: #d4a04a;
  --shadow: 0 16px 40px rgba(0,0,0,.4);
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Figtree", "Segoe UI", system-ui, sans-serif;
  --header: 3.35rem;
  --dock: 4.15rem;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body { position: fixed; inset: 0; overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; }
img { max-width: 100%; display: block; }

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  background: var(--bg);
}

.top {
  flex: 0 0 var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: 0 .9rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
}
.brand { min-width: 0; }
.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  line-height: 1.1;
}
.sub { color: var(--muted); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: .35rem; }

.segment {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.segment button {
  padding: .35rem .75rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: .82rem;
  min-height: 32px;
  white-space: nowrap;
}
.segment button.on { background: var(--ink); color: var(--bg); }
.segment.wide button, .segment.stacked button { flex: 1; }
.segment.tiny button { padding: .28rem .5rem; font-size: .72rem; min-height: 30px; }
.segment.stacked { flex-direction: column; border-radius: 12px; }
.segment.stacked button { border-radius: 10px; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
}
.icon-btn:disabled { opacity: .35; cursor: default; }

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  background: var(--bg);
}

.rail { display: none; width: 250px; overflow: auto; padding: .7rem; gap: .55rem; flex-direction: column; }
.rail-left { border-right: 1px solid var(--line); }
.rail-right { border-left: 1px solid var(--line); width: 270px; }
.rail-right .panel:last-child { margin-top: auto; flex-shrink: 0; }
.rail-right #propsDesktopWrap, .rail-right .panel:first-child { min-height: 0; overflow: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .7rem;
}
.panel h2, .sheet h2 {
  margin: 0 0 .6rem;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.sheet h3 {
  margin: 1rem 0 .45rem;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.stage-bar {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .7rem 0;
  flex-wrap: wrap;
}
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: .4rem .6rem .3rem;
  background:
    radial-gradient(ellipse at 50% 42%, #eee8df 0%, #d5cfc6 58%, #c3bbb1 100%);
  margin: .45rem .6rem;
  border-radius: 16px;
  border: 1px solid var(--line);
}
.stage-inner {
  position: relative;
  height: 100%;
  width: auto;
  aspect-ratio: 800 / 800;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}
#shirtMount, #designCanvas, #handles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#shirtMount svg { width: 100%; height: 100%; display: block; overflow: visible; }
#designCanvas { display: block; }
#handles { pointer-events: none; }
#handles .box, #handles .handle, #handles .rot {
  position: absolute;
  pointer-events: auto;
}
#handles .box {
  border: 1.5px solid var(--accent-2);
  box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}
#handles .handle {
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  background: #fff;
  border: 2px solid var(--accent-2);
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
#handles .rot {
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
}
#handles .rot-line {
  position: absolute;
  width: 1.5px;
  background: var(--accent-2);
  pointer-events: none;
  transform-origin: bottom center;
}

.warn-bar {
  margin: 0 .7rem .35rem;
  padding: .5rem .7rem;
  background: color-mix(in srgb, var(--warn) 18%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  color: #f3d7a0;
  border-radius: 10px;
  font-size: .8rem;
  line-height: 1.35;
}

.prop-bar {
  display: none;
  margin: 0 .7rem calc(.35rem + var(--safe-bot));
}

.dock {
  flex: 0 0 calc(var(--dock) + var(--safe-bot));
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: .35rem .4rem var(--safe-bot);
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.dock button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  color: var(--muted);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .25rem 0;
  min-height: 44px;
}
.dock button:active, .dock button.on { color: var(--ink); }

.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 20;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: .4rem 1rem calc(1.1rem + var(--safe-bot));
  box-shadow: var(--shadow);
  max-height: 78dvh;
  overflow: auto;
}
.sheet.tall { max-height: 86dvh; }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 4px;
  background: var(--line); margin: .35rem auto .7rem;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .45rem;
  padding: 4px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
  min-height: 36px;
}
.swatch.on { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-2); }
.swatch.light { box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }

.custom-color {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .7rem; color: var(--muted); font-size: .85rem;
}
.custom-color input { width: 48px; height: 32px; border: 0; background: none; padding: 0; }

.add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
}
.add-btn, .text-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem .6rem;
  font-weight: 600;
  min-height: 42px;
  text-align: center;
}
.add-btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.text-btn { display: block; width: 100%; margin-bottom: .4rem; text-align: left; padding-left: .85rem; }
.check { display: flex; align-items: center; gap: .4rem; margin-top: .55rem; color: var(--muted); font-size: .85rem; }
.check.slim { margin-top: 0; font-size: .75rem; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .7rem; color: var(--muted); font-size: .8rem; }
.field input, .field select, .field textarea, .props input, .props select, .props textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem .7rem;
  font-size: 16px; /* prevent iOS zoom */
  width: 100%;
}
.props { display: flex; flex-direction: column; gap: .55rem; margin-top: .5rem; }
.props label { display: flex; flex-direction: column; gap: .25rem; font-size: .75rem; color: var(--muted); }
.props .row { display: flex; gap: .4rem; }
.props .row > * { flex: 1; }
.props input[type="range"] { padding: 0; accent-color: var(--accent); }
.props input[type="color"] { padding: 0; height: 36px; }
.hint { color: var(--muted); font-size: .78rem; line-height: 1.45; margin: .7rem 0 0; }

.layer-list { display: flex; flex-direction: column; gap: .3rem; min-height: 2rem; }
.layer-item {
  display: flex; align-items: center; gap: .4rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .35rem .4rem;
  min-height: 44px;
}
.layer-item.on { border-color: var(--accent-2); }
.layer-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.layer-item button { width: 32px; height: 32px; border-radius: 8px; color: var(--muted); }
.layer-item button:hover, .layer-item button:active { color: var(--ink); background: var(--panel); }
.layer-empty { color: var(--muted); font-size: .85rem; padding: .3rem; }

.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  text-align: left;
}
.card img { width: 100%; aspect-ratio: 4/5; object-fit: cover; background: #3a3530; }
.card .meta { padding: .5rem .6rem .65rem; }
.card .meta strong { display: block; font-size: .85rem; }
.card .meta span { color: var(--muted); font-size: .72rem; }
.card .meta .row { display: flex; gap: .3rem; margin-top: .35rem; }
.card .meta button { flex: 1; min-height: 34px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: .75rem; font-weight: 600; }
.card .meta button.danger { color: var(--danger); }

.install-hint {
  position: fixed;
  left: .7rem; right: .7rem;
  bottom: calc(var(--dock) + var(--safe-bot) + .5rem);
  z-index: 15;
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  padding: .7rem .8rem;
  display: flex;
  gap: .6rem;
  align-items: center;
  font-size: .82rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.install-hint button {
  flex: 0 0 auto;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  padding: .4rem .65rem;
  min-height: 36px;
}

@media (min-width: 960px) {
  .dock, .stage-bar, #installHint { display: none !important; }
  .rail { display: flex; }
  .stage { padding: 1rem; }
  .prop-bar { display: none !important; }
  .warn-bar { margin: 0 1rem .8rem; }
}

@media (max-width: 959px) {
  .prop-bar.show {
    display: block;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .5rem .65rem;
    margin-bottom: calc(.4rem + var(--safe-bot));
  }
  /* On mobile the dock already accounts for the safe area; don't double-pad the prop bar */
  .prop-bar.show { margin-bottom: .4rem; }
}
