/* LEVÉ Ring Sizer — single consolidated stylesheet.
   Replaces nstyle.css, mstyle.css, measureFinger.css, svg_animation.css. */

@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ---------- Tokens ---------- */

:root {
  --brown: #764834;
  --brown-dark: #5a382a;
  --brown-tint: #f3ece7;
  --line: #e7dcd4;
  --ink: #433126;
  --bg: #faf7f4;
  --surface: #ffffff;
  --accent: #5448f9;
  --radius: 18px;
  --shadow-soft: 0 4px 20px rgba(118, 72, 52, 0.10);
  --shadow-lift: 0 12px 32px rgba(118, 72, 52, 0.20);
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* Prevent double-tap zoom on mobile */
  touch-action: manipulation;
}

/* Both measuring elements are sized by their CONTENT box, with the blue
   border drawn OUTSIDE it. The visible boundary (card image edge, white
   disc edge) is the exact measuring edge; the border is a guide that can
   be any thickness without affecting accuracy. */
#cardSizer,
#ringSizer {
  box-sizing: content-box;
}

body {
  font-family: 'Poppins', sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  opacity: 0;
  animation: fadeIn 0.4s ease forwards;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

/* Keep the screen still while a card or ring is held against it, and
   compress everything except the stage so the action buttons stay above
   the browser's URL bar */
@media (max-width: 600px) {
  body.page-ring {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
  }

  body.page-ring .site-header { padding: 10px 20px 0; }
  body.page-ring .site-header img { width: 110px; }

  body.page-ring main {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  body.page-ring .hint { font-size: 0.8rem; }

  /* Let the stage absorb all leftover height */
  body.page-ring .stage {
    flex: 1 1 0;
    height: auto;
    min-height: 110px;
  }

  body.page-ring .actions { margin-top: 22px; }
}

h1, h2, h3 {
  color: var(--brown);
  font-weight: 600;
  line-height: 1.25;
}

h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }

a { color: var(--brown); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.fade-in  { animation: fadeIn 0.2s ease forwards; }
.fade-out { animation: fadeOut 0.2s ease forwards; }

body.fade-out {
  animation: fadeOut 0.2s;
  opacity: 0;
}

:focus-visible {
  outline: 3px solid rgba(118, 72, 52, 0.55);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header & footer ---------- */

.site-header {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 18px 20px 6px;
}

.site-header img {
  width: 170px;
  display: block;
}

.site-footer {
  padding: 18px;
  font-size: 0.85rem;
  color: var(--brown);
  margin-top: auto;
}

.site-footer a { text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

main {
  width: 100%;
  max-width: 1080px;
  padding: 8px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.lede {
  color: var(--brown);
  margin: 8px 0 0;
  font-size: 1.05rem;
}

/* ---------- Buttons & controls ---------- */

.btn {
  font-family: 'Poppins', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 13px 26px;
  border-radius: 12px;
  border: 1.5px solid var(--brown);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background-color 0.15s ease, color 0.15s ease,
              transform 0.1s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn-primary {
  background-color: var(--brown);
  color: #ffffff;
  box-shadow: var(--shadow-soft);
}

.btn-primary:hover {
  background-color: var(--brown-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift);
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--brown);
}

.btn-secondary:hover { background-color: var(--brown-tint); }

.round-btn {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 50%;
  border: 1.5px solid var(--brown);
  background-color: var(--surface);
  color: var(--brown);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.round-btn:hover { background-color: var(--brown-tint); }

/* Range sliders */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: min(340px, 60vw);
  height: 6px;
  background: var(--line);
  border-radius: 6px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  background-color: #ffffff;
  border: 2px solid var(--brown);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  background-color: #ffffff;
  border: 2px solid var(--brown);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

/* ---------- Landing tiles ---------- */

.tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 28px;
  margin-top: clamp(24px, 8vh, 72px);
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 210px;
  height: 210px;
  background: var(--brown);
  color: #ffffff;
  border: none;
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  padding: 20px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: var(--shadow-lift);
}

.tile .icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Line-drawing animation on the landing icons */

.tile .ring {
  stroke: #ffffff;
  stroke-width: 2px;
  stroke-dasharray: 2000;
  animation: drawRing 3s infinite alternate-reverse forwards;
  animation-delay: -1.5s;
}

.tile .hand {
  stroke: #ffffff;
  stroke-width: 10px;
  stroke-dasharray: 2000;
  animation: drawHand 3s infinite alternate forwards;
}

@keyframes drawRing {
  from { stroke-dashoffset: -320; }
  to   { stroke-dashoffset: 0; }
}

@keyframes drawHand {
  from { stroke-dashoffset: -1500; }
  to   { stroke-dashoffset: 100; }
}

.chart-link {
  margin-top: 26px;
  background: none;
  border: none;
  font-family: 'Poppins', sans-serif;
  font-size: 0.92rem;
  color: var(--brown);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 8px 12px;
}

.chart-link:hover { color: var(--brown-dark); }

.modal-card.chart-card {
  width: min(430px, 94vw);
}

.chart-card h3 { margin-top: 10px; }

.size-chart-table {
  border-collapse: collapse;
  margin: 16px 0 10px;
  font-size: 0.92rem;
}

.size-chart-table th,
.size-chart-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.size-chart-table th {
  color: var(--brown);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.size-chart-table td:first-child {
  color: var(--brown);
  font-weight: 600;
}

.size-chart-table tr:last-child td { border-bottom: none; }

.chart-note {
  font-size: 0.8rem;
  color: var(--brown);
  opacity: 0.8;
  margin: 0 10px 6px;
}

/* ---------- Measure wizard (card + ring pages) ---------- */

.step-kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--brown);
  opacity: 0.75;
  margin-top: 10px;
}

.wizard {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.wizard h1 { margin-top: 2px; }

.hint {
  max-width: 560px;
  margin: 10px auto 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
}

.hint .accent { color: var(--accent); }

/* Clip sideways only: the card may legitimately be wider than a phone
   screen, but its top and bottom edges must never be cut off — they're
   what the user lines up against. Vertical overflow draws over the
   neighbouring text instead of disappearing. */
.stage {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: clip;
  overflow-y: visible;
  margin: 6px 0;
}

.stage-card { height: clamp(230px, 46vh, 480px); }
.stage-ring { height: clamp(190px, 38vh, 420px); }

#cardSizer {
  background-image: url(img/cc.svg);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: transform 0.2s ease;
  /* The blue lines sit outside the card's 85.6x53.98mm box, so their
     inner edges bound exactly one card: the card "fits between the lines".
     Thickness is outside the measuring edge and can't affect accuracy. */
  border: 4px solid var(--accent);
  border-radius: 14px;
  flex: none;
  /* Purely visual: when scaled up it may overlap the controls, and must
     never swallow their taps */
  pointer-events: none;
}

#ringSizer {
  background-color: #ffffff;
  /* No shadow: the white disc's edge is the measuring edge and must be
     crisp. Its diameter is exactly 20mm x scale; the border sits outside. */
  transition: transform 0.2s ease;
  flex: none;
  pointer-events: none;
}

.slider-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 8px 0;
  user-select: none;
  -webkit-user-select: none;
  /* Stay visible above an overflowing card/circle */
  position: relative;
  z-index: 2;
}

.readout {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 20px;
  font-size: 0.9rem;
  color: var(--brown);
  margin-top: 2px;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  /* Keep a deliberate gap below the slider so a finger coming off it
     can't land on Set/Calculate */
  margin-top: 26px;
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(40, 25, 17, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-backdrop.fade-in { display: flex; }

.modal-card {
  position: relative;
  width: min(360px, 92vw);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lift);
  padding: 22px 22px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 1.15rem;
  color: #b4a294;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}

.modal-close:hover { color: var(--brown); }

.modal-card img {
  max-width: 100%;
  border-radius: 14px;
  margin: 14px 0 12px;
}

.modal-card p {
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 4px 16px 14px;
}

.result-card img { width: 90px; margin-top: 20px; }

.result-card #displayDiameter {
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 2px;
}

.result-card #displaySize {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--brown);
  margin-bottom: 20px;
}

/* ---------- Measure-finger page ---------- */

.measure-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 26px 26px 30px;
  margin-top: 14px;
  max-width: 460px;
  width: 100%;
}

.measure-card h1 { font-size: 1.3rem; }

.input-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 20px;
}

.input-row input {
  width: 120px;
  padding: 12px;
  font-family: 'Poppins', sans-serif;
  font-size: 1.05rem;
  text-align: center;
  color: var(--brown);
  border: 2px solid var(--brown);
  border-radius: 10px;
  outline: none;
}

.input-row input:focus { box-shadow: 0 0 0 3px rgba(118, 72, 52, 0.25); }
.input-row input:focus::placeholder { color: transparent; }

.input-row .unit {
  font-size: 1rem;
  color: var(--brown);
}

.steps-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin: 28px 0 10px;
  max-width: 1000px;
}

.step-card {
  flex: 1 1 280px;
  max-width: 320px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.step-card img {
  width: 100%;
  height: auto;
  display: block;
}

.step-card p {
  font-size: 0.88rem;
  line-height: 1.55;
  padding: 14px 18px 20px;
  margin: auto 0;
}

#goToTop {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 24px;
  z-index: 99;
  border: none;
  background-color: var(--brown);
  color: #ffffff;
  cursor: pointer;
  padding: 13px 15px;
  border-radius: 12px;
  font-size: 1.1rem;
  box-shadow: var(--shadow-soft);
}

#goToTop:hover { background-color: var(--brown-dark); }

/* ---------- Error page ---------- */

.error-page h1 {
  font-size: 4rem;
  margin-top: clamp(30px, 18vh, 140px);
}

.error-page p { margin: 8px 0 26px; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  body { opacity: 1; }
}
