:root {
    --anim-speed: 1;
    --primary-color: #6d4b8e;
    --primary-hover: #583a75;
    --primary-light: #f3eefa;
    --bg-color: #e2e8f0;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --disc-size: min(80vw, 600px);
    --peek-transform: translateX(140%);
    --inner-scale: 1.07; /* Adjusted for exact centering and tiny padding */
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-color);
    font-family:
        'Inter',
        -apple-system,
        BlinkMacSystemFont,
        'Segoe UI',
        Roboto,
        sans-serif;
    color: var(--text-primary);
}

body {
    display: flex;
    flex-direction: row;
    height: 100vh;
    height: 100dvh;
}

/* Animation Canvas Panel */
.animation-view {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 24px;
    background: radial-gradient(circle at center, #ffffff 0%, #cbd5e1 100%);
    overflow: hidden;
}

/* Controls Panel */
.controls-view {
    width: 360px;
    background: var(--card-bg);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.06);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 20;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
}

/* Header Styling */
.header-section {
    margin-bottom: 4px;
}

.header-title {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.header-subtitle {
    margin: 4px 0 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Card Containers */
.control-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #ffffff;
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Button Styling */
.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.btn-full {
    grid-column: span 2;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(109, 75, 142, 0.25);
    min-height: 44px;
}

.btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(109, 75, 142, 0.35);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    background: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn-secondary {
    background: var(--primary-light);
    color: var(--primary-color);
    box-shadow: none;
}

.btn-secondary:hover {
    background: #e9e0f5;
    color: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 1.5px solid var(--primary-color);
    box-shadow: none;
}

.btn-outline:hover {
    background: var(--primary-light);
}

/* Custom File Input */
.file-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.file-input-wrapper input[type='file'] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* Textarea & Select */
input[type='text'],
textarea {
    width: 100%;
    padding: 10px 12px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 13px;
    background: #f8fafc;
    color: var(--text-primary);
    transition: border-color 0.2s;
}

input[type='text']:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: #ffffff;
}

select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    min-height: 44px;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Segmented Control Buttons */
.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.btn-toggle {
    padding: 8px 4px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.78rem;
    transition: all 0.2s ease;
    text-align: center;
    white-space: nowrap;
    min-height: 38px;
}

.btn-toggle:hover {
    color: var(--primary-color);
    background: rgba(109, 75, 142, 0.08);
}

.btn-toggle.active {
    background: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(109, 75, 142, 0.28);
}

/* Range Slider */
input[type='range'] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    margin: 6px 0;
}

input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

input[type='range']::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

/* Accordion Details */
details {
    width: 100%;
}

details summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    user-select: none;
    padding: 4px 0;
    outline: none;
}

details summary:hover {
    color: var(--primary-color);
}

/* Animation Container & Base */
.doodle-container {
    position: relative;
    width: var(--disc-size);
    height: var(--disc-size);
    display: flex;
    justify-content: center;
    align-items: center;
    transition:
        width 0.3s ease,
        height 0.3s ease;
}

/* Clean Paper Stack */
.paper-stack {
    position: absolute;
    width: calc(118% * var(--inner-scale, 1));
    height: calc(118% * var(--inner-scale, 1));
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1; /* Layer 1: Bottom */
    pointer-events: none;
}

.paper-sheet {
    position: absolute;
    inset: 0;
    background-color: #ffffff;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.paper-sheet-1 {
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.06),
        0 12px 32px rgba(0, 0, 0, 0.08);
}

.paper-sheet-2 {
    transform: rotate(2.5deg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    background-color: #fcfcfc;
}

/* Drawing Canvas */
.canvas-svg {
    position: absolute;
    width: calc(100% * var(--inner-scale, 1));
    height: calc(100% * var(--inner-scale, 1));
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2; /* Layer 2: On top of paper */
    pointer-events: none;
}

/* Disc Slide Animation & Dynamic Shadow */
.disc-slide-wrapper {
    position: absolute;
    width: calc(100% * var(--inner-scale, 1));
    height: calc(100% * var(--inner-scale, 1));
    top: calc(50% - (50% * var(--inner-scale, 1)));
    left: calc(50% - (50% * var(--inner-scale, 1)));
    z-index: 10; /* Starts BELOW the frame (Layer 3) */
    /* Delay z-index switch when returning so it slides under smoothly */
    transition:
        transform calc(1.2s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        filter calc(1.2s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        z-index 0s calc(1.2s / var(--anim-speed));
    filter: drop-shadow(0px 0px 0px rgba(0, 0, 0, 0)); /* Flush against paper */
}

.disc-slide-wrapper.is-peeking {
    transform: var(--peek-transform);
    filter: drop-shadow(12px 18px 24px rgba(0, 0, 0, 0.35));
    transition:
        transform calc(1.2s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        filter calc(1.2s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        z-index 0s 0s;
}

.disc-rotate-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform calc(1s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1);
}

#disc-container {
    width: 100%;
    height: 100%;
}
#disc-container svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Physical 3D Disc Holder (Base Frame) */
.base-wrapper {
    position: absolute;
    width: 104.5%;
    height: 104.5%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10; /* Layer 6: Highest static element */
    pointer-events: none;
}

.base-mark {
    position: absolute;
    top: 1%;
    left: 50%;
    transform: translateX(-50%);
    width: 1.2%;
    height: 3%;
    background-color: #d4d4d4;
    border-radius: 4px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Highlights & Drawing */
.highlighted-label,
.highlighted-label path {
    fill: #ffea00 !important;
    transition: fill 0.25s;
    filter: drop-shadow(0 0 4px rgba(255, 234, 0, 0.8));
}

.drawn-path {
    stroke: #1e293b;
    stroke-width: 18;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: draw calc(1s / var(--anim-speed)) forwards;
}

@keyframes draw {
    to {
        stroke-dashoffset: 0;
    }
}

.drawn-region {
    fill: transparent;
    stroke: none;
    animation: color-in calc(1s / var(--anim-speed)) ease-in-out forwards;
}

@keyframes color-in {
    to {
        fill: #1e293b;
    }
}

/* CSS Pausing State */
.is-paused .drawn-path,
.is-paused .drawn-region {
    animation-play-state: paused !important;
}

/* Drawing Hand & Pencil */
.pencil-hand {
    position: absolute;
    top: 90%;
    left: 85%;
    pointer-events: none;
    z-index: 25; /* Topmost layer */
    opacity: 0;
    filter: drop-shadow(4px 10px 12px rgba(0, 0, 0, 0.28));
    transition:
        left calc(1s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        top calc(1s / var(--anim-speed)) cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.4s ease,
        transform 0.3s ease;
}

/* Style 1: Pencil in Hand */
.pencil-hand.style-hand {
    width: 38%;
    aspect-ratio: 371 / 349;
    transform-origin: 6.74% 17.76%;
    transform: translate(-6.74%, -17.76%);
}

.pencil-hand.style-hand.is-drawing {
    animation: hand-scribble calc(0.35s / var(--anim-speed)) ease-in-out infinite alternate;
}

/* Style 2: Just Pencil (pencil.svg) */
.pencil-hand.style-pencil {
    width: 44%;
    aspect-ratio: 400 / 240;
    transform-origin: 13.3% 21.5%;
    transform: translate(-13.3%, -21.5%);
}

.pencil-hand.style-pencil.is-drawing {
    animation: pencil-scribble calc(0.35s / var(--anim-speed)) ease-in-out infinite alternate;
}

.pencil-hand.is-visible {
    opacity: 1;
}

.pencil-hand img.pencil-img {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes hand-scribble {
    0% {
        transform: translate(-6.74%, -17.76%) rotate(0deg) translate(0px, 0px);
    }
    25% {
        transform: translate(-6.74%, -17.76%) rotate(-1.5deg) translate(-2px, 1px);
    }
    50% {
        transform: translate(-6.74%, -17.76%) rotate(1deg) translate(2px, -2px);
    }
    75% {
        transform: translate(-6.74%, -17.76%) rotate(-0.8deg) translate(1px, 2px);
    }
    100% {
        transform: translate(-6.74%, -17.76%) rotate(1.2deg) translate(-1px, -1px);
    }
}

@keyframes pencil-scribble {
    0% {
        transform: translate(-13.3%, -21.5%) rotate(0deg) translate(0px, 0px);
    }
    25% {
        transform: translate(-13.3%, -21.5%) rotate(-2.5deg) translate(-2px, 1px);
    }
    50% {
        transform: translate(-13.3%, -21.5%) rotate(2deg) translate(1px, -2px);
    }
    75% {
        transform: translate(-13.3%, -21.5%) rotate(-1.5deg) translate(-1px, 2px);
    }
    100% {
        transform: translate(-13.3%, -21.5%) rotate(2.5deg) translate(2px, -1px);
    }
}

.is-paused .pencil-hand {
    animation-play-state: paused !important;
    transition: none !important;
}

/* RESPONSIVE LAYOUT FOR MOBILE / TABLET */
@media (max-width: 859px) {
    :root {
        --disc-size: min(76vw, 38vh);
        --peek-transform: translateX(55%) scale(0.82);
    }
    body {
        flex-direction: column;
    }
    .animation-view {
        flex: 0 0 auto;
        height: 48vh;
        height: 48dvh;
        padding: 16px 12px;
        box-shadow: inset 0 -4px 12px rgba(0, 0, 0, 0.04);
    }
    .controls-view {
        flex: 1;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        padding: 20px 16px;
        gap: 14px;
        background: #ffffff;
    }
    .header-title {
        font-size: 1.25rem;
    }
    select,
    textarea,
    input[type='file'],
    .btn {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    :root {
        --disc-size: min(84vw, 36vh);
        --peek-transform: translateX(45%) scale(0.78);
    }
    .animation-view {
        height: 44vh;
        height: 44dvh;
        padding: 12px;
    }
    .controls-view {
        padding: 16px 14px;
        gap: 12px;
    }
    .control-card {
        padding: 12px;
    }
    .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* EMBED / MINIMAL MODE STYLES */
body.embed-mode {
    background: transparent;
}
body.embed-mode .controls-view {
    display: none !important;
}
body.embed-mode .animation-view {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: 0;
}
body.embed-mode.bg-transparent .animation-view {
    background: transparent !important;
}
body.embed-mode.bg-white .animation-view {
    background: #ffffff !important;
}
