/* --- CSS Variables (New Dark Theme) --- */
:root {
    --primary-color: #8A2BE2; /* A vibrant purple */
    --secondary-color: #00BFFF; /* A bright cyan */
    --accent-gradient: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    
    --background-color: #121019; /* Very dark navy/purple */
    --card-background: #1e1b29; /* Lighter dark shade */
    --border-color: #3a364b;
    --text-color: #e0e0e0;
    --text-muted: #9a9a9a;
    --text-dark-on-light: #121019;

    --error-color: #ff4757;
    --heads-gradient: linear-gradient(135deg, #FFD700, #F0A500); /* Gold */
    --tails-gradient: linear-gradient(135deg, #C0C0C0, #8A95A5); /* Silver */

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --border-radius: 12px;
    --box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    --transition-speed: 0.3s ease;
}

/* --- Global Reset & Body Styling --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- App Layout (Sidebar + Content) --- */
.app-container {
    display: flex;
    flex: 1;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* --- Sidebar Navigation --- */
.sidebar {
    width: 260px;
    background-color: var(--card-background);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    flex-shrink: 0;
}

.sidebar-header {
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0 0.5rem;
}

.nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-button {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: var(--transition-speed);
}

.nav-button svg {
    stroke: var(--text-muted);
    transition: var(--transition-speed);
    flex-shrink: 0;
}

.nav-button:hover {
    background-color: var(--background-color);
    color: var(--text-color);
}
.nav-button:hover svg {
    stroke: var(--text-color);
}

.nav-button.active {
    background: var(--accent-gradient);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
}
.nav-button.active svg {
    stroke: #ffffff;
}

/* --- Main Tool Content --- */
.tool-content {
    flex: 1;
    padding: 2.5rem;
    overflow-y: auto;
}

/* --- Tool Panel Styling --- */
.tool-panel {
    display: none; /* Hidden by default */
    max-width: 800px;
    margin: 0 auto;
}

.tool-panel.active {
    display: block;
    animation: fadeIn 0.5s ease-out; /* Fade-in animation */
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.tool-card {
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.tool-card h2 {
    font-weight: 700;
    font-size: 1.75rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.description {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* --- Form & Input Elements --- */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.sr-only { /* For accessibility, hides label visually */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

input[type="number"],
textarea {
    width: 100%;
    padding: 0.85rem 1rem;
    font-family: var(--font-family);
    font-size: 1rem;
    background-color: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
    transition: var(--transition-speed);
}

input[type="number"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(138, 43, 226, 0.3);
}

textarea {
    resize: vertical;
    min-height: 140px;
}

.form-controls {
    display: flex;
    gap: 1.5rem;
}
.input-group {
    flex: 1;
}

/* --- Button Styling --- */
.button-group {
    display: flex;
    gap: 1rem;
}

.primary-btn,
.secondary-btn {
    flex: 1;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-speed);
    transform: scale(1);
}

.primary-btn {
    background: var(--accent-gradient);
    background-size: 200% 100%;
    background-position: left;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
}

.primary-btn:hover {
    background-position: right;
    box-shadow: 0 6px 16px rgba(0, 191, 255, 0.3);
    transform: scale(1.02);
}

.secondary-btn {
    background-color: var(--border-color);
    color: var(--text-color);
}

.secondary-btn:hover {
    background-color: #4a465b; /* Slightly lighter border color */
    transform: scale(1.02);
}

.primary-btn:active,
.secondary-btn:active {
    transform: scale(0.98);
}

.secondary-btn.small {
    flex: 0 1 auto;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
}

/* --- Result & Info Display --- */
.result-box {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 160px;
    background-color: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
}

.result-text {
    font-size: 4.5rem;
    font-weight: 700;
    color: var(--text-color);
    text-align: center;
    word-wrap: break-word;
    line-height: 1.2;
}
/* Animation for result text */
.result-text.animate {
    animation: popIn 0.3s ease-out;
}
@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8); }
    70% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

.result-container.secondary {
    text-align: center;
    background: var(--background-color);
    padding: 0.75rem;
    border-radius: var(--border-radius);
}
.result-container.secondary h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}
.result-container.secondary p {
    font-size: 1.25rem;
    color: var(--text-color);
}

.info-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

.error-message {
    color: var(--error-color);
    font-weight: 600;
    display: none; /* Hidden by default */
    text-align: center;
    background: rgba(255, 71, 87, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
}

/* --- V2: 3D Coin Flipper --- */
.coin-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}
.coin-wrapper {
    perspective: 1000px; /* This enables the 3D space */
    width: 150px;
    height: 150px;
}
.coin {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d; /* This is crucial for 3D */
    transition: transform 1s cubic-bezier(0.3, 0, 0.3, 1);
}
/* These classes will be added by JS */
.coin.flip-heads {
    transform: rotateY(1800deg); /* 5 full spins */
}
.coin.flip-tails {
    transform: rotateY(1980deg); /* 5.5 spins (1800 + 180) */
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden; /* Hides the back of the element */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-dark-on-light);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.2), 0 4px 10px rgba(0,0,0,0.3);
}
.coin-front {
    background: var(--heads-gradient);
    z-index: 2;
}
.coin-back {
    background: var(--tails-gradient);
    transform: rotateY(180deg); /* Flips this face to the back */
}
.result-display-sub {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Coin History */
.history-container {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
#flip-history {
    list-style: none;
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--background-color);
}
#flip-history li {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
}
#flip-history li:last-child { border-bottom: none; }
#flip-history li.heads {
    font-weight: 600;
    color: #FFD700;
}
#flip-history li.tails {
    font-weight: 600;
    color: #C0C0C0;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

/* --- Responsive Design --- */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
    }
    .sidebar-header {
        display: none; /* Hide header on mobile nav */
    }
    .nav-list {
        flex-direction: row;
        gap: 0.5rem;
    }
    .nav-button {
        padding: 0.75rem;
        flex-direction: column;
        gap: 0.25rem;
    }
    .nav-button span {
        font-size: 0.75rem;
    }
    .tool-content {
        padding: 1.5rem;
    }
    .tool-card {
        padding: 1.5rem;
    }
    .result-text {
        font-size: 3rem;
    }
    .coin-wrapper {
        width: 120px;
        height: 120px;
    }
    .coin-face {
        font-size: 3rem;
    }
    .form-controls {
        flex-direction: column;
        gap: 1rem;
    }
}
