/* ═══════════════════════════════════════════════════════════════════════
   Advice Slip – Stylesheet
   Paper-receipt aesthetic · Pure CSS · Dark-mode aware · Responsive
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens (Light) ───────────────────────────────────────────── */
:root {
    --font-mono: "Courier New", "Courier", monospace;
    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;

    --bg-page: #e8e4df;
    --bg-card: #fffef9;
    --bg-card-shadow: rgba(0, 0, 0, 0.12);
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #999999;
    --accent: #2c2c2c;
    --accent-hover: #000000;
    --separator-color: #1a1a1a;
    --error-color: #cc3333;
    --error-bg: #fff5f5;
    --btn-bg: #1a1a1a;
    --btn-text: #ffffff;
    --btn-hover: #333333;
    --skeleton-bg: #e0ddd8;
    --skeleton-shine: #f5f3f0;
    --tear-color: #fffef9;
    --circle-1: rgba(255, 200, 100, 0.15);
    --circle-2: rgba(100, 180, 255, 0.10);
    --circle-3: rgba(255, 130, 130, 0.08);

    --radius: 4px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark Theme ──────────────────────────────────────────────────────── */
.app-root.dark {
    --bg-page: #0d0d0d;
    --bg-card: #1c1c1c;
    --bg-card-shadow: rgba(0, 0, 0, 0.5);
    --text-primary: #f0ede8;
    --text-secondary: #b0ada8;
    --text-muted: #666666;
    --accent: #e0ddd8;
    --accent-hover: #ffffff;
    --separator-color: #f0ede8;
    --error-color: #ff7777;
    --error-bg: #1f1515;
    --btn-bg: #f0ede8;
    --btn-text: #1a1a1a;
    --btn-hover: #ffffff;
    --skeleton-bg: #2a2a2a;
    --skeleton-shine: #3a3a3a;
    --tear-color: #1c1c1c;
    --circle-1: rgba(255, 200, 100, 0.04);
    --circle-2: rgba(100, 180, 255, 0.03);
    --circle-3: rgba(255, 130, 130, 0.03);
}

/* ── Reset ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-mono);
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

/* ── App Root ────────────────────────────────────────────────────────── */
.app-root {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 2rem 1rem;
}

/* ── Background Decoration ───────────────────────────────────────────── */
.bg-decoration {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.bg-circle {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
}

.bg-circle--1 {
    width: 500px;
    height: 500px;
    background: var(--circle-1);
    top: -150px;
    right: -100px;
    animation: float 20s ease-in-out infinite;
}

.bg-circle--2 {
    width: 400px;
    height: 400px;
    background: var(--circle-2);
    bottom: -100px;
    left: -80px;
    animation: float 25s ease-in-out infinite reverse;
}

.bg-circle--3 {
    width: 300px;
    height: 300px;
    background: var(--circle-3);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float 18s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(20px, -20px) scale(1.05); }
    66% { transform: translate(-15px, 15px) scale(0.95); }
}

/* ── App Container ───────────────────────────────────────────────────── */
.app-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* ── Header ──────────────────────────────────────────────────────────── */
.app-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-icon {
    font-size: 1.6rem;
    animation: wiggle 3s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.logo-text {
    font-family: var(--font-mono);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: 2px solid var(--btn-bg);
    border-radius: var(--radius);
    background: var(--btn-bg);
    color: var(--btn-text);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.btn:hover {
    background: var(--btn-hover);
    border-color: var(--btn-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--bg-card-shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

.btn-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.btn-theme {
    padding: 0.55rem 0.7rem;
    font-size: 1.2rem;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-retry {
    margin-top: 1.2rem;
    padding: 0.7rem 1.8rem;
    font-size: 0.9rem;
}

/* ── Main ────────────────────────────────────────────────────────────── */
.app-main {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* ── Slip Card (the "paper") ─────────────────────────────────────────── */
.slip-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow:
        0 2px 8px var(--bg-card-shadow),
        0 12px 40px var(--bg-card-shadow);
    position: relative;
    transition: all var(--transition);
    animation: slip-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.slip-card:hover {
    box-shadow:
        0 4px 16px var(--bg-card-shadow),
        0 20px 60px var(--bg-card-shadow);
    transform: translateY(-3px);
}

.slip-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

@keyframes slip-in {
    from {
        opacity: 0;
        transform: translateY(30px) rotate(-1deg) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }
}

.slip-inner {
    padding: 2.5rem 2rem;
    text-align: center;
}

/* ── Brand ───────────────────────────────────────────────────────────── */
.slip-brand {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* ── Separator (dashed receipt line) ─────────────────────────────────── */
.separator {
    width: 100%;
    height: 2px;
    margin: 1.4rem 0;
    background: repeating-linear-gradient(
        to right,
        var(--separator-color) 0px,
        var(--separator-color) 8px,
        transparent 8px,
        transparent 14px
    );
    opacity: 0.5;
}

/* ── Advice Text ─────────────────────────────────────────────────────── */
.slip-advice {
    font-family: var(--font-mono);
    font-size: 1.35rem;
    line-height: 1.7;
    color: var(--text-primary);
    padding: 0.5rem 0;
    quotes: "\201C" "\201D";
    animation: fade-up 0.5s ease 0.2s both;
}

.slip-advice::before {
    content: open-quote;
    display: block;
    font-size: 2.5rem;
    line-height: 1;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.slip-advice::after {
    content: close-quote;
    display: block;
    font-size: 2.5rem;
    line-height: 0.5;
    color: var(--text-muted);
    margin-top: 0.8rem;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Meta Row ────────────────────────────────────────────────────────── */
.slip-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.meta-ref {
    font-weight: 700;
    color: var(--text-secondary);
}

/* ── Torn Paper Edge ─────────────────────────────────────────────────── */
.slip-tear {
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    height: 12px;
    background: var(--tear-color);
    clip-path: polygon(
        0% 0%, 3% 100%, 6% 0%, 9% 100%, 12% 0%, 15% 100%,
        18% 0%, 21% 100%, 24% 0%, 27% 100%, 30% 0%, 33% 100%,
        36% 0%, 39% 100%, 42% 0%, 45% 100%, 48% 0%, 51% 100%,
        54% 0%, 57% 100%, 60% 0%, 63% 100%, 66% 0%, 69% 100%,
        72% 0%, 75% 100%, 78% 0%, 81% 100%, 84% 0%, 87% 100%,
        90% 0%, 93% 100%, 96% 0%, 100% 100%, 100% 0%
    );
    filter: drop-shadow(0 2px 2px var(--bg-card-shadow));
}

/* ── Loading State ───────────────────────────────────────────────────── */
.slip-card--loading .slip-inner {
    min-height: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-dots {
    display: flex;
    gap: 0.6rem;
    margin: 1.5rem 0 0.8rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    animation: bounce 1.4s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.loading-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Skeleton lines */
.skeleton-lines {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    align-items: center;
}

.skeleton-line {
    height: 14px;
    border-radius: 7px;
    background: linear-gradient(
        90deg,
        var(--skeleton-bg) 25%,
        var(--skeleton-shine) 50%,
        var(--skeleton-bg) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Error State ─────────────────────────────────────────────────────── */
.slip-card--error {
    background: var(--error-bg);
    border: 2px solid var(--error-color);
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 0.8rem;
    animation: shake 0.6s ease both;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.error-title {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--error-color);
    margin-bottom: 0.5rem;
}

.error-message {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    word-break: break-word;
}

/* ── Footer ──────────────────────────────────────────────────────────── */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.app-footer a:hover {
    color: var(--text-primary);
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 560px) {
    .app-root {
        padding: 1.5rem 0.75rem;
    }

    .app-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .slip-inner {
        padding: 2rem 1.4rem;
    }

    .slip-advice {
        font-size: 1.15rem;
    }

    .slip-brand {
        font-size: 0.95rem;
    }

    .btn-label {
        display: none;
    }

    .btn-refresh {
        padding: 0.55rem 0.7rem;
    }
}

@media (max-width: 380px) {
    .slip-advice {
        font-size: 1.05rem;
    }

    .slip-meta {
        flex-direction: column;
        gap: 0.3rem;
    }
}

/* ── Reduced Motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Focus Visible ───────────────────────────────────────────────────── */
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}
