/*
 * Potter's Wheel scanner. Phone-first; the same palette and type as web/.
 * Paper screens (sign-in, home, review, done) use the web page's card look;
 * camera and corner-adjust screens are dark and edge to edge.
 */

:root {
  --teal:      #165F5B;
  --teal-dark: #0F4340;
  --teal-tint: #EAF2F1;
  --rose:      #E3335E;
  --rose-dark: #C22349;
  --rose-tint: #FDEDF1;
  --gold:      #FFBD59;
  --slate:     #4A5464;
  --ink:       #23312F;
  --muted:     #585857;
  --line:      #DCDEDD;
  --line-soft: #E7E7E7;
  --surface:   #FFFFFF;
  --page:      #F4F6F5;
  --night:     #0B1413;

  --radius:    14px;
  --radius-sm: 10px;
  --shadow:    0 1px 2px rgba(15, 67, 64, .06), 0 12px 32px rgba(15, 67, 64, .08);
  --focus:     0 0 0 3px rgba(22, 95, 91, .28);

  --display: "Poppins", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --body:    "Figtree", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: none; box-shadow: var(--focus); }

h1, h2 { font-family: var(--display); color: var(--teal-dark); line-height: 1.2; }
h1 { font-size: 1.5rem; margin: 0 0 6px; }

.boot { text-align: center; color: var(--muted); padding: 40vh 16px 0; margin: 0; }

/* ---- paper screens --------------------------------------------------------- */

.screen.paper { min-height: 100dvh; }

.masthead {
  background: var(--teal);
  padding: calc(18px + var(--safe-top)) 16px 46px;
  text-align: center;
}
.mark { display: block; margin: 0 auto; width: auto; height: 40px; }

.paper main { max-width: 560px; margin: -28px auto 0; padding: 0 16px 40px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
}

.lede { color: var(--muted); margin: 0 0 20px; }
.lede.small { font-size: .92rem; margin: 0; }

.gsi-slot { display: flex; justify-content: center; min-height: 44px; }

.primary, .secondary {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
}
.primary { background: var(--rose); color: #fff; }
.primary:active:not(:disabled) { background: var(--rose-dark); }
.primary:disabled { background: #C9CDCC; cursor: default; }
.primary.big { padding: 18px 20px; font-size: 1.1rem; }
.secondary { background: var(--teal-tint); color: var(--teal-dark); }

.linkish {
  background: none; border: 0; padding: 4px;
  color: var(--teal); text-decoration: underline; font-size: .92rem;
}

.pending {
  margin-top: 20px; padding: 16px;
  border-radius: var(--radius-sm);
  background: #FFF6E6;
  border: 1px solid #F5D9A8;
}
.pending p { margin: 0 0 12px; font-weight: 600; }

.who { text-align: center; color: var(--muted); font-size: .88rem; margin-top: 18px; }

.status { margin: 14px 0 0; font-size: .92rem; font-weight: 500; text-align: center; }
.status:empty { display: none; }
.status.bad { color: var(--rose-dark); }
.status.ok { color: var(--teal); }

/* ---- camera ---------------------------------------------------------------- */

.screen.dark {
  position: fixed; inset: 0;
  background: var(--night);
  color: #fff;
  display: flex; flex-direction: column;
  overscroll-behavior: none;
  touch-action: none;
}

.cam-top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
}
.cam-count { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
#cam-form { font-family: var(--display); font-weight: 600; }
#cam-pages { font-size: .85rem; opacity: .75; }
.cam-thumb {
  width: 38px; height: 50px; object-fit: cover;
  border-radius: 4px; border: 2px solid #fff;
}

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .12);
  font-size: 1.5rem; line-height: 1;
}
.icon-btn[aria-pressed="true"] { background: var(--gold); color: var(--night); }

.cam-stage { position: relative; flex: 1; min-height: 0; }
.cam-stage video, .cam-stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
}
.cam-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .55); padding: 6px 14px; border-radius: 999px;
  font-size: .9rem; white-space: nowrap;
}
.cam-hint:empty { display: none; }
.cam-flash {
  position: absolute; inset: 0; background: #fff; opacity: 0;
  pointer-events: none; transition: opacity .25s ease-out;
}
.cam-flash.on { opacity: .8; transition: none; }

.cam-bottom {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 14px 16px calc(12px + var(--safe-bot));
}
.cam-bottom > :first-child { justify-self: start; }
.cam-bottom > :last-child { justify-self: end; }
#screen-adjust .cam-bottom { grid-template-columns: 1fr 1fr; }

.pill {
  border: 0; border-radius: 999px; padding: 12px 18px; min-width: 96px;
  background: rgba(255, 255, 255, .14); color: #fff;
  font-family: var(--display); font-weight: 600; font-size: .95rem;
}
.pill.strong { background: var(--rose); }
.pill:disabled { opacity: .4; }

.shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 5px solid #fff; background: var(--rose);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .35);
}
.shutter:active:not(:disabled) { transform: scale(.94); }
.shutter:disabled { background: #555; }

.upload-link {
  text-align: center; font-size: .85rem; opacity: .75;
  padding: 0 0 calc(10px + var(--safe-bot)); text-decoration: underline;
}

/* ---- adjust ---------------------------------------------------------------- */

.adj-top { padding: calc(12px + var(--safe-top)) 16px 6px; text-align: center; }
.adj-top p { margin: 0; font-size: .95rem; opacity: .85; }

.adj-stage { position: relative; flex: 1; min-height: 0; margin: 8px 12px; }
#adj-canvas, #adj-svg { position: absolute; }
#adj-svg { overflow: visible; touch-action: none; }
.adj-poly { fill: rgba(22, 95, 91, .25); stroke: var(--gold); stroke-width: 2.5; }
.adj-handle { fill: rgba(255, 189, 89, .35); stroke: var(--gold); stroke-width: 3; }
.adj-hit { fill: transparent; cursor: grab; }

.adj-modes { display: flex; justify-content: center; gap: 8px; padding: 6px 12px 0; }
.mode {
  border: 1px solid rgba(255, 255, 255, .3); background: transparent; color: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: .85rem;
}
.mode[aria-checked="true"] { background: #fff; color: var(--night); border-color: #fff; }

/* ---- review ---------------------------------------------------------------- */

.bar {
  background: var(--teal); color: #fff;
  padding: calc(16px + var(--safe-top)) 16px 16px;
}
.bar h1 { color: #fff; margin: 0; }
.bar .lede { color: rgba(255, 255, 255, .8); }

.review-list { max-width: 560px; margin: 0 auto; padding: 16px 16px 180px; }

.group {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
  border: 2px solid transparent;
}
.group.has-error { border-color: var(--rose); }
.group.sent { opacity: .75; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.group-head h2 { font-size: 1.1rem; margin: 0; }
.badge { font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--line-soft); color: var(--slate); }
.badge.sending { background: #FFF6E6; color: #8A5A00; }
.badge.sent { background: var(--teal-tint); color: var(--teal-dark); }
.badge.failed { background: var(--rose-tint); color: var(--rose-dark); }

.thumbs {
  display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 6px;
  scroll-snap-type: x proximity;
}
.thumb {
  flex: 0 0 auto; position: relative; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; scroll-snap-align: start;
}
.thumb img { display: block; height: 110px; width: auto; border-radius: 5px; }
.thumb span {
  position: absolute; left: 4px; bottom: 4px; background: rgba(0, 0, 0, .6);
  color: #fff; font-size: .72rem; padding: 0 6px; border-radius: 999px;
}

.field { margin-top: 14px; }
.field label { display: block; font-family: var(--display); font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.req { color: var(--rose); margin-left: 3px; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); appearance: none;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--slate) 50%),
                    linear-gradient(135deg, var(--slate) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--teal); box-shadow: var(--focus); }
.field.has-error input, .field.has-error select { border-color: var(--rose); background: var(--rose-tint); }
.field .error { color: var(--rose-dark); font-size: .85rem; margin: 6px 0 0; }
.field .note { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.progress {
  height: 4px; margin-top: 10px; border-radius: 999px;
  background: var(--line-soft); overflow: hidden;
}
.progress span {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: var(--teal); transition: width .25s ease-out;
}
/* Apps Script reports no progress, so "saving" crawls toward the end instead
   of sitting still -- a bar that stops reads as a stuck upload. */
.progress.saving span { animation: pw-crawl 12s cubic-bezier(.1, .6, .3, 1) forwards; }
@keyframes pw-crawl { from { width: 60%; } to { width: 95%; } }
@media (prefers-reduced-motion: reduce) {
  .progress.saving span { animation: none; width: 80%; }
}

.group-actions { display: flex; justify-content: space-between; margin-top: 12px; }
.group-actions button { background: none; border: 0; color: var(--teal); font-size: .9rem; padding: 6px 2px; text-decoration: underline; }
.group-actions .danger { color: var(--rose-dark); }
.group-msg { margin: 10px 0 0; font-size: .88rem; }
.group-msg.bad { color: var(--rose-dark); }
.group-msg.ok { color: var(--teal); }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line-soft);
  padding: 12px 16px calc(12px + var(--safe-bot));
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
}
.sticky-actions .secondary { width: auto; padding-inline: 22px; white-space: nowrap; }
.sticky-actions .status { grid-column: 1 / -1; margin: 2px 0 0; }

/* ---- done ------------------------------------------------------------------ */

.done { text-align: center; }
.tick {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%;
  background: var(--teal-tint); color: var(--teal); font-size: 1.8rem; line-height: 56px; font-weight: 700;
}
.done-list { list-style: none; padding: 0; margin: 12px 0 22px; text-align: left; }
.done-list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: .95rem; }
.done-list li:last-child { border-bottom: 0; }
.done-list .rc { color: var(--muted); font-size: .8rem; font-family: ui-monospace, Menlo, monospace; }
.done .linkish { margin-top: 12px; }

/* ---- dialogs --------------------------------------------------------------- */

.viewer {
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0; padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bot));
  border: 0; background: var(--night); color: #fff;
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: rgba(0, 0, 0, .8); }
#viewer-img { flex: 1; min-height: 0; object-fit: contain; width: 100%; background: #222; border-radius: 6px; }
.viewer-caption { text-align: center; margin: 8px 0; font-size: .9rem; opacity: .8; }
.viewer-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.viewer-actions button {
  border: 0; border-radius: 10px; padding: 12px 6px; background: rgba(255, 255, 255, .14); color: #fff; font-size: .9rem;
}
.viewer-actions button:disabled { opacity: .35; }
.viewer-actions .danger { grid-column: 1 / 2; background: rgba(227, 51, 94, .3); }
.viewer-actions .strong { grid-column: 2 / 4; background: var(--rose); font-weight: 600; }

.reauth {
  border: 0; border-radius: var(--radius); padding: 24px 20px; max-width: 360px; width: calc(100vw - 32px);
  box-shadow: var(--shadow); text-align: center;
}
.reauth::backdrop { background: rgba(11, 20, 19, .6); }
.reauth h2 { margin: 0 0 8px; }
.reauth p { color: var(--muted); font-size: .95rem; margin: 0 0 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(120px + var(--safe-bot)); transform: translateX(-50%);
  background: rgba(20, 30, 29, .92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: .92rem; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
