/* PicketPerfect — Styles */
/* ================================================
   Design Tokens
   ================================================ */
:root {
    /* Colors */
    --bg: #F5F2EB;
    --card: #FFFFFF;
    --border: #D4CFC5;
    --border-light: #E8E4DC;
    --accent: #FFB800;
    --accent-hover: #E6A600;
    --accent-glow: rgba(255, 184, 0, 0.25);
    --blue: #2D5F8A;
    --blue-light: #3A7AB5;
    --blue-bg: rgba(45, 95, 138, 0.08);
    --red: #D94032;
    --red-bg: rgba(217, 64, 50, 0.1);
    --green: #3A8A4A;
    --green-bg: rgba(58, 138, 74, 0.1);
    --text: #2E2E2E;
    --text-secondary: #6B6B6B;
    --text-muted: #9A9590;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Spacing */
    --gap: 16px;
    --radius: 10px;
    --radius-sm: 6px;
}

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

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

body {
    font-family: var(--font-body);
    color: var(--text);
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
    background-size: 20px 20px;
    line-height: 1.6;
    min-height: 100vh;
}

/* ================================================
   Header
   ================================================ */
#site-header {
    background: linear-gradient(135deg, #2E2E2E 0%, #1a1a1a 100%);
    color: #fff;
    padding: 20px var(--gap);
    text-align: center;
    border-bottom: 4px solid var(--accent);
    position: relative;
}

#site-header::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.logo-icon {
    font-size: 1.8rem;
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo-accent {
    color: var(--accent);
}

.tagline {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.65);
    margin-top: 4px;
    letter-spacing: 0.5px;
}

/* ================================================
   Main Layout
   ================================================ */
#app-main {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--gap);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

/* ================================================
   Card
   ================================================ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.section-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-light);
    letter-spacing: -0.3px;
}

/* ================================================
   Hero Result
   ================================================ */
.hero-card {
    text-align: center;
    padding: 28px 20px;
    border: 2px solid var(--accent);
    background: linear-gradient(180deg, #FFFDF5 0%, #FFFFFF 100%);
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--blue), var(--accent));
}

.hero-label {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.hero-fraction {
    font-family: var(--font-mono);
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--blue);
    line-height: 1.1;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.hero-decimal {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

.hero-compliance {
    margin-top: 10px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.hero-compliance.compliance-pass {
    background: var(--green-bg);
    color: var(--green);
}

.hero-compliance.compliance-fail {
    background: var(--red-bg);
    color: var(--red);
    animation: pulse-warn 1.5s ease-in-out infinite;
}

@keyframes pulse-warn {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Fraction typography */
.frac-whole {
    /* inherits */
}

.frac-sep {
    margin: 0 1px;
}

.frac-num {
    font-size: 0.6em;
    vertical-align: super;
    line-height: 1;
}

.frac-den {
    font-size: 0.6em;
    vertical-align: sub;
    line-height: 1;
}

.frac-slash {
    font-size: 0.6em;
    margin: 0 1px;
}

/* ================================================
   Config Panel
   ================================================ */
.config-group {
    margin-bottom: 18px;
}

.config-group:last-child {
    margin-bottom: 0;
}

.config-label {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.config-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    margin-top: -4px;
}

/* Pill Buttons (Project Type) */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04), inset 0 -2px 0 rgba(0, 0, 0, 0.06);
}

.pill-btn:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.pill-btn.active {
    background: linear-gradient(180deg, #FFF8E1 0%, #FFF3CC 100%);
    border-color: var(--accent);
    color: #5A4500;
    box-shadow: 0 2px 8px var(--accent-glow), inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.pill-icon {
    font-size: 1.1rem;
}

.pill-text {
    white-space: nowrap;
}

/* Small pills (Units) */
.pill-group-small {
    gap: 6px;
}

.pill-btn-sm {
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.pill-btn-sm:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.pill-btn-sm.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

/* End Condition Buttons */
.pill-group-end {
    flex-direction: column;
    gap: 8px;
}

.pill-btn-end {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    text-align: left;
    width: 100%;
}

.pill-btn-end:hover {
    border-color: var(--accent);
}

.pill-btn-end.active {
    background: linear-gradient(180deg, #FFF8E1 0%, #FFF3CC 100%);
    border-color: var(--accent);
}

.end-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.end-text {
    font-weight: 600;
    flex: 1;
}

.end-detail {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Inputs */
.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-field {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.num-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    background: #FAFAF8;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -moz-appearance: textfield;
}

.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.num-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(45, 95, 138, 0.15);
}

.num-input.input-error {
    border-color: var(--red);
    box-shadow: 0 0 0 3px var(--red-bg);
}

.num-input-sm {
    max-width: 90px;
}

.num-input-count {
    max-width: 90px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
}

.input-unit {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Stepper */
.stepper-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stepper-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: linear-gradient(180deg, #FFFFFF 0%, #F5F2EB 100%);
    color: var(--text);
    font-size: 1.4rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), inset 0 -2px 0 rgba(0, 0, 0, 0.06);
    line-height: 1;
}

.stepper-btn:hover {
    border-color: var(--accent);
    background: linear-gradient(180deg, #FFF8E1 0%, #FFF3CC 100%);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.stepper-btn:active {
    transform: scale(0.93);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Select */
.select-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text);
    background: #FAFAF8;
    cursor: pointer;
    transition: border-color 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236B6B6B' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.select-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(45, 95, 138, 0.15);
}

/* ================================================
   Results Table
   ================================================ */
.results-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table td {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.result-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-value {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--blue);
    text-align: right;
    white-space: nowrap;
}

.results-error {
    padding: 12px 14px;
    background: var(--red-bg);
    border: 1px solid var(--red);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ================================================
   Visual Diagram
   ================================================ */
.diagram-container {
    overflow-x: auto;
    padding: 16px 0;
    -webkit-overflow-scrolling: touch;
}

.diagram-inner {
    display: flex;
    align-items: stretch;
    min-height: 80px;
    position: relative;
}

.diagram-post {
    width: 8px;
    min-height: 80px;
    background: linear-gradient(180deg, #4A4A4A 0%, #2E2E2E 100%);
    border-radius: 2px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.diagram-post::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -2px;
    right: -2px;
    height: 6px;
    background: #3A3A3A;
    border-radius: 2px 2px 0 0;
}

.diagram-element {
    min-height: 80px;
    background: linear-gradient(180deg, #D4A55A 0%, #B8904A 30%, #C49B52 70%, #A67F40 100%);
    border: 1px solid #997640;
    border-radius: 2px;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    z-index: 1;
}

.diagram-element::after {
    content: '';
    position: absolute;
    top: 10%;
    left: 50%;
    width: 1px;
    height: 80%;
    background: rgba(0, 0, 0, 0.08);
}

.diagram-element:hover {
    transform: scaleY(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 3;
}

.diagram-gap {
    min-height: 80px;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.diagram-gap-line {
    position: absolute;
    top: 50%;
    left: 4px;
    right: 4px;
    height: 0;
    border-top: 1px dashed var(--blue);
    opacity: 0.4;
}

.diagram-gap-arrow-l,
.diagram-gap-arrow-r {
    position: absolute;
    top: 50%;
    width: 0;
    height: 0;
    border-style: solid;
    transform: translateY(-50%);
}

.diagram-gap-arrow-l {
    left: 2px;
    border-width: 4px 5px 4px 0;
    border-color: transparent var(--blue) transparent transparent;
    opacity: 0.5;
}

.diagram-gap-arrow-r {
    right: 2px;
    border-width: 4px 0 4px 5px;
    border-color: transparent transparent transparent var(--blue);
    opacity: 0.5;
}

.diagram-gap-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--blue);
    background: rgba(255, 255, 255, 0.9);
    padding: 1px 4px;
    border-radius: 3px;
    position: relative;
    z-index: 2;
    white-space: nowrap;
    pointer-events: none;
}

.diagram-gap:hover .diagram-gap-label {
    background: var(--accent);
    color: #2E2E2E;
    font-weight: 600;
}

.diagram-gap.violation {
    background: var(--red-bg);
}

.diagram-gap.violation .diagram-gap-label {
    color: var(--red);
    font-weight: 700;
}

.diagram-gap.violation .diagram-gap-line {
    border-color: var(--red);
    opacity: 0.6;
}

.diagram-total-label {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.diagram-tooltip {
    position: fixed;
    background: #2E2E2E;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
}

.diagram-note {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

/* Ruler */
.diagram-ruler {
    height: 16px;
    background: linear-gradient(180deg, #F0EDE5 0%, #E8E4DC 100%);
    border: 1px solid var(--border);
    border-bottom: 2px solid var(--text-secondary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    position: relative;
    overflow: hidden;
    margin-bottom: 0;
}

/* ================================================
   Reverse Calculator
   ================================================ */
.reverse-results {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

/* ================================================
   Cut List Card
   ================================================ */
.cutlist-card {
    background: #FEFCF5;
    position: relative;
    border-color: #E0D8C8;
}

.cutlist-torn-edge {
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    height: 10px;
    background: linear-gradient(135deg, var(--bg) 33.33%, transparent 33.33%) 0 0,
                linear-gradient(225deg, var(--bg) 33.33%, transparent 33.33%) 0 0;
    background-size: 12px 10px;
    background-repeat: repeat-x;
}

.cutlist-title {
    margin-top: 4px;
}

.cutlist-hint {
    margin-top: 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    padding-top: 10px;
    border-top: 1px dashed var(--border-light);
}

/* ================================================
   Action Buttons
   ================================================ */
.actions-row {
    display: flex;
    gap: 12px;
}

.action-btn {
    flex: 1;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    user-select: none;
}

.action-btn-primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #2E2E2E;
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.action-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--accent-glow);
}

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

.action-btn-secondary {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.action-btn-secondary:hover {
    border-color: var(--blue);
    color: var(--blue);
}

/* ================================================
   Copy Toast
   ================================================ */
.copy-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #2E2E2E;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

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

/* ================================================
   Ad Placeholders
   ================================================ */
.ad-container {
    display: flex;
    justify-content: center;
    margin: 4px 0;
}

.ad-placeholder {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.5);
}

.ad-mobile {
    display: flex;
}

.ad-mobile .ad-placeholder {
    width: 320px;
    height: 50px;
}

.ad-desktop {
    display: none;
}

.ad-desktop .ad-placeholder {
    width: 728px;
    height: 90px;
}

/* ================================================
   Footer
   ================================================ */
#site-footer {
    text-align: center;
    padding: 20px var(--gap);
    color: var(--text-muted);
    font-size: 0.78rem;
    border-top: 1px solid var(--border-light);
    margin-top: 8px;
}

.footer-sub {
    margin-top: 4px;
    font-size: 0.7rem;
}

/* ================================================
   Utility
   ================================================ */
.hidden {
    display: none !important;
}

/* ================================================
   Desktop (min-width: 768px)
   ================================================ */
@media (min-width: 768px) {
    .logo h1 {
        font-size: 2.2rem;
    }

    .logo-icon {
        font-size: 2.2rem;
    }

    .hero-fraction {
        font-size: 4.2rem;
    }

    .hero-decimal {
        font-size: 1.15rem;
    }

    #app-main {
        padding: 24px;
        gap: 20px;
    }

    .card {
        padding: 28px;
    }

    .ad-mobile {
        display: none;
    }

    .ad-desktop {
        display: flex;
    }

    .pill-btn {
        padding: 10px 18px;
    }

    .pill-btn-end {
        flex-direction: row;
    }

    .pill-group-end {
        flex-direction: row;
    }

    .pill-btn-end {
        flex: 1;
        flex-direction: column;
        text-align: center;
        align-items: center;
    }

    .diagram-gap-label {
        font-size: 0.7rem;
    }
}

/* ================================================
   Print Styles
   ================================================ */
@media print {
    body {
        background: #fff !important;
        background-image: none !important;
        color: #000 !important;
        font-size: 11pt;
    }

    #site-header {
        background: none !important;
        color: #000 !important;
        border-bottom: 3px solid #000 !important;
        padding: 10px 0;
    }

    #site-header::after {
        display: none;
    }

    .logo-accent {
        color: #000 !important;
    }

    .tagline {
        color: #555 !important;
    }

    .ad-container,
    #config-panel,
    #reverse-section,
    #actions-section,
    .copy-toast,
    .diagram-tooltip,
    #site-footer {
        display: none !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        padding: 12px !important;
        page-break-inside: avoid;
    }

    .hero-card {
        border: 2px solid #000 !important;
        background: #fff !important;
    }

    .hero-card::before {
        display: none;
    }

    .hero-fraction {
        color: #000 !important;
        font-size: 36pt !important;
    }

    .hero-decimal {
        color: #333 !important;
    }

    .result-value {
        color: #000 !important;
    }

    .section-title {
        border-bottom-color: #ccc !important;
    }

    .diagram-element {
        background: #D4A55A !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .diagram-post {
        background: #2E2E2E !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .diagram-gap-label {
        background: transparent !important;
        color: #000 !important;
    }

    .diagram-note {
        font-size: 8pt;
    }

    .cutlist-card {
        background: #fff !important;
    }

    .cutlist-torn-edge {
        display: none;
    }

    #app-main {
        max-width: 100%;
        padding: 0;
    }
}
