/*
 * TermFlip - A memory match game for learning
 * © 2024 Tarushv Kosgi. All rights reserved.
 */
:root {
    /* Light theme */
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --background-color: #f5f6fa;
    --card-color: #ffffff;
    --text-color: #2c3e50;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --primary-color: #ecf0f1;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --background-color: #2c3e50;
    --card-color: #34495e;
    --text-color: #ecf0f1;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Helvetica, "Helvetica Neue", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.screen {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.screen.active {
    display: block;
    opacity: 1;
}

/* Input Screen Styles */
.instruction-panel {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

h1#title {
    transition: color 0.3s ease;
}

h1#title:hover {
    color: var(--secondary-color);
    cursor: pointer;
}

.tagline {
    font-size: 1.2rem;
    color: var(--secondary-color);
    margin-bottom: 2rem;
}

.format-examples {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    margin: 2rem auto;
    max-width: 800px;
    padding: 0 1rem;
}

.json-example, .text-example {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Change to left align */
    width: 100%;
    min-height: 150px;
    position: relative;
    margin-bottom: 1rem;
}

.json-example h3, .text-example h3 {
    width: 100%;
    text-align: center; /* Center align */
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.text-example .note {
    width: 100%;
    text-align: left; /* Change to left align */
    font-size: 0.9rem;
    margin-top: 0.75rem;
    color: var(--text-color);
    opacity: 0.8;
}

.pre-wrapper {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    direction: ltr; /* Add LTR direction for the wrapper */
}

pre {
    background: var(--card-color);
    color: var(--text-color);
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    border: 2px solid #ddd;
    font-family: 'Courier New', Courier, monospace;
    transition: var(--transition);
    position: static;
    width: 100%;
    text-align: left;
    direction: ltr; /* Add LTR direction */
}

pre:hover {
    border-color: var(--secondary-color);
}

/* Add specific styling for pre content to maintain proper text direction */
pre code, 
pre span {
    direction: ltr; /* Add LTR direction */
    display: block;
    text-align: left;
    width: 100%;
}

pre code {
    display: block;
    text-align: left;
    direction: ltr;
}

.input-area {
    max-width: 800px;
    margin: 0 auto;
}

textarea {
    width: 800px;
    max-width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-family: monospace;
    resize: vertical;
    transition: var(--transition);
}

textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.input-feedback {
    min-height: 24px;
    margin: 0.5rem 0;
    color: var(--accent-color);
}

/* Button Styles */
.primary-button, .secondary-button {
    padding: 0.8rem 2rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    margin: 0.5rem;
}

.primary-button {
    background-color: var(--secondary-color);
    color: white;
}

.secondary-button {
    background-color: transparent;
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
}

.primary-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Game Screen Styles */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.game-stats {
    font-size: 1.2rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    perspective: 1000px;
}

.card {
    position: relative;
    height: 150px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

.card.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    border-radius: 8px;
    background: var(--card-color);
    box-shadow: var(--shadow);
}

.card-back {
    background-color: var(--secondary-color);
    color: white;
}

.card-front {
    background-color: var(--card-color);
    transform: rotateY(180deg);
}

.card.matched {
    transform: rotateY(180deg); /* Keep cards flipped */
}

.card.matched.pulse {
    animation: matchPulse 0.5s ease-out;
}

.card.matched .card-front {
    background-color: var(--card-color);
    border: 2px solid var(--secondary-color); /* Add a subtle border to highlight matched pairs */
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--card-color);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    transform: translateY(-20px);
    transition: var(--transition);
}

.modal.visible .modal-content {
    transform: translateY(0);
}

@keyframes matchPulse {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
    100% { transform: rotateY(180deg) scale(1); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .format-examples {
        padding: 0 1rem;
    }
    
    .example-content,
    .json-example h3,
    .text-example h3,
    .text-example .note {
        width: 100%;
        min-width: unset;
    }
    
    .code-block pre {
        width: 100%;
        min-width: unset;
    }
    
    .game-header {
        flex-direction: column;
        gap: 1rem;
    }

    .code-block pre {
        width: 100%;
        min-width: unset;
    }
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--card-color);
    border: 2px solid var(--secondary-color);
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 1000;
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.theme-toggle .icon {
    font-size: 1.2rem;
}

/* Copyright Footer */
.copyright {
    text-align: center;
    padding: 1rem;
    margin-top: 2rem;
    color: var(--text-color);
    opacity: 0.8;
    font-size: 0.9rem;
}

.example-content {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    direction: ltr; /* Change to LTR direction */
}

.example-content table {
    width: 100%;
}

.example-content td {
    text-align: left; /* Change to left align */
}

.code-block {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    direction: ltr; /* Change to LTR direction */
}

.code-block table {
    width: 100%;
    border-spacing: 0;
    background: var(--card-color);
    padding: 1.5rem;
    border-radius: 8px;
    border: 2px solid #ddd;
    font-family: monospace;
}

.code-block td {
    text-align: left; /* Change to left align */
    white-space: pre;
    padding: 0;
    line-height: 1.5;
}

/* Ensure consistent spacing */
.code-block tr:not(:last-child) td {
    padding-bottom: 0.25rem;
}

.code-block pre {
    width: 100%;
    padding: 1.5rem;
    border-radius: 8px;
    border: 2px solid #ddd;
    background: var(--card-color);
    text-align: left;
    white-space: pre;
    direction: ltr; /* Change to LTR direction */
}

/* Remove all complex layout systems */
.code-block pre,
.code-block pre * {
    display: block;
    width: 100%;
}

/* Ensure each line of text is left aligned */
.code-block pre br + *,
.code-block pre > * {
    text-align: left;
}

/* Reset any conflicting styles */
.pre-wrapper,
.example-content,
.example-content table,
.example-content td {
    width: 100%;
    text-align: left;
}

.text-example {
    margin-top: 1rem;  /* Add space between JSON and text examples */
}