/* ==========================================================================
   HP3FREE — Coupon Code Generator
   Pure CSS. No frameworks, no build step.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
    --bg:            #080b14;
    --bg-soft:       #0d1220;
    --surface:       rgba(20, 26, 43, 0.72);
    --surface-solid: #141a2b;
    --surface-2:     rgba(255, 255, 255, 0.035);
    --surface-hover:  rgba(255, 255, 255, 0.06);

    --border:        rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text:          #eef1f8;
    --text-muted:    #98a2bd;
    --text-dim:      #6c7794;

    --accent:        #6d5efc;
    --accent-2:      #22d3ee;
    --accent-soft:   rgba(109, 94, 252, 0.15);
    --accent-glow:   rgba(109, 94, 252, 0.45);

    --success:       #34d399;
    --success-soft:  rgba(52, 211, 153, 0.14);
    --danger:        #fb7185;
    --danger-soft:   rgba(251, 113, 133, 0.13);

    --radius-sm:  10px;
    --radius:     14px;
    --radius-lg:  22px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow:    0 18px 40px -18px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 30px 70px -25px rgba(0, 0, 0, 0.85);

    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas,
                 "Liberation Mono", "Courier New", monospace;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

h1, h2, p, ul { margin: 0; }
ul { list-style: none; padding: 0; }

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    border: 0;
    background: none;
    -webkit-tap-highlight-color: transparent;
}

:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 3px;
    border-radius: 6px;
}

.visually-hidden {
    position: absolute !important;
    top: 0; left: 0;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: 0; left: 50%;
    transform: translate(-50%, -120%);
    z-index: 100;
    padding: 10px 18px;
    background: var(--accent);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    transition: transform 0.2s var(--ease);
}
.skip-link:focus { transform: translate(-50%, 0); }

/* --------------------------------------------------------------------------
   3. Background atmosphere
   -------------------------------------------------------------------------- */
.bg-glow {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(58rem 32rem at 50% -12%, rgba(109, 94, 252, 0.22), transparent 62%),
        radial-gradient(42rem 26rem at 92% 8%, rgba(34, 211, 238, 0.10), transparent 60%),
        radial-gradient(40rem 30rem at 4% 88%, rgba(109, 94, 252, 0.09), transparent 60%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
}

/* --------------------------------------------------------------------------
   4. Layout
   -------------------------------------------------------------------------- */
.page {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: clamp(24px, 5vw, 56px) clamp(16px, 4vw, 24px) 48px;
    padding-left: max(clamp(16px, 4vw, 24px), env(safe-area-inset-left));
    padding-right: max(clamp(16px, 4vw, 24px), env(safe-area-inset-right));
}

#main {
    display: flex;
    flex-direction: column;
    gap: clamp(16px, 3vw, 22px);
}

/* --------------------------------------------------------------------------
   5. Header
   -------------------------------------------------------------------------- */
.site-header {
    display: flex;
    justify-content: center;
    margin-bottom: clamp(22px, 5vw, 38px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    border-radius: 13px;
    background: linear-gradient(140deg, var(--accent) 0%, #8b5cf6 45%, var(--accent-2) 130%);
    box-shadow: 0 10px 26px -8px var(--accent-glow);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-size: clamp(1.15rem, 4.4vw, 1.55rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(95deg, #ffffff 10%, #c9c4ff 70%, var(--accent-2) 140%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-tagline {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

/* --------------------------------------------------------------------------
   6. Cards
   -------------------------------------------------------------------------- */
.card {
    position: relative;
    padding: clamp(20px, 4.5vw, 30px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

/* Hairline highlight along the top edge. */
.card::before {
    content: "";
    position: absolute;
    top: 0; left: 12%; right: 12%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
    pointer-events: none;
}

.card-title {
    font-size: clamp(1.15rem, 3.6vw, 1.35rem);
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text);
}

.card-desc {
    margin-top: 6px;
    font-size: 0.94rem;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   7. Form
   -------------------------------------------------------------------------- */
.generator-form {
    margin-top: 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Stacked by default (mobile first); becomes one row at >=560px. */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: block;
    min-width: 0;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
}

.select-wrap {
    position: relative;
    display: block;
}

.select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    min-height: 54px; /* matches .btn-generate so the row lines up */
    padding: 0 46px 0 16px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: border-color 0.18s var(--ease), background 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.select:hover { background: var(--surface-hover); border-color: rgba(255, 255, 255, 0.26); }
.select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}
/* Native dropdown list renders with OS colors — force readable options. */
.select option {
    background: var(--surface-solid);
    color: var(--text);
}

.select-arrow {
    position: absolute;
    top: 50%;
    right: 16px;
    width: 20px;
    height: 20px;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   8. Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 44px;
    padding: 11px 18px;
    border-radius: var(--radius);
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: transform 0.15s var(--ease), background 0.18s var(--ease),
                box-shadow 0.18s var(--ease), color 0.18s var(--ease),
                border-color 0.18s var(--ease);
}
.btn:active { transform: translateY(1px) scale(0.99); }

.btn-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.btn-generate {
    width: 100%;
    min-height: 54px;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #7c4ff5 55%, #5b8cf7 130%);
    color: #fff;
    box-shadow: 0 14px 30px -12px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-primary:hover {
    box-shadow: 0 18px 38px -12px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.24);
    filter: brightness(1.07);
}

.btn-ghost {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
}
.btn-ghost:hover {
    background: var(--surface-hover);
    border-color: rgba(255, 255, 255, 0.26);
}

.btn-danger { color: var(--danger); }
.btn-danger:hover {
    background: var(--danger-soft);
    border-color: rgba(251, 113, 133, 0.4);
}

/* Shared "copied" success state for Copy / Copy All. */
.btn.is-copied,
.btn.is-copied:hover {
    background: var(--success-soft);
    border-color: rgba(52, 211, 153, 0.45);
    color: var(--success);
    box-shadow: none;
    filter: none;
}

/* --------------------------------------------------------------------------
   9. Results header
   -------------------------------------------------------------------------- */
.results-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.results-count {
    margin-top: 4px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent-2);
}
.results-count:empty { display: none; }

.results-actions {
    display: flex;
    gap: 10px;
}
.results-actions[hidden] { display: none; }

/* --------------------------------------------------------------------------
   10. Empty state
   -------------------------------------------------------------------------- */
.empty-state {
    margin-top: 22px;
    padding: clamp(28px, 6vw, 42px) 20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}
.empty-state[hidden] { display: none; }

.empty-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    color: var(--text-dim);
    opacity: 0.85;
}
.empty-icon svg { width: 100%; height: 100%; }

.empty-title {
    font-size: 1rem;
    font-weight: 650;
    color: var(--text);
}

.empty-text {
    margin-top: 5px;
    font-size: 0.88rem;
    color: var(--text-dim);
}

/* --------------------------------------------------------------------------
   11. Code list
   -------------------------------------------------------------------------- */
/* Capped height so a 50-code batch scrolls inside the box instead of
   stretching the card down the page. Shows 5 rows; the vh term keeps the
   box inside the viewport on short screens. */
.code-list {
    margin-top: 22px;
    max-height: min(85vh, 309px); /* 5 rows @ ~61.3px + 1px borders */
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.018);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.code-list[hidden] { display: none; }

/* WebKit / Blink scrollbar — Firefox uses the scrollbar-* properties above. */
.code-list::-webkit-scrollbar { width: 10px; }
.code-list::-webkit-scrollbar-track { background: transparent; }
.code-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    background-clip: padding-box;
    border: 3px solid transparent;
    border-radius: 999px;
}
.code-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.32);
    background-clip: padding-box;
}

.code-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 10px 10px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.16s var(--ease);
    animation: row-in 0.32s var(--ease) both;
}
.code-row:last-child { border-bottom: 0; }
.code-row:hover { background: rgba(255, 255, 255, 0.045); }

@keyframes row-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.code-index {
    flex: 0 0 auto;
    min-width: 26px;
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    user-select: none;
}

.code-value {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    margin: 0;
    text-align: left;
    background: transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: clamp(0.86rem, 3.4vw, 0.98rem);
    font-weight: 600;
    letter-spacing: 0.045em;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.16s var(--ease), color 0.16s var(--ease);
}
.code-value:hover { background: var(--accent-soft); color: #fff; }

.code-row.is-copied { background: var(--success-soft); }
.code-row.is-copied .code-value { color: var(--success); }

.btn-copy {
    flex: 0 0 auto;
    min-width: 84px;
    min-height: 38px;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: background 0.16s var(--ease), color 0.16s var(--ease),
                border-color 0.16s var(--ease), transform 0.14s var(--ease);
}
.btn-copy:hover {
    background: var(--accent-soft);
    border-color: rgba(109, 94, 252, 0.55);
    color: #fff;
}
.btn-copy:active { transform: scale(0.96); }
.btn-copy.is-copied,
.btn-copy.is-copied:hover {
    background: var(--success-soft);
    border-color: rgba(52, 211, 153, 0.45);
    color: var(--success);
}

/* --------------------------------------------------------------------------
   11b. Live stats
   -------------------------------------------------------------------------- */
.card-stats {
    padding: clamp(16px, 3.5vw, 22px) clamp(16px, 4vw, 26px);
}

.stats-title {
    margin-bottom: 14px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 10px;
    text-align: center;
    background: rgba(255, 255, 255, 0.028);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: clamp(1.15rem, 4vw, 1.45rem);
    font-weight: 750;
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.stat-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.015em;
    color: var(--text-dim);
}

/* Pulsing dot on the "Online Now" tile. */
.stat-dot {
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
    animation: pulse 2.2s ease-out infinite;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
    70%  { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* Brief highlight when a number changes. */
.stat-value.is-bumped {
    color: var(--accent-2);
    transition: color 0.2s var(--ease);
}

/* --------------------------------------------------------------------------
   12. Footer
   -------------------------------------------------------------------------- */
.site-footer {
    margin-top: 8px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-dim);
}

/* --------------------------------------------------------------------------
   13. Toasts
   -------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    z-index: 90;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    padding: 12px 18px;
    background: rgba(24, 31, 51, 0.94);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    animation: toast-in 0.28s var(--ease) both;
}
.toast.is-leaving { animation: toast-out 0.24s var(--ease) both; }

.toast-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px var(--success-soft);
}
.toast-error .toast-dot {
    background: var(--danger);
    box-shadow: 0 0 0 4px var(--danger-soft);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(10px) scale(0.97); }
}

/* --------------------------------------------------------------------------
   14. Responsive
   -------------------------------------------------------------------------- */
/* Quantity + Generate share one line once there is room for both:
   select on the left, button filling the remaining width on the right. */
@media (min-width: 560px) {
    .form-row {
        flex-direction: row;
        align-items: flex-end;
        gap: 14px;
    }
    .form-row .field {
        flex: 0 0 clamp(140px, 30%, 200px);
    }
    .form-row .btn-generate {
        flex: 1 1 auto;
        width: auto;
    }
}

@media (max-width: 560px) {
    /* Four tiles across is too tight on phones — go 2x2. */
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .brand-mark { width: 42px; height: 42px; border-radius: 12px; }

    .results-head { flex-direction: column; align-items: stretch; }
    .results-actions { width: 100%; }
    .results-actions .btn { flex: 1 1 0; }

    .code-row { padding: 9px 8px 9px 10px; gap: 8px; }
    .code-index { display: none; }
    .code-value { padding: 8px 6px; letter-spacing: 0.03em; }
    .btn-copy { min-width: 72px; padding: 8px 10px; }
}

@media (max-width: 340px) {
    .btn-copy { min-width: 64px; font-size: 0.76rem; }
}

/* --------------------------------------------------------------------------
   15. Preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

@media print {
    .bg-glow, .card-generator, .results-actions, .toast-container, .site-footer { display: none !important; }
    body { background: #fff; color: #000; }
    .card { box-shadow: none; border-color: #ccc; backdrop-filter: none; }
}
