:root {
    --paper: #ffffff;
    --paper-2: #f3f0ea;
    --ink: #29271f;
    --ink-soft: #6b6455;
    --vine: #2f5233;
    --vine-deep: #22381f;
    --kag-red: #ec2427;      /* Kagome brand red */
    --kag-red-deep: #c81619;
    --tomato: #ec2427;
    --tomato-deep: #c81619;
    --carrot: #e07a2c;
    --line: #e4e0d6;
    --card: #ffffff;
    --radius: 6px;
    --shadow: 0 24px 60px -30px rgba(41, 39, 31, .55);
    --font-display: "Raleway", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-body: "Raleway", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--paper);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

/* film grain overlay */
.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: .1;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E");
}

.trace {
    position: relative;
    z-index: 1;
    max-width: 1320px;
    margin: 0 auto;
    padding: clamp(28px, 6vw, 64px) clamp(20px, 5vw, 48px) 64px;
}

/* header */
.trace__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: clamp(28px, 6vw, 52px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}
.brand img {
    height: 34px;
    width: auto;
    display: block;
}
.brand__tag {
    font-size: .74rem;
    letter-spacing: .2em;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--kag-red);
    padding-left: 12px;
    border-left: 2px solid rgba(236,36,39,.35);
}

.au-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .04em;
    color: #fff;
    background: var(--kag-red);
    border: 1px solid var(--kag-red-deep);
    padding: 7px 13px;
    border-radius: 6px;
    box-shadow: 0 8px 18px -8px rgba(236,36,39,.7);
}
.au-badge svg { color: #fff; flex: 0 0 auto; }

/* hero banner */
.hero__banner {
    position: relative;
    min-height: clamp(250px, 30vw, 460px);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: clamp(24px, 5vw, 38px);
    animation: rise .7s cubic-bezier(.2,.7,.2,1) both;
}
.hero__banner img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 78% center; /* keep the Kagome crate in view */
}
.hero__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: clamp(20px, 4vw, 44px) clamp(20px, 5vw, 48px);
    background: linear-gradient(90deg, rgba(19,31,40,.7) 0%, rgba(19,31,40,.42) 46%, rgba(19,31,40,.05) 78%);
}
.hero__overlay-inner {
    max-width: 60%;
    animation: rise .7s .08s cubic-bezier(.2,.7,.2,1) both;
}
.hero__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.6rem, 5.4vw, 3.1rem);
    line-height: 1.04;
    letter-spacing: -.01em;
    color: #fff;
    text-shadow: 0 2px 18px rgba(0,0,0,.45);
}

.hero__lede {
    max-width: 42ch;
    font-size: clamp(.92rem, 1.8vw, 1.16rem);
    color: rgba(255,255,255,.94);
    margin: clamp(10px, 1.6vw, 16px) 0 0;
    text-shadow: 0 1px 10px rgba(0,0,0,.5);
}
.hero__lede strong { color: #fff; font-weight: 700; }

@media (max-width: 600px) {
    .hero__banner img { object-position: 60% center; }
    .hero__overlay {
        align-items: flex-end;
        background: linear-gradient(180deg, rgba(19,31,40,.12) 25%, rgba(19,31,40,.82) 100%);
    }
    .hero__overlay-inner { max-width: 100%; }
}

/* lookup form — fade-in only (no transform, so a fixed-position modal nested inside
   isn't trapped by a transformed containing block) */
.lookup { max-width: 760px; animation: fadein .7s .16s ease both; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.lookup__label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--vine);
    margin-bottom: 10px;
}
/* boxes on the left, Trace button on the right */
.lookup__row {
    display: flex;
    align-items: center;
    gap: 14px 12px;
    flex-wrap: wrap;
}
/* segmented (OTP-style) lot entry */
.otp {
    flex: 1 1 300px;
    display: flex;
    align-items: center;
    gap: clamp(4px, 1vw, 8px);
    flex-wrap: nowrap;
}
.otp__cell {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: 64px;
    text-align: center;
    font-family: var(--font-display);
    font-size: clamp(1.1rem, 3.4vw, 1.75rem);
    font-weight: 600;
    color: var(--ink);
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: 6px;
    padding: 0;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.otp__cell::placeholder { color: #cfc9bb; font-weight: 500; }
.otp__cell:focus {
    outline: none;
    border-color: var(--kag-red);
    box-shadow: 0 0 0 4px rgba(236,36,39,.16);
}
.otp__cell.is-filled { border-color: #b8b1a1; background: #fff; }
/* subtly group as YY · PP · NNNNNN */
.otp__cell:nth-child(2), .otp__cell:nth-child(4) { margin-right: clamp(6px, 1.6vw, 14px); }


.lookup__btn {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--kag-red);
    border: none;
    border-radius: 6px;
    padding: 0 26px;
    min-height: 62px;
    cursor: pointer;
    transition: transform .15s, background .2s, box-shadow .2s;
    box-shadow: 0 12px 26px -10px rgba(236,36,39,.75);
}
.lookup__btn:hover { background: var(--kag-red-deep); transform: translateY(-2px); }
.lookup__btn:active { transform: translateY(0); }
.lookup__btn:disabled { opacity: .7; cursor: progress; transform: none; }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    display: none;
    animation: spin .7s linear infinite;
}
.lookup__btn.is-loading .spinner { display: inline-block; }

.lookup__hint {
    font-size: .84rem;
    color: var(--ink-soft);
    margin: 12px 2px 0;
}

/* "where's my lot number" interactive helper */
.lothelp { position: relative; display: inline-block; margin-top: 16px; }
.lothelp__trigger {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    padding: 4px 2px;
    background: none;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.lothelp__thumb {
    width: auto;
    height: 44px;
    flex: 0 0 auto;
    border-radius: 4px;
    border: 1px solid var(--line);
    box-shadow: 0 3px 8px -3px rgba(0, 0, 0, .35);
    background: #fff;
    transition: transform .15s ease, box-shadow .15s ease;
}
.lothelp__trigger:hover .lothelp__thumb,
.lothelp__trigger:focus-visible .lothelp__thumb {
    transform: scale(1.08);
    box-shadow: 0 6px 14px -4px rgba(0, 0, 0, .4);
}
.lothelp__label { display: flex; flex-direction: column; line-height: 1.25; }
.lothelp__q { font-size: .92rem; font-weight: 700; color: var(--vine); }
.lothelp__hint { font-size: .8rem; color: var(--ink-soft); }
.lothelp__trigger:hover .lothelp__q,
.lothelp__trigger:focus-visible .lothelp__q { color: var(--kag-red); text-decoration: underline; }

/* dim backdrop behind the centred modal */
.lothelp__backdrop {
    position: fixed;
    inset: 0;
    z-index: 99998;   /* above Leaflet controls (~1000) and everything else */
    background: rgba(20, 18, 14, .45);
    opacity: 0;
    visibility: hidden;
    /* none on hover devices so the covering backdrop doesn't steal the trigger's
       :hover and cause an open/close flicker; tappable on touch to dismiss. */
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s;
}
@media (hover: none), (pointer: coarse) {
    .lothelp__backdrop { pointer-events: auto; }
}
.lothelp__backdrop.is-open { opacity: 1; visibility: visible; }

/* centred in the browser window */
.lothelp__pop {
    position: fixed;
    z-index: 99999;   /* top of the stack — above the backdrop and all page content */
    top: 50%;
    left: 50%;
    width: min(380px, 92vw);
    max-height: 88vh;
    overflow: auto;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 40px 90px -30px rgba(0, 0, 0, .6);
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -48%) scale(.96);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.lothelp__pop.is-open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}
.lothelp__close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: rgba(17, 15, 12, .55);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, transform .15s ease;
}
.lothelp__close:hover { background: rgba(17, 15, 12, .8); transform: scale(1.06); }
/* real product-label photo with an animated highlight over the lot number */
.labelshot { margin: 0; }
.labelshot__frame { position: relative; display: block; line-height: 0; }
.labelshot__img { display: block; width: 100%; height: auto; border-radius: 6px; }
.labelshot__hi {
    position: absolute;
    left: var(--hi-left, 21%);
    top: var(--hi-top, 92%);
    width: var(--hi-width, 52%);
    height: var(--hi-height, 6.5%);
    border: 3px solid #ec2427;
    border-radius: 6px;
    background: rgba(236, 36, 39, .12);
    box-shadow: 0 0 0 4px rgba(236, 36, 39, .12);
    pointer-events: none;
}
.lothelp__pop.is-open .labelshot__hi { animation: lotboxpulse 1.5s ease-in-out infinite; }
.labelshot__cap { margin: 10px 2px 0; font-size: .82rem; color: var(--ink-soft); text-align: center; }

@keyframes lotboxpulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(236, 36, 39, .12); background: rgba(236, 36, 39, .10); }
    50%      { box-shadow: 0 0 0 10px rgba(236, 36, 39, 0); background: rgba(236, 36, 39, .30); }
}

/* results */
.result { margin-top: clamp(30px, 6vw, 46px); }
.result[hidden] { display: none; }

.result__card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}

.result__banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
}
.result__banner--ok { background: rgba(47,82,51,.07); }
.result__banner--warn { background: rgba(224,122,44,.1); }
.result__banner--err { background: rgba(207,59,36,.1); }

.result__dot {
    width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
}
.result__banner--ok .result__dot { background: var(--vine); }
.result__banner--warn .result__dot { background: var(--carrot); }
.result__banner--err .result__dot { background: var(--tomato); }

.result__banner-title { font-weight: 600; font-size: 1rem; }
.result__banner-sub { color: var(--ink-soft); font-size: .86rem; }

/* crop identity badge */
.crop {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 18px 24px 0;
    padding: 16px 20px;
    border-radius: 6px;
    border: 1px solid var(--line);
    animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.crop__icon {
    font-size: 2.1rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,.15));
}
.crop__label {
    display: block;
    font-size: .72rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--ink-soft);
}
.crop__name {
    display: block;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.4rem, 4vw, 2rem);
    line-height: 1.05;
}
.crop--tomato { background: rgba(236,36,39,.08); border-color: rgba(236,36,39,.3); }
.crop--tomato .crop__name { color: var(--kag-red-deep); }
.crop--carrot { background: rgba(224,122,44,.1); border-color: rgba(224,122,44,.38); }
.crop--carrot .crop__name { color: #b9611c; }
.crop--other { background: rgba(47,82,51,.08); border-color: rgba(47,82,51,.28); }
.crop--other .crop__name { color: var(--vine); }

/* story stats */
.story {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 22px 24px 6px;
}
.story__stat {
    flex: 1 1 120px;
    background: var(--paper-2);
    border-radius: 5px;
    padding: 16px 18px;
}
.story__num {
    display: block;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(1.3rem, 4vw, 1.75rem);
    line-height: 1.05;
    color: var(--kag-red);
}
.story__lbl {
    display: block;
    margin-top: 4px;
    font-size: .78rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-soft);
}
.story__regions {
    margin: 4px 0 0;
    padding: 10px 24px 4px;
    font-size: 1.02rem;
    color: var(--ink);
}
.story__regions strong { color: var(--tomato-deep); }

/* region accordions */
.regions {
    display: grid;
    gap: 12px;
    padding: 18px 24px 28px;
}
.region {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.region__head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: none;
    border: 0;
    text-align: left;
    font-family: inherit;
    color: var(--ink);
    cursor: pointer;
    transition: background .2s;
}
.region__head:hover { background: rgba(47,82,51,.05); }
.region__pin { font-size: 1.15rem; flex: 0 0 auto; }
.region__id { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.region__name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.16rem;
    color: var(--vine-deep);
}
.region__sub { font-size: .84rem; color: var(--ink-soft); margin-top: 2px; }
.region__chev {
    width: 11px; height: 11px;
    border-right: 2px solid var(--ink-soft);
    border-bottom: 2px solid var(--ink-soft);
    transform: rotate(45deg);
    transition: transform .35s cubic-bezier(.3,.7,.2,1);
    flex: 0 0 auto;
    margin-top: -3px;
}
.region.is-open .region__chev { transform: rotate(225deg); margin-top: 3px; }

.region__panel {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .45s cubic-bezier(.3,.7,.2,1);
}
.region.is-open .region__panel { grid-template-rows: 1fr; }
.region__inner { overflow: hidden; }
.region__pad { padding: 2px 18px 20px; }

/* field map */
.fieldmap {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 5px;
    box-shadow: inset 0 0 0 1px var(--line);
}
.paddock {
    fill: var(--vine);
    fill-opacity: .16;
    stroke: var(--vine);
    stroke-width: 2.2;
    stroke-linejoin: round;
}
.paddock__lbl {
    fill: var(--vine-deep);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    text-anchor: middle;
    paint-order: stroke;
    stroke: var(--paper);
    stroke-width: 3px;
    stroke-linejoin: round;
    opacity: 0;
    pointer-events: none;
}
.region.is-open .paddock__lbl { animation: fadeIn .6s ease forwards; }
@keyframes fadeIn { to { opacity: 1; } }

.bin { opacity: 0; transform-box: fill-box; transform-origin: center; cursor: pointer; }
.region.is-open .bin { animation: binDrop .55s cubic-bezier(.3,1.5,.5,1) forwards; }
@keyframes binDrop {
    0%   { opacity: 0; transform: translateY(-16px) scale(.3); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.bin__dot { fill: var(--tomato); stroke: #fff; stroke-width: 2; transition: transform .15s; }
.bin:hover .bin__dot { transform: scale(1.35); }
.bin__pulse { fill: var(--tomato); transform-box: fill-box; transform-origin: center; }
.region.is-open .bin__pulse { animation: ping 2.6s ease-out infinite; animation-delay: 1.1s; }
@keyframes ping {
    0%        { transform: scale(.55); opacity: .5; }
    80%, 100% { transform: scale(3.4); opacity: 0; }
}
.compass text { font-family: var(--font-body); }

.maplegend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-top: 12px;
    font-size: .8rem;
    color: var(--ink-soft);
}
.lg { display: inline-flex; align-items: center; gap: 7px; }
.lg--bin::before {
    content: ""; width: 11px; height: 11px; border-radius: 50%;
    background: var(--tomato); box-shadow: 0 0 0 3px rgba(207,59,36,.2);
}
.lg--pad::before {
    content: ""; width: 14px; height: 11px; border-radius: 2px;
    border: 2px solid var(--vine); background: rgba(47,82,51,.16);
}
.mapcredit { margin-left: auto; font-size: .72rem; color: #a49e90; }

.padchips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.padchip {
    font-size: .82rem;
    color: var(--ink-soft);
    background: var(--paper-2);
    border-radius: 4px;
    padding: 6px 11px;
}
.padchip em { font-style: normal; font-weight: 600; color: var(--vine); }

.map-none { color: var(--ink-soft); font-size: .92rem; margin: 6px 0 0; }

/* leaflet tile map */
.regionmap { border-radius: 5px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.regionmap--live { height: clamp(400px, 46vw, 600px); }
.leaflet-container {
    background: #eaddc4; /* warm fallback if tiles don't load */
    font-family: var(--font-body);
    border-radius: 5px;
}
.leaflet-container a { color: var(--vine); }

/* paddock outline drawn onto tiles */
.paddock-l { filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

/* harvest bin marker (divIcon) */
/* Must stay absolute — Leaflet positions markers via translate3d on an
   absolutely-positioned icon. Overriding to relative makes pins drift on zoom. */
.binmarker { position: absolute; }
.bm__dot, .bm__ring {
    position: absolute; left: 50%; top: 50%;
    width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px;
    border-radius: 50%;
}
.bm__dot { background: var(--tomato); border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5); }
.bm__ring { background: var(--tomato); opacity: .5; animation: ping 2.6s ease-out infinite; }

.result__foot {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    font-size: .82rem;
    font-weight: 500;
    letter-spacing: .02em;
    color: #fff;
    background: var(--kag-red);
}
.result__logo { height: 26px; width: auto; display: block; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
    /* Map elements normally fade/draw in — show their final visible state instead. */
    .paddock { stroke-dashoffset: 0; fill-opacity: .16; }
    .paddock__lbl { opacity: 1; }
    .bin { opacity: 1; }
    .bin__pulse { display: none; }
}
