/* ===========================================================================
   Retro Rationing -- ration-book styling
   Palette and type are taken from the project brief: coral/salmon ration-book
   pink, dark brown period ink, Georgia serif. The signature element is the
   coupon counter, treated like a stamped page torn from a real ration book.
   =========================================================================== */

:root {
    --pink:        #E8A298;   /* ration-book cover / screen background */
    --coral:       #D4918A;   /* cards and secondary surfaces */
    --coral-deep:  #C77F77;   /* pressed / hover on coral */
    --brown:       #2F1B14;   /* ink, borders, primary buttons */
    --brown-dark:  #1A0F0B;   /* button hover */
    --cream:       #F5F1E4;   /* text on dark surfaces */
    --stamp-red:   #9E2B25;   /* coupon counter, official stamp */
    --ink-faded:   rgba(47, 27, 20, 0.68);
    --hairline:    rgba(47, 27, 20, 0.22);

    --serif: Georgia, "Times New Roman", "Nimbus Roman", serif;
    --shadow-card: 0 2px 0 rgba(47, 27, 20, 0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--serif);
    color: var(--brown);
    background-color: var(--pink);
    /* faint woven-paper texture */
    background-image: repeating-linear-gradient(
        45deg, transparent, transparent 3px,
        rgba(47, 27, 20, 0.035) 3px, rgba(47, 27, 20, 0.035) 4px);
    min-height: 100vh;
    line-height: 1.5;
}

.boot {
    text-align: center;
    padding: 40vh 20px;
    font-style: italic;
    color: var(--ink-faded);
}

/* The whole app lives in a phone-width column, like a held ration book. */
.shell {
    max-width: 460px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--pink);
    box-shadow: 0 0 40px rgba(47, 27, 20, 0.18);
}

/* --------------------------------------------------------------------------- */
/* Top bar                                                                      */
/* --------------------------------------------------------------------------- */
.topbar {
    background: var(--brown);
    color: var(--cream);
    padding: 16px 18px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 3px double rgba(245, 241, 228, 0.4);
}
.topbar h1 {
    font-size: 1.15rem;
    font-weight: bold;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.topbar .pill {
    background: var(--stamp-red);
    color: var(--cream);
    font-size: 0.8rem;
    font-weight: bold;
    padding: 5px 11px;
    border-radius: 2px;
    border: 1px solid rgba(245, 241, 228, 0.5);
    letter-spacing: 0.03em;
}

/* --------------------------------------------------------------------------- */
/* Scrolling content area                                                       */
/* --------------------------------------------------------------------------- */
.view {
    flex: 1;
    padding: 20px 18px 110px;
    overflow-y: auto;
}
.view h2 {
    font-size: 1.45rem;
    margin-bottom: 4px;
    text-shadow: 1px 1px 0 rgba(245, 241, 228, 0.35);
}
.view .subtitle {
    color: var(--ink-faded);
    font-style: italic;
    margin-bottom: 18px;
}
.section-label {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.72rem;
    font-weight: bold;
    color: var(--ink-faded);
    margin: 22px 0 10px;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 5px;
}

/* --------------------------------------------------------------------------- */
/* The coupon counter -- signature element                                      */
/* --------------------------------------------------------------------------- */
.counter {
    background: var(--stamp-red);
    color: var(--cream);
    border-radius: 4px;
    padding: 22px 20px 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(245, 241, 228, 0.25),
                inset 0 0 22px rgba(0, 0, 0, 0.28);
    border: 2px solid var(--brown);
}
/* perforated edge along the top, like a tear-off coupon */
.counter::before {
    content: "";
    position: absolute;
    top: 8px; left: 0; right: 0;
    height: 6px;
    background-image: radial-gradient(circle, var(--pink) 2.5px, transparent 3px);
    background-size: 14px 6px;
    background-position: center;
    opacity: 0.5;
}
.counter .stamp {
    position: absolute;
    top: 12px; right: 10px;
    transform: rotate(-11deg);
    border: 2px solid rgba(245, 241, 228, 0.65);
    border-radius: 3px;
    padding: 2px 7px;
    font-size: 0.6rem;
    font-weight: bold;
    letter-spacing: 0.12em;
    color: rgba(245, 241, 228, 0.78);
}
.counter .big {
    font-size: 3.6rem;
    font-weight: bold;
    line-height: 1;
    display: block;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}
.counter .big-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-top: 4px;
    opacity: 0.9;
}
.counter .progress {
    background: rgba(0, 0, 0, 0.28);
    height: 14px;
    border-radius: 2px;
    margin: 16px 0 8px;
    overflow: hidden;
    border: 1px solid rgba(245, 241, 228, 0.35);
}
.counter .progress span {
    display: block;
    height: 100%;
    background: var(--cream);
    transition: width 0.5s ease;
}
.counter .meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.76rem;
    opacity: 0.92;
}

/* --------------------------------------------------------------------------- */
/* Cards, lists, facts                                                          */
/* --------------------------------------------------------------------------- */
.card {
    background: var(--coral);
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    padding: 14px 15px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-card);
}
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.row .lead { font-weight: bold; }
.row .sub  { font-size: 0.78rem; color: var(--ink-faded); }

.fact {
    background: var(--coral);
    border-left: 5px solid var(--brown);
    border-radius: 0 4px 4px 0;
    padding: 14px 15px;
    box-shadow: var(--shadow-card);
}
.fact .when {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--stamp-red);
    font-weight: bold;
}
.fact h3 { margin: 4px 0 6px; font-size: 1.05rem; }
.fact p  { font-style: italic; font-size: 0.92rem; }

.coupon-badge {
    background: var(--brown);
    color: var(--cream);
    padding: 3px 10px;
    border-radius: 2px;
    font-size: 0.82rem;
    font-weight: bold;
    min-width: 34px;
    text-align: center;
    flex-shrink: 0;
}
.varies-tag {
    display: inline-block;
    font-size: 0.68rem;
    color: var(--stamp-red);
    font-style: italic;
    margin-top: 2px;
}

/* quick action grid on the dashboard */
.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}
.actions button {
    font-family: var(--serif);
    background: var(--coral);
    color: var(--brown);
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    padding: 16px 10px;
    font-size: 0.92rem;
    cursor: pointer;
    box-shadow: var(--shadow-card);
    transition: background 0.15s ease, transform 0.05s ease;
}
.actions button:hover { background: var(--coral-deep); }
.actions button:active { transform: translateY(1px); }

/* --------------------------------------------------------------------------- */
/* Buttons & form controls                                                      */
/* --------------------------------------------------------------------------- */
.btn {
    font-family: var(--serif);
    width: 100%;
    background: var(--brown);
    color: var(--cream);
    border: none;
    border-radius: 4px;
    padding: 15px;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--brown-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
    background: var(--coral);
    color: var(--brown);
    border: 1.5px solid var(--brown);
}
.btn.danger { background: var(--stamp-red); }
.btn-small { width: auto; padding: 9px 14px; font-size: 0.85rem; }

label.field { display: block; margin: 14px 0 6px; font-weight: bold; font-size: 0.9rem; }
input.text {
    font-family: var(--serif);
    width: 100%;
    padding: 13px;
    font-size: 1rem;
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    background: var(--cream);
    color: var(--brown);
}
input.text:focus { outline: 3px solid var(--stamp-red); outline-offset: 1px; }

/* segmented choices (adult/child, male/female, new/second-hand) */
.choices { display: flex; gap: 10px; }
.choices.stack { flex-direction: column; }
.choice {
    flex: 1;
    text-align: center;
    background: var(--coral);
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    padding: 13px 10px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.15s ease, color 0.15s ease;
    user-select: none;
}
.choice:hover { background: var(--coral-deep); }
.choice.selected { background: var(--brown); color: var(--cream); }
.choice .choice-sub { display: block; font-size: 0.74rem; opacity: 0.85; margin-top: 3px; }
.choice.block { text-align: left; }

/* --------------------------------------------------------------------------- */
/* Category accordion (Add Purchase)                                            */
/* --------------------------------------------------------------------------- */
.accordion { border: 1.5px solid var(--brown); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.acc-group + .acc-group { border-top: 1.5px solid var(--brown); }
.acc-head {
    background: var(--brown);
    color: var(--cream);
    padding: 13px 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.acc-head .chev { transition: transform 0.2s ease; }
.acc-group.open .acc-head .chev { transform: rotate(90deg); }
.acc-body { display: none; background: var(--pink); }
.acc-group.open .acc-body { display: block; }
.item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--hairline);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.item:last-child { border-bottom: none; }
.item:hover { background: var(--coral); }
.item .item-main { display: flex; flex-direction: column; }

/* --------------------------------------------------------------------------- */
/* Bottom navigation                                                            */
/* --------------------------------------------------------------------------- */
.nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-width: 460px;
    margin: 0 auto;
    background: var(--brown);
    display: flex;
    border-top: 3px double rgba(245, 241, 228, 0.4);
    z-index: 20;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav button {
    flex: 1;
    background: none;
    border: none;
    color: rgba(245, 241, 228, 0.62);
    font-family: var(--serif);
    padding: 11px 4px 10px;
    cursor: pointer;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
}
.nav button .ico { display: block; font-size: 1.25rem; margin-bottom: 2px; }
.nav button.active { color: var(--cream); }

/* --------------------------------------------------------------------------- */
/* Auth & onboarding (centred, no nav)                                          */
/* --------------------------------------------------------------------------- */
.gate {
    max-width: 460px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 22px;
}
.crest {
    width: 72px; height: 72px;
    margin: 0 auto 14px;
    background: var(--brown);
    color: var(--cream);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    border: 3px double rgba(245, 241, 228, 0.5);
}
.gate h2 { text-align: center; font-size: 1.7rem; }
.gate .subtitle { text-align: center; }
.tabs { display: flex; margin: 18px 0 6px; border: 1.5px solid var(--brown); border-radius: 4px; overflow: hidden; }
.tabs button {
    flex: 1; padding: 12px; border: none; cursor: pointer;
    font-family: var(--serif); font-size: 0.95rem; font-weight: bold;
    background: var(--coral); color: var(--brown);
}
.tabs button.active { background: var(--brown); color: var(--cream); }

/* "(optional)" marker on a field label, and the small helper line under it */
.field-opt { font-weight: normal; color: var(--ink-faded); font-size: 0.85em; }
.field-hint { margin: 6px 0 0; font-size: 0.82rem; color: var(--ink-faded); }

/* text link styled as a button (e.g. "Forgotten your details?") */
.linkbtn {
    display: block;
    width: 100%;
    margin: 14px 0 0;
    background: none;
    border: none;
    color: var(--brown);
    font-family: var(--serif);
    font-size: 0.92rem;
    text-decoration: underline;
    cursor: pointer;
}
.linkbtn:hover { color: var(--stamp-red); }

/* checkbox + label row used in the email-safety confirmation popup */
.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 14px 0 4px;
    font-size: 0.9rem;
    line-height: 1.45;
    cursor: pointer;
}
.check input[type="checkbox"] {
    width: 20px; height: 20px;
    margin-top: 1px;
    flex-shrink: 0;
    accent-color: var(--stamp-red);
    cursor: pointer;
}

/* --------------------------------------------------------------------------- */
/* Messages: errors, empties, toast                                             */
/* --------------------------------------------------------------------------- */
.error {
    background: var(--stamp-red);
    color: var(--cream);
    padding: 11px 13px;
    border-radius: 4px;
    margin: 12px 0;
    font-size: 0.9rem;
}
.empty {
    text-align: center;
    color: var(--ink-faded);
    font-style: italic;
    padding: 30px 16px;
    border: 1.5px dashed var(--hairline);
    border-radius: 4px;
}
.toast {
    position: fixed;
    left: 50%; bottom: 84px;
    transform: translateX(-50%) translateY(20px);
    background: var(--brown);
    color: var(--cream);
    padding: 12px 20px;
    border-radius: 4px;
    border: 1px solid rgba(245, 241, 228, 0.4);
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 50;
    max-width: 90%;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------------------------- */
/* Modal sheet (override / confirm)                                             */
/* --------------------------------------------------------------------------- */
.scrim {
    position: fixed; inset: 0;
    background: rgba(26, 15, 11, 0.6);
    display: flex; align-items: flex-start; justify-content: center;
    z-index: 40;
    overflow-y: auto;                 /* tall sheets scroll within the scrim */
    overscroll-behavior: contain;     /* don't transfer scroll to the page behind */
    -webkit-overflow-scrolling: touch;/* momentum scrolling on iOS */
    /* keep the sheet clear of the address bar / notch at the top and
       leave a little breathing room at the bottom */
    padding: calc(24px + env(safe-area-inset-top, 0)) 0
             calc(24px + env(safe-area-inset-bottom, 0));
}
.sheet {
    background: var(--pink);
    width: 100%;
    max-width: 460px;
    overflow-y: auto;                 /* belt-and-braces; scrim usually scrolls */
    border-radius: 12px;
    border: 3px solid var(--brown);
    padding: 20px 18px;
    box-shadow: 0 6px 24px rgba(26, 15, 11, 0.4);
}
.sheet h3 { font-size: 1.2rem; margin-bottom: 2px; }
.sheet .live-cost {
    text-align: center;
    margin: 16px 0;
    font-size: 0.85rem;
    color: var(--ink-faded);
}
.sheet .live-cost b { font-size: 2rem; color: var(--brown); display: block; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.stat {
    background: var(--coral);
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    padding: 12px 6px;
    text-align: center;
    box-shadow: var(--shadow-card);
}
.stat b { display: block; font-size: 1.6rem; }
.stat span { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faded); }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* --------------------------------------------------------------------------- */
/* Achievements + over-spend note (repairs / achievements build)                */
/* --------------------------------------------------------------------------- */
.ach { margin-bottom: 10px; }
.ach .lead { font-size: 1rem; }
.ach-off { opacity: 0.6; border-style: dashed; }
.ach-on  { box-shadow: var(--shadow-card), inset 0 0 0 2px rgba(47, 27, 20, 0.18); }
.ach-bar {
    background: rgba(47, 27, 20, 0.18);
    height: 10px;
    border-radius: 2px;
    margin: 10px 0 4px;
    overflow: hidden;
    border: 1px solid var(--hairline);
}
.ach-bar span {
    display: block;
    height: 100%;
    background: var(--brown);
    transition: width 0.4s ease;
}
.ach-count {
    font-size: 0.72rem;
    color: var(--ink-faded);
    text-align: right;
}

/* the gentle over-ration nudge in the add-purchase sheet */
.overspend-note {
    background: var(--coral);
    border-left: 5px solid var(--stamp-red);
    border-radius: 0 4px 4px 0;
    padding: 13px 15px;
    margin: 8px 0 16px;
    font-style: italic;
}

/* data-export privacy notice: an official-looking aside, not a warning */
.privacy-note {
    background: var(--cream);
    border: 1.5px solid var(--brown);
    border-left: 5px solid var(--brown);
    border-radius: 0 4px 4px 0;
    padding: 13px 15px;
    margin: 8px 0 4px;
    font-size: 0.9rem;
    color: var(--ink-faded);
}

/* selects reuse the .text input styling */
/* selects: coral background + brown text, in keeping with the ration-book
   palette (matching the difficulty/choice boxes), with a custom chevron since
   appearance:none removes the native arrow */
select.text {
    font-family: var(--serif);
    width: 100%;
    padding: 13px 40px 13px 13px;     /* room on the right for the chevron */
    font-size: 1rem;
    border: 1.5px solid var(--brown);
    border-radius: 4px;
    color: var(--brown);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--coral);
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232F1B14' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px 14px;
}
select.text:focus { outline: 3px solid var(--stamp-red); outline-offset: 1px; }

/* --------------------------------------------------------------------------- */
/* Year in Review (Wrapped) + past years (ration-year build)                    */
/* --------------------------------------------------------------------------- */
.review {
    max-width: 460px;
    margin: 0 auto;
    min-height: 100vh;
    padding: 28px 22px 40px;
}
.review.flush { min-height: 0; padding: 6px 0 24px; }
.review h2, .review .subtitle { text-align: center; }

/* coral stat cards, matching the original mockup */
.summary-card {
    background: var(--coral);
    border: 2px solid var(--brown);
    border-radius: 12px;
    padding: 15px;
    margin: 10px 0;
    text-align: center;
    box-shadow: var(--shadow-card);
}
.summary-stat {
    font-size: 2rem;
    font-weight: bold;
    color: var(--brown);
    display: block;
    line-height: 1.1;
}
.summary-label { font-size: 0.9rem; color: var(--brown); margin-top: 5px; }
.summary-label small { color: var(--ink-faded); }

.badge-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.badge-chip {
    background: var(--cream);
    border: 1.5px solid var(--brown);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--brown);
}

.historical-note {
    background: var(--brown);
    color: var(--cream);
    border-radius: 10px;
    padding: 14px 16px;
    margin-top: 16px;
    text-align: center;
    font-style: italic;
}

/* rows that drill into a detail screen */
.card.tappable { cursor: pointer; }
.card.tappable .chev { color: var(--ink-faded); }

/* --------------------------------------------------------------------------- */
/* Achievement celebration ("stamp")                                            */
/* --------------------------------------------------------------------------- */
.ach-scrim {
    position: fixed; inset: 0;
    background: rgba(26, 15, 11, 0.62);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    z-index: 60;                 /* above sheets (40) and the nav */
    opacity: 0;
    transition: opacity 0.25s ease;
    cursor: pointer;
}
.ach-scrim.show { opacity: 1; }

.ach-stamp {
    background: var(--cream);
    border: 2px solid var(--brown);
    border-radius: 8px;
    padding: 26px 28px 20px;
    width: 100%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 10px 0 rgba(47, 27, 20, 0.22);
    transform: scale(1.6) rotate(-9deg);
    opacity: 0;
}
.ach-scrim.show .ach-stamp {
    animation: stamp-in 0.5s cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
}
@keyframes stamp-in {
    0%   { transform: scale(1.6) rotate(-9deg);  opacity: 0; }
    60%  { transform: scale(0.92) rotate(-1.5deg); opacity: 1; }
    100% { transform: scale(1) rotate(-2.5deg);  opacity: 1; }
}

.ach-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-weight: bold;
    color: var(--stamp-red);
    margin-bottom: 12px;
}
.ach-medal {
    width: 96px; height: 96px;
    margin: 0 auto 14px;
    border: 3px double var(--stamp-red);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem;
    background: rgba(158, 43, 37, 0.06);
    transform: rotate(3deg);
}
.ach-name {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--brown);
    line-height: 1.15;
    margin-bottom: 12px;
}
.ach-seal {
    font-size: 0.74rem;
    font-style: italic;
    color: var(--ink-faded);
    border-top: 1px solid var(--hairline);
    padding-top: 12px;
}
