/* ============================================
   Tip the Yen — "Gilded Sunburst" Design System
   Inspired by Stitch's Vintage Instrumentalism
   ============================================ */

:root {
    /* Gilded Sunburst Palette */
    --primary: #eead2b;
    --primary-glow: #ffcc77;
    --primary-deep: #c89020;
    --bg-dark: #181307;
    --bg-surface: #221c10;
    --surface-container: #251f13;
    --surface-container-high: #30291c;
    --surface-container-highest: #3b3426;
    --tobacco-mid: #8b4513;
    --tobacco-edge: #4a2c0a;
    --ivory: #eee1cd;
    --ivory-soft: rgba(238, 225, 205, 0.85);
    --ivory-muted: rgba(238, 225, 205, 0.55);

    /* Semantic Mappings */
    --color-text-main: var(--ivory);
    --color-text-muted: var(--ivory-muted);
    --color-accent: var(--primary);

    /* Glass Surfaces */
    --glass-bg: rgba(24, 19, 7, 0.72);
    --glass-border: rgba(238, 173, 43, 0.12);
    --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    --glass-highlight: inset 0 1px 0 rgba(255, 220, 140, 0.15);

    /* Ambient Shadows — amber-tinted, never cold gray */
    --shadow-ambient: 0 20px 50px rgba(66, 44, 0, 0.08);
    --shadow-glow: 0 0 40px rgba(238, 173, 43, 0.12);

    /* Fonts — Newsreader for display, Inter for UI */
    --font-display: 'Outfit', sans-serif;
    --font-ui: 'Inter', sans-serif;
    --font-icon: 'Material Symbols Outlined';

    /* Spacing Scale */
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #000;
    color: var(--color-text-main);
    font-family: var(--font-display);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
}

/* Background: Cracked lacquer texture — warm and textured */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url('assets/cracked_lacquer_bg.png');
    background-size: cover;
    background-position: center;
    filter: brightness(1.2) saturate(1.1) blur(1.5px);
    z-index: -3;
}

/* Background Layer 2: Sunburst vignette — warm amber center, tobacco edges */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(
        ellipse at center,
        rgba(238, 173, 43, 0.08) 0%,
        rgba(120, 80, 30, 0.15) 40%,
        rgba(34, 28, 16, 0.5) 85%,
        rgba(0, 0, 0, 0.7) 100%
    );
    pointer-events: none;
    z-index: -2;
    transition: box-shadow 0.6s ease;
    box-shadow: inset 0 0 0px 0px transparent;
}

/* Darken layer */
.bg-darken {
    display: none;
}

/* Vintage vignette ring */
.vintage-ring {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    box-shadow: inset 0 0 120px 40px rgba(0, 0, 0, 0.3);
}

/* Hide the raw video element */
#camera-feed {
    display: none;
}

/* Canvas covers everything */
#scan-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ============================================
   UI Layer — full-height flex column
   ============================================ */
#ui-layer {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    padding: 0 var(--space-md);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Re-enable pointer events on interactive elements */
button, a, .glass-btn, .action-btn { pointer-events: auto; cursor: pointer; }

/* ============================================
   App Header — editorial warmth
   ============================================ */
.app-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-md) 0 var(--space-xs);
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

.title-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo {
    font-family: var(--font-display);
    font-weight: 700;
    text-align: center;
    line-height: 1.15;
    padding: var(--space-xs) var(--space-sm);
}

.logo-main {
    display: block;
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 9vw, 3.5rem);
    font-weight: 800;
    color: var(--primary-glow);
    line-height: 1.1;
    letter-spacing: 0.02em;
    font-style: normal;
    text-transform: uppercase;
    text-shadow:
        0 3px 8px rgba(0, 0, 0, 0.85),
        0 6px 24px rgba(0, 0, 0, 0.5),
        0 0 50px rgba(238, 173, 43, 0.2);
}

/* Subtle breathing pulse on title */
.breathing {
    animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(0.98); }
}

.logo-sub {
    display: block;
    font-size: clamp(1.2rem, 4.5vw, 1.6rem);
    font-family: var(--font-display);
    font-weight: 400;
    color: var(--ivory-soft);
    margin-top: var(--space-xs);
    line-height: 1.55;
    text-shadow:
        0 2px 6px rgba(0, 0, 0, 0.7),
        0 4px 16px rgba(0, 0, 0, 0.35);
}

.logo-sub em {
    color: var(--primary);
    font-weight: 600;
    font-style: italic;
}

/* ============================================
   Scan Area Spacer
   ============================================ */
#scan-area-spacer {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: var(--space-sm);
    min-height: 0;
}


/* Confidence Bar — drawn on canvas, hide CSS version */
#confidence-bar-container {
    display: none !important;
}

/* Confidence vignette classes — warm amber glow ramp */
body.scan-detecting::after {
    box-shadow: inset 0 0 120px 30px rgba(238, 173, 43, 0.06);
}
body.scan-reading::after {
    box-shadow: inset 0 0 100px 40px rgba(238, 173, 43, 0.12);
}
body.scan-almost-locked::after {
    box-shadow: inset 0 0 80px 50px rgba(238, 173, 43, 0.2);
}
body.scan-locked::after {
    box-shadow: inset 0 0 60px 60px rgba(238, 173, 43, 0.3);
}

/* ============================================
   Help Button — glassmorphic double-bevel
   ============================================ */
.glass-btn {
    background: rgba(24, 19, 7, 0.55);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(238, 173, 43, 0.4);
    color: var(--ivory);
    padding: var(--space-md) var(--space-lg);
    border-radius: 16px;
    font-family: var(--font-display);
    font-size: clamp(1.15rem, 4vw, 1.3rem);
    font-weight: 500;
    font-style: normal;
    text-transform: none;
    letter-spacing: 0.01em;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    text-align: center;
    line-height: 1.4;
    flex-shrink: 0;
    margin-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.3),
        var(--glass-highlight),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4),
        inset 0 0 0 4px rgba(24, 19, 7, 0.2),
        inset 0 0 0 5px rgba(238, 173, 43, 0.25);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.glass-btn:active {
    transform: scale(0.97);
    background: rgba(238, 173, 43, 0.08);
    border-color: rgba(238, 173, 43, 0.5);
}

.glass-btn .sub-text {
    font-size: clamp(1.1rem, 4vw, 1.25rem);
    opacity: 0.85;
    font-style: italic;
    margin-top: 2px;
}

.icon {
    font-family: var(--font-icon);
    font-weight: normal;
    font-style: normal;
    font-size: 1.2rem;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
}

/* Help Button Location */
#help-link {
    position: relative;
    z-index: 20;
    margin-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
}

#help-link .icon {
    display: none;
}

/* ============================================
   Overlays (Success, Fail, Help, Permission)
   ============================================ */
.overlay-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(24, 19, 7, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.35s ease;
}

.overlay-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ============================================
   Glass Panel — warm tonal layered card
   ============================================ */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid rgba(238, 173, 43, 0.15);
    box-shadow:
        var(--shadow-glow),
        var(--shadow-ambient),
        inset 0 0 30px rgba(0, 0, 0, 0.2),
        var(--glass-highlight);
    border-radius: 1.25rem;
    padding: var(--space-xl) var(--space-lg);
    color: var(--ivory);
    text-align: center;
    max-width: 95%;
    width: 460px;
    position: relative;
    overflow: hidden;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

/* Ghost border accent for panels */
.glass-panel::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 1.25rem;
    border: 1px solid rgba(238, 173, 43, 0.08);
    pointer-events: none;
}

/* Inner amber glow for the panel */
.glass-panel::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(
        ellipse at center,
        rgba(238, 173, 43, 0.04) 0%,
        transparent 60%
    );
    pointer-events: none;
}

/* ============================================
   Typography — editorial scale
   ============================================ */
.tech-title {
    font-family: var(--font-display);
    font-weight: 700;
    /* Slightly smaller than before — the CODE is the hero of the page */
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-style: italic;
    margin-bottom: var(--space-sm);
    color: var(--ivory);
    text-shadow:
        0 2px 12px rgba(0, 0, 0, 0.4),
        0 0 30px rgba(238, 173, 43, 0.08);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.tech-subtitle {
    font-family: var(--font-display);
    font-size: clamp(1.1rem, 3.8vw, 1.35rem);
    color: var(--ivory-soft);
    margin-bottom: var(--space-xl);
    line-height: 1.6;
    font-style: italic;
}

.tech-title.warning,
.tech-title.error {
    color: #e0acac;
    text-shadow: 0 0 12px rgba(200, 50, 50, 0.3);
}

/* ============================================
   Scanned Code Display — inset amberit
   ============================================ */
.code-display-container {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(238, 173, 43, 0.2);
    border-radius: 0.75rem;
    padding: var(--space-lg);
    margin: var(--space-md) 0 var(--space-xl) 0;
    position: relative;
    box-shadow:
        inset 0 2px 12px rgba(0, 0, 0, 0.35),
        inset 0 0 0 1px rgba(238, 173, 43, 0.06);
}

.label {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: var(--space-sm);
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
}

.scanned-code {
    font-family: var(--font-ui);
    /* BIG — the whole point is comparing it against the physical pack */
    font-size: clamp(1.8rem, 8.5vw, 3rem);
    color: var(--ivory);
    letter-spacing: 0.06em;
    text-shadow: 0 0 24px rgba(238, 173, 43, 0.5);
    word-break: break-all;
    overflow-wrap: anywhere;
    font-weight: 800;
    line-height: 1.25;
    max-width: 100%;
}

.compare-note {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-style: italic;
    color: var(--ivory-muted);
    margin-top: var(--space-sm);
    line-height: 1.5;
}

.compare-note strong {
    color: var(--primary-glow);
    font-style: normal;
}

.scanned-code .code-segment {
    display: inline;
}

.scanned-code .code-segment.main {
    color: var(--ivory);
}

.scanned-code .code-segment.last {
    display: block;
    margin-top: 0.25em;
    font-size: 1.15em;
    color: var(--primary-glow);
    text-shadow: 0 0 28px rgba(238, 173, 43, 0.7);
    letter-spacing: 0.06em;
}

.code-display-container .label {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0.75;
    margin-bottom: 0.6rem;
}

/* Captured Code Image Preview */
#captured-preview {
    display: none;
    margin: var(--space-xs) 0 var(--space-lg) 0;
    text-align: center;
}

#captured-preview img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(238, 173, 43, 0.2);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

/* ============================================
   Action Buttons — pill standard with glow
   ============================================ */
.action-btn {
    width: 100%;
    padding: 16px 20px;
    border: none;
    border-radius: 9999px;
    font-family: var(--font-ui);
    font-size: 1.05rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    transition: all 0.25s ease;
    text-decoration: none;
    margin-top: 10px;
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--primary-glow) 0%, var(--primary-deep) 100%);
    color: var(--bg-dark);
    box-shadow:
        0 4px 24px rgba(238, 173, 43, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.action-btn.primary:active {
    transform: scale(0.97);
    box-shadow:
        0 2px 12px rgba(238, 173, 43, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.action-btn.secondary {
    background: rgba(24, 19, 7, 0.4);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(238, 173, 43, 0.35);
    color: var(--primary-glow);
}

.action-btn.secondary:active {
    background: rgba(238, 173, 43, 0.1);
    border-color: rgba(238, 173, 43, 0.5);
}

.action-btn.simple-retry {
    background: rgba(24, 19, 7, 0.4);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(238, 225, 205, 0.2);
    color: var(--ivory);
}

.action-btn.simple-retry:active {
    background: rgba(238, 225, 205, 0.08);
}

/* ============================================
   Bookmark Tip — warm footer
   ============================================ */
.bookmark-tip {
    margin-top: var(--space-lg);
    padding: var(--space-md);
    background: rgba(238, 173, 43, 0.04);
    border-radius: 12px;
    border: 1px solid rgba(238, 173, 43, 0.08);
}

.bookmark-tip p {
    font-family: var(--font-display);
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--ivory-muted);
    margin: 0;
    font-style: italic;
}

.bookmark-action {
    color: var(--primary-glow);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 600;
    font-style: normal;
    cursor: pointer;
    pointer-events: auto;
    transition: color 0.2s ease;
}

.bookmark-action:active {
    color: var(--primary);
}

/* ============================================
   Bookmark Toast
   ============================================ */
.bookmark-toast {
    position: fixed;
    bottom: var(--space-xl);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(24, 19, 7, 0.95);
    border: 1px solid rgba(238, 173, 43, 0.35);
    border-radius: 16px;
    padding: 1.25rem 1.5rem;
    color: var(--ivory);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: center;
    max-width: 340px;
    z-index: 200;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.6),
        var(--shadow-glow);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    opacity: 0;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.bookmark-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.bookmark-toast .toast-title {
    font-weight: 700;
    color: var(--primary-glow);
    margin-bottom: var(--space-xs);
    font-size: 1rem;
}

.bookmark-toast .toast-close {
    margin-top: var(--space-sm);
    background: none;
    border: 1px solid rgba(238, 225, 205, 0.2);
    color: var(--ivory);
    padding: 0.4rem 1.5rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s ease;
}

.bookmark-toast .toast-close:active {
    background: rgba(238, 225, 205, 0.08);
}

/* ============================================
   Help Image
   ============================================ */
#help-image {
    width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(238, 173, 43, 0.12);
    margin-bottom: var(--space-md);
    opacity: 0.9;
}

/* ============================================
   Flash & Freeze
   ============================================ */
#scan-flash {
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transition: opacity 0.1s;
}

#scan-flash.active {
    opacity: 0.8;
}

/* ============================================
   Button Group — stacking fix
   ============================================ */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.button-group .action-btn {
    margin-top: 0;
}

/* ============================================
   Responsive polish for very small screens
   ============================================ */
@media (max-height: 680px) {
    .logo-main {
        font-size: clamp(1.6rem, 6vw, 2.2rem);
    }
    .logo-sub {
        font-size: clamp(0.95rem, 3.5vw, 1.15rem);
    }
    .glass-panel {
        padding: var(--space-lg) var(--space-md);
    }
    .tech-title {
        font-size: clamp(1.5rem, 5vw, 1.9rem);
    }
}
