:root {
    --brand: #0654ba;
    --brand-dark: #0a3d8f;
    --accent: #e53238;
    --bg: #f3f5f9;
    --card: #ffffff;
    --text: #1a1a2e;
    --muted: #6b7280;
    --border: #e5e7eb;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(6, 84, 186, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
    background: radial-gradient(1200px 600px at 50% -10%, #e8efff 0%, var(--bg) 55%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

header.site-header {
    text-align: center;
    padding: 26px 20px 6px;
}

header.site-header h1 {
    font-size: clamp(26px, 5.5vw, 42px);
    margin: 0 0 8px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

header.site-header h1 a { color: inherit; text-decoration: none; }
header.site-header .accent { color: var(--brand); }

header.site-header .tagline {
    color: var(--muted);
    font-size: clamp(15px, 3vw, 18px);
    margin: 0 auto;
    max-width: 560px;
    line-height: 1.5;
}

.breadcrumb {
    max-width: 620px;
    margin: 12px auto 0;
    padding: 0 16px;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
}

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

/* First screen fills the viewport: header on top, card fills the middle,
   fetch button pinned at the bottom. SEO content lives below in .page-content. */
.app-shell {
    position: relative;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    width: 100%;
    padding: 8px 16px;
}

.page-content { width: 100%; }

/* ---- Filter toolbar (top-right icon buttons + popovers) ---- */
.toolbar {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    gap: 8px;
    z-index: 30;
}

.tool-btn {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s ease;
}

.tool-btn:hover { border-color: var(--brand); color: var(--brand); }
.tool-btn[aria-expanded="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

.tool-btn .dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 11px;
    height: 11px;
    background: var(--accent);
    border: 2px solid #fff;
    border-radius: 50%;
    display: none;
}

.tool-btn .dot.show { display: block; }

.panel {
    position: absolute;
    top: 64px;
    right: 14px;
    width: min(320px, calc(100vw - 28px));
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 14px;
    z-index: 30;
    display: none;
}

.panel.open { display: block; }

.panel .search-row { display: flex; gap: 8px; }

.panel .search-row input {
    flex: 1;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
}

.panel .search-row input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.market-heading { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--muted); }
.market-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 240px; overflow-y: auto; }
.market-list .chip { display: inline-flex; align-items: center; gap: 6px; }

.chip {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
}

.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.price-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}

.price-inputs input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
}

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-bottom: 12px;
    min-height: 0;
}

.filter-pill {
    background: #eaf1ff;
    color: var(--brand-dark);
    border: none;
    padding: 6px 10px 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.filter-pill::after { content: "✕"; font-size: 10px; opacity: 0.7; }

/* ---- Item card ---- */
.card {
    background: var(--card);
    width: 100%;
    max-width: min(460px, calc(100vw - 32px));
    flex: 1 0 auto;
    min-height: 0;
    min-width: 0;
    margin: 8px 0;
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.card.loading { opacity: 0.55; pointer-events: none; }

#randomItem {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    margin: 0 0 14px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 1.4em;
    width: 100%;
}

.image-container {
    width: 100%;
    flex: 1 1 auto;
    min-height: 120px;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fafbfc;
    border-radius: 12px;
    margin-bottom: 14px;
    position: relative;
}

#randomItemImage {
    max-height: 100%;
    max-width: 100%;
    border-radius: 12px;
    display: none;
}

.spinner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.card.loading .spinner { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    width: 100%;
    margin-bottom: 8px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-condition { background: #eef2ff; color: #3730a3; }
.badge-toprated { background: #e7f7ec; color: #138a4e; }
.badge-auction { background: #fff3e0; color: #b25e00; }

#price {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
}

#shipping {
    margin: 4px 0 2px;
    font-size: 14px;
    color: var(--muted);
}

.meta-line {
    margin: 2px 0 14px;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
}

.box-icon { margin-right: 6px; }

.buy-now-btn {
    width: 100%;
    background: var(--brand);
    border: none;
    color: #fff;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.15s ease, transform 0.05s ease;
}

.buy-now-btn:hover { background: var(--brand-dark); }
.buy-now-btn:active { transform: scale(0.98); }

.desc {
    margin: 14px 0 0;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
    text-align: left;
    width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.seller-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
}

#sellerUsername { font-weight: 600; color: var(--text); }
.score-wrapper { text-align: right; }
.score-container { display: inline-flex; align-items: center; gap: 4px; }
.star-icon { color: #f5b50a; }

#error {
    display: none;
    color: var(--accent);
    text-align: center;
    font-size: 14px;
    margin-top: 12px;
    width: 100%;
}

.fetch-bar {
    display: flex;
    justify-content: center;
    flex: 0 0 auto;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
}

#fetchButton {
    background: var(--text);
    border: none;
    color: #fff;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    border-radius: 999px;
    transition: transform 0.05s ease, opacity 0.15s ease;
    box-shadow: var(--shadow);
}

#fetchButton:hover { opacity: 0.92; }
#fetchButton:active { transform: scale(0.97); }
#fetchButton:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Content sections ---- */
.about, .category-section {
    max-width: 720px;
    margin: 40px auto 0;
    padding: 0 20px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.about { text-align: center; }

.about h2, .category-section h2 {
    color: var(--text);
    font-size: 18px;
    margin-bottom: 8px;
}

.faq-heading { margin-top: 32px; }

.faq { text-align: left; margin: 16px 0 0; }
.faq dt { font-weight: 700; color: var(--text); margin-top: 16px; }
.faq dd { margin: 6px 0 0; color: var(--muted); }

/* ---- Category grid (hub + related links) ---- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    margin: 16px 0 0;
}

.category-grid a {
    display: block;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    transition: all 0.12s ease;
}

.category-grid a:hover {
    border-color: var(--brand);
    color: var(--brand);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.home-guides-heading { margin: 22px 0 0; font-size: 15px; color: var(--muted); font-weight: 700; }

/* ---- Featured live listings (server-rendered product samples) ---- */
.featured-section { max-width: 960px; margin: 44px auto 0; padding: 0 20px; }
.featured-section h2 { color: var(--text); font-size: 18px; margin-bottom: 4px; }
.featured-sub { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 18px; }

.featured-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.product-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    transition: all 0.12s ease;
}

.product-card:hover {
    border-color: var(--brand);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.product-card .thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #f3f5f9;
}

.product-card .product-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-card .product-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card .product-price { font-size: 14px; font-weight: 700; color: var(--brand); }
.product-card .product-cond { font-size: 11px; color: var(--muted); }

.featured-disclaimer { color: var(--muted); font-size: 12px; margin: 16px 0 0; text-align: center; }

footer {
    text-align: center;
    padding: 28px 20px;
    font-size: 13px;
    color: var(--muted);
}

footer a { color: var(--muted); }

.lang-switcher {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    justify-content: center;
    font-size: 12px;
}
.lang-switcher a { color: var(--muted); text-decoration: none; }
.lang-switcher a:hover { color: var(--brand); }
.lang-switcher .lang-current { color: var(--text); font-weight: 700; }
