/* ============================================================
   Kupi²RentSplitter — style.css
   Mobile-first, responsive from 320 px to 1440 px
   ============================================================ */

/* ── 1. Design tokens (CSS custom properties) ── */
:root {
  /* Colors */
  --color-bg:        #E6EEEA;   /* light mint-grey page background */
  --color-text:      #102A2A;   /* deep green-black for all text   */
  --color-accent:    #F2C230;   /* signal yellow for primary CTAs  */
  --color-white:     #FFFFFF;
  --color-card-bg:   #FFFFFF;
  --color-border:    #C8D9D2;   /* subtle green-grey borders        */
  --color-muted:     #4A6A6A;   /* secondary / caption text         */
  --color-error:     #CC3333;
  --color-receipt-bg:#FDFAF3;   /* warm off-white for the receipt   */
  --color-receipt-dash: #B8C9C0;

  /* Typography */
  --font-head: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Courier New', Courier, monospace; /* receipt numbers */

  /* Spacing scale (multiples of 4 px) */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-24: 96px;

  /* Border radius */
  --radius-sm:  6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Shadows */
  --shadow-card: 0 2px 16px 0 rgba(16, 42, 42, 0.08);
  --shadow-input: 0 0 0 3px rgba(242, 194, 48, 0.40);

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast:  150ms;
  --dur-mid:   250ms;
  --dur-slow:  400ms;

  /* Layout */
  --container-max: 1080px;
  --header-h:       60px;
}

/* ── 2. Reset & base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* Smooth scrolling for anchor jumps */
  scroll-behavior: smooth;
  /* Prevent horizontal overflow */
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;          /* 16 px */
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  /* Tabular numerals everywhere — digits line up in columns */
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
ol, ul { list-style: none; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
input, button { font: inherit; }

/* ── 3. Skip link (keyboard / a11y) ── */
.skip-link {
  position: absolute;
  top: var(--sp-2);
  left: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--color-accent);
  color: var(--color-text);
  font-weight: 700;
  border-radius: var(--radius-sm);
  z-index: 9999;
  /* Hide visually but keep focusable */
  transform: translateY(-120%);
  transition: transform var(--dur-fast) var(--ease-out);
}
.skip-link:focus {
  transform: translateY(0);
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}

/* ── 4. Container ── */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}
@media (min-width: 600px) {
  .container { padding-inline: var(--sp-6); }
}
@media (min-width: 900px) {
  .container { padding-inline: var(--sp-8); }
}

/* ── 5. HEADER ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  /* Slight frosted effect on browsers that support it */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.92);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  letter-spacing: -0.02em;
}
.logo-icon { font-size: 1.1em; }

.nav-list {
  display: flex;
  gap: var(--sp-5);
}
.nav-list a {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-muted);
  padding: var(--sp-2) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.nav-list a:hover,
.nav-list a:focus-visible {
  color: var(--color-text);
  border-color: var(--color-accent);
  outline: none;
}

/* ── 6. HERO ── */
.hero {
  padding-block: var(--sp-16) var(--sp-12);
  text-align: center;
  /* Top padding accounts for sticky header */
  padding-top: calc(var(--sp-16) + var(--sp-4));
}

.hero-heading {
  font-family: var(--font-head);
  font-size: clamp(2.4rem, 6vw + 1rem, 5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--color-text);
  margin-bottom: var(--sp-5);
}
.hero-heading em {
  font-style: normal;
  /* Highlight the payoff phrase with accent underline */
  background: linear-gradient(to bottom, transparent 65%, var(--color-accent) 65%);
  background-size: 100% 100%;
}

.hero-sub {
  font-size: 1.125rem;
  color: var(--color-muted);
  max-width: 48ch;
  margin-inline: auto;
  margin-bottom: var(--sp-8);
  line-height: 1.65;
}

/* ── 7. Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-6);
  min-height: 44px;
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text);
  font-size: 1.125rem;
  padding: var(--sp-4) var(--sp-8);
  min-height: 52px;
  box-shadow: 0 4px 0 0 #c9a020;
}
.btn-primary:hover,
.btn-primary:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 0 #c9a020;
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}
.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 0 #c9a020;
}

/* Copy-summary button inside receipt */
.btn-copy {
  background: var(--color-accent);
  color: var(--color-text);
  width: 100%;
  margin-top: var(--sp-4);
  min-height: 48px;
}
.btn-copy:hover,
.btn-copy:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 0 #c9a020;
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}

/* Minimal text-link style for "Clear all" */
.btn-text-link {
  background: none;
  border: none;
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: var(--sp-2) 0;
  margin-top: var(--sp-3);
  min-height: 44px;
  transition: color var(--dur-fast) var(--ease-out);
}
.btn-text-link:hover,
.btn-text-link:focus-visible {
  color: var(--color-text);
  outline: 2px solid var(--color-text);
  outline-offset: 3px;
}

/* ── 8. CALCULATOR SECTION ── */
.calculator-section {
  padding-block: var(--sp-12);
}

.section-title {
  font-family: var(--font-head);
  font-size: clamp(1.5rem, 3vw + 0.5rem, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-8);
}

/* Two-column layout on wider screens */
.calc-layout {
  display: flex;
  flex-direction: column;
  gap: var(--sp-8);
}
@media (min-width: 768px) {
  .calc-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: var(--sp-8);
  }
  .calc-form-col  { flex: 1 1 380px; }
  .calc-receipt-col {
    flex: 1 1 340px;
    /* Stick the receipt while the user scrolls the form */
    position: sticky;
    top: calc(var(--header-h) + var(--sp-6));
  }
}

/* ── 9. Form elements ── */
.settings-row {
  display: flex;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.field-currency { flex: 0 0 auto; }
.field-people   { flex: 1 1 140px; }

.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}

label {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.required-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--color-accent);
  color: var(--color-text);
  padding: 1px var(--sp-1);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Shared input styling */
input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 52px;
  padding: var(--sp-3) var(--sp-4);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  color: var(--color-text);
  font-size: 1rem;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  /* Remove browser spinner arrows — we use custom steppers */
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-text);
  box-shadow: var(--shadow-input);
}

/* Currency prefix inside input */
.input-wrap {
  position: relative;
}
.currency-prefix {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-muted);
  pointer-events: none;
  user-select: none;
  /* Prevent text wrapping */
  white-space: nowrap;
}
/* Pad the input so text doesn't overlap the prefix.
   Using 4ch covers up to 4-letter currency labels (e.g. "USD "). */
.input-wrap input {
  padding-left: calc(var(--sp-3) + 4ch + var(--sp-2));
}

/* Fieldset / legend reset */
.bills-fieldset {
  border: none;
  padding: 0;
}
.bills-fieldset legend {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: var(--sp-4);
  color: var(--color-text);
}

/* Small currency input */
#currency {
  width: 72px;
  min-height: 44px;
  text-align: center;
  font-weight: 700;
  padding-inline: var(--sp-2);
}

/* People stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}
.stepper-btn {
  width: 44px;
  height: 52px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  color: var(--color-text);
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.stepper-btn:hover,
.stepper-btn:focus-visible {
  background: var(--color-accent);
  border-color: var(--color-accent);
  transform: scale(1.08);
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}
#people {
  width: 60px;
  text-align: center;
  min-height: 52px;
  font-weight: 700;
  font-size: 1.1rem;
}

/* ── 10. RECEIPT CARD ── */

/*
  The "zig-zag torn bottom edge" uses an SVG-based clip or a
  CSS repeating linear-gradient as a mask on a pseudo-element.
  We use ::after with a repeating triangle pattern.
*/
.receipt-card {
  background: var(--color-receipt-bg);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  box-shadow: var(--shadow-card);
  padding: var(--sp-6);
  /* Extra bottom padding so text sits above the zig-zag */
  padding-bottom: var(--sp-10);
  position: relative;
  font-family: var(--font-mono);
  /* Overflow hidden so the pseudo ::after zig-zag stays clipped inside */
  overflow: visible; /* we want the zig-zag to hang below */
}

/* Zig-zag torn-paper bottom edge */
.receipt-card::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 0;
  right: 0;
  height: 18px;
  /* Repeating triangles pointing downward */
  background:
    linear-gradient(135deg, var(--color-receipt-bg) 33.33%, transparent 33.33%)  0    0,
    linear-gradient(225deg, var(--color-receipt-bg) 33.33%, transparent 33.33%) 50%   0;
  background-size: 16px 18px;
  background-repeat: repeat-x;
}

/* Small shadow under the zig-zag for depth */
.receipt-card::before {
  content: '';
  position: absolute;
  bottom: -28px;
  left: 4%;
  right: 4%;
  height: 16px;
  background: rgba(16, 42, 42, 0.07);
  border-radius: 0 0 50% 50%;
  filter: blur(8px);
  z-index: -1;
}

/* Placeholder before user types anything */
.receipt-placeholder {
  text-align: center;
  color: var(--color-muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding-block: var(--sp-8);
  line-height: 1.7;
}

/* Receipt header */
.receipt-header {
  text-align: center;
  margin-bottom: var(--sp-4);
}
.receipt-shop-name {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text);
}
.receipt-date {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: var(--sp-1);
}

/* Dashed dividers (classic receipt style) */
.receipt-divider {
  border: none;
  border-top: 2px dashed var(--color-receipt-dash);
  margin-block: var(--sp-4);
}

/* Line items */
.receipt-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.88rem;
  line-height: 1.8;
  gap: var(--sp-2);
}
.receipt-line .label {
  color: var(--color-muted);
  flex-shrink: 0;
}
.receipt-line .amount {
  font-weight: 700;
  color: var(--color-text);
  text-align: right;
}

/* The BIG total number — most prominent element */
.receipt-total-block {
  text-align: center;
  padding-block: var(--sp-4);
}
.receipt-per-person-label {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin-bottom: var(--sp-1);
}
.receipt-total-amount {
  font-family: var(--font-head);
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--color-text);
  line-height: 1;
  /* "pop" animation triggered via class from JS */
  transition: transform var(--dur-fast) var(--ease-out);
  display: inline-block;
}
/* The pop keyframe: triggered by adding .pop class in JS */
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.receipt-total-amount.pop {
  animation: pop var(--dur-mid) var(--ease-out) forwards;
}

.receipt-house-total {
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-top: var(--sp-2);
  text-align: center;
}

/* Rounding note */
.receipt-rounding-note {
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--color-muted);
  text-align: center;
  margin-top: var(--sp-2);
  font-style: italic;
}

/* "Copied" confirmation */
.copy-confirm {
  text-align: center;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
  margin-top: var(--sp-2);
  min-height: 1.4em; /* reserve space to avoid layout shift */
}

/* ── 11. HOW IT WORKS ── */
.hiw-section {
  padding-block: var(--sp-16);
  background: var(--color-white);
}

.hiw-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-8);
  counter-reset: step;
}

@media (min-width: 700px) {
  .hiw-steps {
    flex-direction: row;
    gap: var(--sp-6);
  }
  .hiw-step { flex: 1; }
}

.hiw-step {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.step-number {
  font-family: var(--font-head);
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--color-accent);
  /* Stroke technique: text + outline = bordered numeral */
  -webkit-text-stroke: 2px var(--color-text);
  text-stroke: 2px var(--color-text);
}

.step-body h3 {
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: var(--sp-2);
}
.step-body p {
  font-size: 0.95rem;
  color: var(--color-muted);
  line-height: 1.7;
}

/* ── 12. FOOTER ── */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding-block: var(--sp-8);
  background: var(--color-white);
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
}
.footer-brand {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 1rem;
}
.footer-note {
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* ── 13. HERO ENTRANCE ANIMATIONS ── */
/*
  Elements start hidden (opacity 0, shifted down).
  The .animate-hero-* classes apply delayed fade-up.
  No JS needed — pure CSS animation-fill-mode: both.
*/
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-hero-1,
.animate-hero-2,
.animate-hero-3 {
  animation: fadeUp var(--dur-slow) var(--ease-out) both;
}
.animate-hero-1 { animation-delay:  80ms; }
.animate-hero-2 { animation-delay: 200ms; }
.animate-hero-3 { animation-delay: 340ms; }

/* ── 14. SCROLL REVEAL (for How it works) ── */
/*
  .reveal elements start invisible; JS adds .revealed.
  If JS is off they are visible by default (no-js safety below).
*/
.reveal {
  opacity: 0;
  transform: translateY(32px);
  transition: opacity var(--dur-slow) var(--ease-out),
              transform var(--dur-slow) var(--ease-out);
}
.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}
/* Stagger via CSS custom property set by JS */
.reveal { transition-delay: var(--reveal-delay, 0ms); }

/* ── 15. FOCUS VISIBLE (global keyboard style) ── */
:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 3px;
  border-radius: 3px;
}

/* ── 16. REDUCED MOTION — turn everything off ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Make scroll-reveal items immediately visible */
  .reveal {
    opacity: 1;
    transform: none;
  }
}

/* ── 17. Utility: visually hidden (screen-reader only) ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
