/* Try-on app. Tokens, logo and buttons come from brand.css. */

:root {
  --panel-w: 330px;
  --header-h: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --top: calc(var(--header-h) + var(--safe-top));
  --ok: #1f9d55;
  --warn: #c98a00;
  --err: #d64545;
}

html, body { height: 100%; overflow: hidden; }
body { background: var(--page); }

/* ---------------------------------------------------------------- header */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--top);
  padding: var(--safe-top) max(20px, var(--safe-right)) 0 max(20px, var(--safe-left));
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}
.app-header .logo-dos { height: 40px; }
.header-end { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.back-btn { min-height: 44px; padding: 8px 16px; }

#status {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--tile);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--line);
  vertical-align: 0;
}
#status[data-kind="ok"]::before { background: var(--ok); }
#status[data-kind="warn"]::before { background: var(--warn); }
#status[data-kind="error"] { color: var(--err); border-color: #f1c6c6; background: #fff6f6; }
#status[data-kind="error"]::before { background: var(--err); }

/* ----------------------------------------------------------------- stage */

#stage {
  position: fixed;
  top: var(--top);
  right: var(--panel-w);
  bottom: 0;
  left: 0;
  overflow: hidden;
  touch-action: none;
  background: #0b1f30;
}
body[data-mode="preview"] #stage {
  background: radial-gradient(ellipse at 50% 38%, #ffffff 0%, #eef1f4 55%, #dfe4e9 100%);
}

#frame { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#frame.mirrored { transform: translate(-50%, -50%) scaleX(-1); }
#video, #gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#video { object-fit: fill; }
body:not([data-mode="camera"]) #video { visibility: hidden; }

/* ----------------------------------------------------------------- intro */

#intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    linear-gradient(rgba(6, 42, 66, 0.82), rgba(6, 42, 66, 0.92)),
    radial-gradient(ellipse at 30% 20%, #1e4166 0%, #062a42 70%);
  color: #fff;
  text-align: center;
}
body:not([data-mode="idle"]) #intro { display: none; }
.intro-inner { max-width: 460px; }
#intro h1 { margin: 0 0 14px; font-size: 30px; font-weight: 400; }
#intro p { margin: 0 0 28px; color: rgba(255, 255, 255, 0.85); }
.intro-actions { display: grid; gap: 12px; }
.intro-actions .btn { width: 100%; }
#intro .intro-note { margin: 28px 0 0; font-size: 13px; color: rgba(255, 255, 255, 0.6); }

/* ----------------------------------------------------------------- panel */

#panel {
  position: fixed;
  top: var(--top);
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}
.panel-body { padding: 22px max(22px, var(--safe-right)) calc(28px + var(--safe-bottom)) 22px; }
#panel-toggle { display: none; }

#panel h2 {
  margin: 22px 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
#panel h2:first-child { margin-top: 0; }
.hint { margin-left: 4px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--heading); }

.styles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.style-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
}
.style-btn:hover { border-color: var(--cyan); }
.style-btn span { font-weight: 700; color: var(--heading); text-transform: uppercase; font-size: 13px; letter-spacing: 0.04em; }
.style-btn small { color: var(--muted); font-size: 11px; }
.style-btn.selected { border-color: var(--cyan); background: #eef8fa; }
.style-btn.selected span { color: var(--cyan); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  outline: 1px solid var(--line);
  background: var(--c);
  padding: 0;
}
.swatch:hover { outline-color: var(--cyan); }
.swatch.selected { outline: 2px solid var(--cyan); }
.swatch.tortoise {
  background:
    radial-gradient(circle at 30% 35%, #c78a3e 0 18%, transparent 30%),
    radial-gradient(circle at 70% 65%, #a2642a 0 15%, transparent 28%),
    radial-gradient(circle at 65% 25%, #140902 0 12%, transparent 22%),
    #3b1f0c;
}
.swatch.clear { background: linear-gradient(135deg, #ffffff, #dfe7ee); }
.swatch.mirror { background: linear-gradient(135deg, #9fc4ff, var(--c) 55%, #0b1a3a); }

.slider { display: block; margin-bottom: 14px; font-size: 14px; }
.slider output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; margin-top: 6px; accent-color: var(--cyan); }

.toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--cyan); }

.panel-actions { display: grid; gap: 8px; margin-top: 24px; }
body:not([data-mode="camera"]) .when-camera { display: none; }
body:not([data-mode="preview"]) .when-preview { display: none; }
body[data-mode="idle"] #shot { display: none; }

#toast { left: calc((100% - var(--panel-w)) / 2); }

/* ---------------------------------------------------------------- narrow */

/* ------------------------------------------------------- size & measure */

.measure { margin-bottom: 14px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--tile); }
.measure-status { margin: 0 0 8px; font-size: 13px; color: var(--text); }
.measure-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.measure-bar span { display: block; height: 100%; width: 0; background: var(--cyan); transition: width 0.2s; }
.measure-result { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 0; }
.measure-result div { padding: 8px; background: var(--surface); border-radius: var(--radius-sm); }
.measure-result dt { font-size: 11px; color: var(--muted); }
.measure-result dd { margin: 2px 0 0; font-size: 18px; font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.measure-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.measure .link-btn { margin-top: 6px; color: var(--cyan); font-weight: 700; font-size: 13px; }

.sub-title { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--heading); }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.size-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.size-btn b { font-size: 16px; color: var(--heading); }
.size-btn small { font-size: 11px; color: var(--muted); }
.size-btn:hover { border-color: var(--cyan); }
.size-btn.selected { border-color: var(--cyan); background: #eef8fa; }
.size-btn.selected b { color: var(--cyan); }
.size-btn .rec {
  position: absolute;
  top: -8px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  background: var(--cyan);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pd-input { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; font-size: 13px; }
.pd-field { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.pd-field input {
  width: 64px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--heading);
}
.pd-field input:focus { border-color: var(--cyan); outline: none; }

#hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 5;
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(6, 42, 66, 0.82);
  color: #e6f5f8;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  pointer-events: none;
}

/* ------------------------------------------------------------- phones */

@media (max-width: 760px) {
  :root { --header-h: 56px; --sheet-h: 46vh; --peek-h: 132px; }
  @supports (height: 1dvh) { :root { --sheet-h: 46dvh; } }

  .app-header { gap: 8px; padding-left: max(12px, var(--safe-left)); padding-right: max(12px, var(--safe-right)); }
  .app-header .logo-dos { height: 30px; }
  .back-btn { min-height: 40px; padding: 6px 10px; }
  .back-btn span { display: none; }
  .lang-btn { height: 40px; padding: 0 8px; }
  #status { font-size: 12px; padding: 5px 8px; }

  /* Settings live in a bottom sheet; the camera gets the rest of the screen. */
  #stage { right: 0; bottom: calc(var(--sheet-h) + var(--safe-bottom)); }
  #panel {
    top: auto;
    left: 0;
    width: 100%;
    height: calc(var(--sheet-h) + var(--safe-bottom));
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(6, 42, 66, 0.12);
    transition: height 0.25s ease;
  }
  body.panel-collapsed #stage { bottom: calc(var(--peek-h) + var(--safe-bottom)); }
  body.panel-collapsed #panel { height: calc(var(--peek-h) + var(--safe-bottom)); overflow: hidden; }

  /* Intro covers the whole screen; the sheet appears once a mode is chosen. */
  body[data-mode="idle"] #panel { display: none; }
  body[data-mode="idle"] #stage { bottom: 0; }

  #panel-toggle {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 100%;
    height: 32px;
    background: var(--surface);
    color: var(--muted);
  }
  #panel-toggle::before {
    content: "";
    position: absolute;
    top: 8px;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
  }
  #panel-toggle svg { margin-top: 8px; width: 18px; height: 18px; transition: transform 0.2s; }
  body.panel-collapsed #panel-toggle svg { transform: rotate(180deg); }
  .panel-body { padding: 0 16px calc(24px + var(--safe-bottom)); }
  #panel h2 { margin: 16px 0 8px; }
  #panel h2:first-child { margin-top: 2px; }

  /* Rows that scroll sideways instead of wrapping: frames and swatches. */
  .styles, .swatches {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0 -16px;
    padding: 4px 16px 6px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 16px;
    scrollbar-width: none;
  }
  .styles::-webkit-scrollbar, .swatches::-webkit-scrollbar { display: none; }
  .style-btn { flex: 0 0 auto; min-width: 132px; scroll-snap-align: start; }
  .swatch { flex: none; width: 36px; height: 36px; scroll-snap-align: start; }

  .pd-field input { height: 40px; font-size: 16px; }   /* 16px: no iOS zoom on focus */
  .slider input { height: 28px; }
  .toggle { min-height: 36px; }
  #toast { left: 50%; bottom: calc(var(--sheet-h) + var(--safe-bottom) + 12px); }
  body.panel-collapsed #toast { bottom: calc(var(--peek-h) + var(--safe-bottom) + 12px); }
  #intro h1 { font-size: 26px; }
}

/* Phones held sideways: little height, so a slim header and a narrower side panel. */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --header-h: 48px; --panel-w: min(320px, 42vw); }
  .app-header .logo-dos { height: 26px; }
  .back-btn { min-height: 34px; padding: 4px 10px; }
  .back-btn span { display: none; }
  .lang-btn { height: 34px; }
  #status { font-size: 12px; padding: 4px 8px; }
  #panel-toggle { display: none; }
  .panel-body { padding-top: 12px; padding-left: max(16px, var(--safe-left)); }
  #panel h2 { margin: 14px 0 8px; }
  #intro { align-items: start; overflow-y: auto; }
  #intro h1 { font-size: 22px; margin-bottom: 8px; }
  #intro p { margin-bottom: 14px; }
  .intro-actions { grid-template-columns: 1fr 1fr; }
  #intro .intro-note { margin-top: 12px; }
}

/* --------------------------------------------------------- face shape */

.face-shape { margin-top: 4px; }
.heads { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.head-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  color: var(--text);
}
.head-btn svg { width: 26px; height: 32px; fill: var(--skin); fill-opacity: 0.55; stroke: var(--heading); stroke-width: 2; }
.head-btn:hover { border-color: var(--cyan); }
.head-btn.selected { border-color: var(--cyan); background: #eef8fa; color: var(--cyan); font-weight: 700; }
.head-btn.selected svg { stroke: var(--cyan); }
.face-detect { margin: 0 0 10px; font-size: 13px; color: var(--text); }
.suits { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.suits-label { font-size: 12px; color: var(--muted); }
.suits-list { display: flex; flex-wrap: wrap; gap: 6px; }
.suit-chip {
  padding: 5px 10px;
  border: 1px solid var(--cyan);
  border-radius: 999px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 700;
}
.suit-chip:hover, .suit-chip.selected { background: var(--cyan); color: #fff; }
.face-tip { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.style-btn { position: relative; }
.style-btn.suits::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cyan);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .heads {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0 -16px 10px;
    padding: 2px 16px 6px;
    overflow-x: auto;
    scroll-padding-inline: 16px;
    scrollbar-width: none;
  }
  .heads::-webkit-scrollbar { display: none; }
  .head-btn { flex: 0 0 auto; min-width: 84px; min-height: 64px; }
  .suit-chip { padding: 8px 12px; }
}
.head-btn { position: relative; }
.head-btn .auto {
  position: absolute;
  top: -7px;
  right: 4px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  background: var(--cyan);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}
