/* ===========================
   Paint By Pictures - Core Styles
   =========================== */

/* --- Base Layout --- */
* {
    box-sizing: border-box;
}

:root {
    --paper: #FAF9F5;
    --graphite: #5C5954;
    --pencil-shadow: #D1CEC5;
    --grid-line: #EAE8DF;
}

html {
    --font-size: 15px;
    width: 100vw;
    height: 100%;
    /* Fallback */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    /* Prevent overscroll/bounce on iOS */
    inset: 0;
}

body {
    font-family: 'Josefin Sans', sans-serif;
    color: var(--graphite);
    background-color: var(--paper);
    background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 20px 20px;
    font-size: 16px;
    max-width: 100%;
    width: 100vw;
    height: 100%;
    /* Fallback */
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    overscroll-behavior: none;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Fredericka the Great', cursive;
    color: var(--graphite);
}

h1 {
    margin-bottom: 20px;
}

/* --- Utility Classes --- */
.hide {
    display: none;
}

.transparent {
    opacity: 0;
}

.expanded {
    width: 100%;
}

.with-shadow {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.35);
}

.white {
    fill: white;
    stroke: black;
    stroke-width: 1px
}

.transition-ease {
    transition: fill 800ms ease-in;
    z-index: 99;
}

/* --- Animation --- */
.fall-animation {
    animation-fill-mode: forwards;
}

/* --- Canvas & Camera --- */
.canvas-container {
    margin: 20px 0;
    border: 1px solid #ccc;
    position: relative;
    width: 100%;
    overflow: hidden;
}

#selection-canvas .selection-border {
    fill: none;
    stroke: var(--selection-color);
    stroke-width: 5px;
    stroke-linejoin: round;
    stroke-linecap: round;
}

#camera-view {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#capture-canvas,
#mask-canvas {
    display: none;
}

/* --- Color Swatches --- */
#color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    padding: 12px 16px;
}

#color-swatches::-webkit-scrollbar {
    display: none;
}

.capture-btn-inline {
    display: none;
}

/* Swatches container - unified, no split */

.swatch {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25), 0 1px 4px rgba(0, 0, 0, 0.15);
    border: 4px solid rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
}

.swatch:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* --- Tippy.js Custom Theme --- */
.tippy-box[data-theme~='piclo'] {
    background-color: #333;
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    padding: 6px 4px;
    max-width: 200px !important;
}

.tippy-box[data-theme~='piclo'][data-placement^='top']>.tippy-arrow::before {
    border-top-color: #333;
}

.swatch.active {
    border: 3px solid #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px) scale(1.05);
}

.swatch span {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.controls {
    display: none;
    /* No longer needed, capture button is inline */
}

/* --- UI CONTROLS --- (consolidated above) */

/* --- Universal Button Typography --- */
button,
.clickable-list {
    font-family: inherit;
    font-size: 16px;
    letter-spacing: 0.3px;
    font-weight: 600;
}

.clickable-list.no-padding {
    padding: 0;
}

.clickable-list.no-chevron::after {
    content: none;
}

.clickable-list.centered {
    text-align: center;
}

/* --- Buttons --- */
.btn {
    font-family: inherit;
    font-size: 16px;
    letter-spacing: 0.3px;
    font-weight: 600;
    padding: 0.75rem 1rem;
    background-color: transparent;
    color: var(--graphite);
    border: 1px solid var(--graphite);
    cursor: pointer;
    box-shadow: 2px 2px 0px var(--pencil-shadow);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translate(2px, 2px);
}

.btn:disabled {
    background: transparent;
    border-color: #e0e0e0;
    color: #999;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn.hollow {
    background: transparent;
    border: 1px solid var(--graphite);
    color: var(--graphite);
    box-shadow: none;
}

.btn.clear {
    background: transparent;
    border: 0;
    color: var(--graphite);
    box-shadow: none;
}

.btn.clear:hover {
    background: transparent;
}

.btn.width-full {
    width: 100%;
}

/* --- Capture FAB --- */
#capture-btn {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 64px;
    height: 64px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background-color: var(--graphite);
    border: 4px solid white;
    color: white;
    /* box-shadow: 2px 2px 0px var(--pencil-shadow); */
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25);
    z-index: 100;
    transition: all 0.1s ease;
    background-color: #3d87c2
}

#capture-btn:hover {
    transform: translateX(-50%) translateY(-2px);
}

#capture-btn:active {
    transform: translateX(-50%) translate(2px, 2px);
    box-shadow: 0px 0px 0px var(--pencil-shadow);
}

/* Removed capture-btn glow effects */

/* --- Clickable List --- */
.clickable-list {
    width: 100%;
    border: 0;
    border-color: #AAA;
    border-radius: 0;
    border-bottom: 1px solid #AAA;
    /* border-bottom: 1px solid #666;  */
    position: relative;
    text-align: left;
    background: transparent;
    color: black;
    padding: 1rem;
    transition: background-color 0.2s ease, filter 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.clickable-list:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.clickable-list:active {
    background-color: rgba(0, 0, 0, 0.1);
    transform: scale(0.98);
}

.clickable-list::after {
    position: absolute;
    right: 1rem;
    content: '\f054';
    font-family: 'fontAwesome';
    color: #AAA;
}

.clickable-list:last-of-type {
    border-bottom: 0;
}

/* .clickable-list:first-of-type {
    border-top: 1px solid #999 !important;
} */

.clickable-list.border-top-1 {
    border-top: 1px solid #999 !important;
}

.clickable-list.border-top-0 {
    border-top: 0 !important;
}

.margin-top-1 {
    margin-top: 1rem;
}

/* --- Instructions & Status --- */
.instructions {
    margin: 20px 0;
    padding: 15px;
    background-color: #f0f0f0;
    border-radius: 5px;
}

#status-message {
    margin-top: 10px;
    font-style: italic;
    color: #666;
    display: none;
}

/* --- Artwork Container --- */
#artwork-container {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Hide overflow to prevent scrollbars */
}

#artwork-container>* {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#camera-view {
    z-index: 1;
    object-fit: cover;
    pointer-events: none;
}

/* --- SVG Canvas --- */
#svg-canvas {
    z-index: 3;
}

#svg-canvas svg {
    display: block;
}

#svg-canvas path,
#svg-canvas polygon,
#svg-canvas rect,
#svg-canvas circle,
#svg-canvas ellipse {
    cursor: pointer;
    pointer-events: auto;
    vector-effect: non-scaling-stroke;
}

#svg-canvas .template-view {
    fill: white;
    stroke: #666;
    stroke-width: 1.5px;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 1;
}

#svg-canvas .selected {
    fill: transparent !important;
    stroke: none !important;
}

#svg-canvas .captured {
    fill: transparent;
    stroke: transparent;
}

#masked-canvas {
    z-index: 2;
    pointer-events: none;
}

#selection-canvas {
    z-index: 4;
    pointer-events: none;
}

/* --- Footer --- */
.footer {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 9;
    padding: 0;
    padding-top: 34px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    /* Safe area for home indicator */
    width: 100%;
    background: transparent;
    overflow: visible;
    pointer-events: none;
}

.footer>* {
    pointer-events: all;
}

/* .footer.open {
    height: unset;
    max-height: 50000px;
    
} */

/* --- UI CONTROLS --- (consolidated above) */

/* --- Dialogs --- */
dialog>article header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 1rem;
    margin-bottom: 0;
    border-bottom: 0 !important;
    background: none !important;
}

h2.logo-header {
    font-size: 45px;
}


dialog>article .close,
dialog>article :is(a, button)[rel=prev] {
    background-size: unset;
    margin: 0;
    position: absolute;
    right: 1.5rem;
    top: 1.75rem;
    transform: translateY(-50%);
}

dialog>article {
    border-radius: 5px;
    border: 1px solid var(--graphite);
    box-shadow: 3px 3px 0px var(--pencil-shadow);
    background-color: var(--paper);
    color: var(--graphite);
}

.score-block-wrapper {
    position: relative;
    display: inline-block;
    cursor: help;
}

.score-block-wrapper::after {
    content: attr(data-title);
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, bottom 0.2s;
    letter-spacing: normal;
    font-family: Arial, sans-serif;
    z-index: 9999;
}

.score-block-wrapper::before {
    content: '';
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.85);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, bottom 0.2s;
    z-index: 9999;
}

.score-block-wrapper:hover::after,
.score-block-wrapper:hover::before {
    opacity: 1;
}

/* ===========================
   Layer Bar Chart UI
   =========================== */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    justify-content: center;
    margin-top: 15px;
    font-size: 1.2rem;
    text-align: center;
}

.emoji-grid span {
    display: inline-block;
}

.layer-barchart-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 15px;
    padding: 0 5px;
    height: 120px;
}

.layer-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    height: 100%;
    cursor: pointer;
}

.layer-bar-swatch {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.layer-bar-track {
    width: 12px;
    flex-grow: 1;
    background-color: #f1f3f5;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: flex-end;
}

.layer-bar-fill {
    width: 100%;
    border-radius: 6px;
    transition: height 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 400px) {
    .layer-bar-swatch {
        width: 12px;
        height: 12px;
    }

    .layer-bar-track {
        width: 8px;
    }
}

/* ===========================
   Mobile Overrides
   =========================== */
@media (max-width: 600px) {
    .results-layout {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        /* Adds breathing room between the text and the chart */
        margin-bottom: 1rem;
    }

    .results-text {
        text-align: center;
        width: 100%;
    }

    .results-title {
        margin-bottom: 0.5rem;
    }

    /* Adjust the list to look good when centered */
    .results-list {
        display: block;
        /* Resets any flex/inline overrides */
        width: fit-content;
        /* Shrinks the invisible box to exactly fit the text */
        margin: 0 auto;
        /* Centers that perfectly sized box horizontally */
        text-align: left;
        /* Keeps the text/bullets left-aligned inside the centered box */
        padding-left: 0rem;
        /* Gives the bullets space to breathe */
        margin-bottom: 0;
        font-size: 1.1rem;
    }

    .results-list li {
        text-align: left;
        margin-bottom: 0.25rem;
        list-style-type: disc !important;
        list-style-position: outside !important;
    }

    #score-blocks {
        width: 100%;
        display: flex;
        justify-content: center;
    }
}

/* ===========================
   Modal Layout & Typography
   =========================== */
.modal-header {
    margin: 0;
    color: var(--graphite);
    font-family: 'Fredericka the Great', cursive;
    font-size: 25px;
    font-weight: 400;
    width: 100%;
    text-align: center;
}

.results-layout {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    margin-top: 1rem;
    padding-left: 2rem;
    padding-right: 2rem;
}

.results-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.results-title {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: #333;
}

/* ===========================
   Base/Desktop Styles
   =========================== */
.results-list {
    padding-left: 2rem;
    margin-top: 0.5rem;
}

.results-list li {
    margin-bottom: 0.25rem;
}



#score-blocks {
    flex: 1;
}

.note-text {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
    font-weight: 400;
    margin-top: 1rem;
}

.text-center {
    text-align: center;
}

.app-icon {
    max-width: 300px;
    display: block;
    margin: auto;
    border-radius: 7px;
    /* border-radius: 3rem;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.25); */
    margin-bottom: 1rem;
    margin-top: 0rem;
}

.app-icon-container {
    width: 200px;
    height: 200px;
    background-image: url('../img/landing-1.png');
    background-size: cover;
    background-position: center;
    border-radius: 1000px;
    margin: 0 auto;
}

/* ===========================
   Confirm Restart Modal
   =========================== */
dialog>article {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    /* Ensure modal doesn't exceed screen height */
}

.modal-content {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem 0;
}

.landing-modal-content {
    display: flex;
    flex-direction: row;
    gap: 1rem;
}

.landing-modal-content>div {
    flex: 1;
}

footer .btn {
    width: 100%;
    margin-bottom: 0px;
}

.confirm-modal-article {
    border-radius: 0px;
}

.confirm-modal-title {
    margin-bottom: 1.5rem;
    text-align: center;
    color: #333;
}

.confirm-modal-text {
    margin-bottom: 1.5rem;
    text-align: left;
    color: #444;
}

.confirm-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.confirm-modal-actions button+button {
    margin-left: 0 !important;
}

/* ===========================
   Support Links
   =========================== */
.support-text {
    text-align: center;
    font-size: 14px;
    margin-top: 2rem;
    color: var(--muted-color);
}

.support-text a {
    color: inherit;
    text-decoration: underline;
}

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