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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #F5F0FF 0%, #F0EAFF 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: #1f2937;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #F5F0FF;
}

header h1 {
    font-size: 2.5rem;
    color: #4908C2;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    color: #6b7280;
    font-size: 1.1rem;
}

.blank-counter {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #4908C2;
    padding: 0.4rem 0.8rem;
    background: #F5F0FF;
    border-radius: 0.5rem;
    display: inline-block;
    z-index: 10;
    pointer-events: none;
}

.accuracy-counter {
    position: absolute;
    top: 3.5rem;
    right: 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #4908C2;
    padding: 0.4rem 0.8rem;
    background: #F5F0FF;
    border-radius: 0.5rem;
    display: none;
    z-index: 10;
    pointer-events: none;
}

.accuracy-counter:not(:empty) {
    display: inline-block;
}

.instructions {
    background: #F8FCFF;
    border-left: 4px solid #4908C2;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
}

.instructions p {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #4908C2;
}

.instructions ul {
    list-style-position: inside;
    color: #4b5563;
}

.instructions li {
    margin-bottom: 0.5rem;
}

.input-section {
    margin-bottom: 2rem;
}

#textInput {
    width: 100%;
    height: 150px;
    padding: 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    transition: border-color 0.3s ease;
    background: white;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

#textInput:focus {
    outline: none;
    border-color: #4908C2;
}

#textInput:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
    pointer-events: none;
}

.btn-primary {
    background: #4908C2;
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 1rem;
    width: 100%;
}

.btn-primary:hover {
    background: #3a07a0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(73, 8, 194, 0.3);
}

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

.btn-retest {
    background: #059669;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-retest:hover {
    background: #047857;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

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

.btn-reset {
    background: #dc2626;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-reset:hover {
    background: #b91c1c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

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

.output-section {
    margin-top: 2rem;
}

.output-header {
    position: relative;
    margin-bottom: 0.5rem;
}

.bracket-selector-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bracket-selector-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4908C2;
    margin: 0;
}

.custom-dropdown {
    position: relative;
    min-width: 180px;
}

.dropdown-toggle {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: inherit;
    color: #4b5563;
    background: white;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.3s ease;
}

.dropdown-toggle:hover {
    border-color: #4908C2;
}

.dropdown-arrow {
    font-size: 0.75rem;
    color: #6b7280;
    transition: transform 0.3s ease;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.25rem;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    min-width: 100%;
    padding: 0.5rem 0;
}

.dropdown-action-buttons {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.25rem;
}

.dropdown-action-btn {
    flex: 1;
    padding: 0.4rem 0.8rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #4b5563;
    transition: all 0.2s ease;
}

.dropdown-action-btn:hover {
    background: #4908C2;
    color: white;
    border-color: #4908C2;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #4b5563;
    user-select: none;
    transition: background-color 0.2s ease;
}

.dropdown-option:hover {
    background-color: #f5f0ff;
}

.dropdown-option input[type="checkbox"] {
    cursor: pointer;
    width: 1.1rem;
    height: 1.1rem;
    accent-color: #4908C2;
}

.color-picker-section {
    padding: 0.75rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #f9fafb;
    margin-top: 0.5rem;
}

.color-picker-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4908C2;
    margin-bottom: 0.5rem;
}

.color-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.color-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
}

.color-preview {
    width: 24px;
    height: 24px;
    border: 2px solid #d1d5db;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-preview.color-selected {
    border-color: #4908C2;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(73, 8, 194, 0.2);
}

.color-preview:not(.color-selected) {
    opacity: 1;
    border-color: #d1d5db;
}

.color-item input[type="color"] {
    width: 0;
    height: 0;
    opacity: 0;
    position: absolute;
}

.remove-color-btn {
    background: #dc2626;
    color: white;
    border: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.remove-color-btn:hover {
    background: #b91c1c;
}

.add-color-btn {
    background: #059669;
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    font-weight: bold;
}

.add-color-btn:hover {
    background: #047857;
}

.output-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.btn-secondary {
    background: #1e3a8a;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: #1e40af;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
}

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

.output-area {
    position: relative;
    min-height: 200px;
    padding: 1.5rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #fafafa;
    font-size: 1.1rem;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    overflow-x: auto;
}

/* Make wrapper be the layout unit */
.output-area .blank-button-wrapper {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    max-width: 100%;
    line-height: normal;
    margin: 0.125rem 0;
}

/* Only reserve space when feedback is visible */
.output-area .blank-button-wrapper.show-feedback {
    padding-right: 3.75rem; /* space for ✓ ✗ */
}

/* Feedback sits on the right, doesn't affect line-breaking */
.output-area .blank-button-wrapper .feedback-buttons {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    z-index: 1;
}

.output-section:fullscreen {
    background: white;
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.output-section:fullscreen .output-header {
    margin-bottom: 1rem;
}

.output-section:fullscreen .output-area {
    font-size: 1.5rem;
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

.output-section:fullscreen .blank-counter {
    top: 2rem;
    right: 2rem;
    font-size: 1.1rem;
    padding: 0.5rem 1rem;
}

.output-section:fullscreen .accuracy-counter {
    top: 5rem;
    right: 2rem;
    font-size: 1.1rem;
    padding: 0.5rem 1rem;
}

.output-section:fullscreen .blank-button {
    font-size: 1.5rem;
    padding: 0.5rem 0.75rem;
}

/* The actual blank must clip inside the wrapper */
.blank-button {
    background: rgba(0, 0, 0, 0.03);
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    margin: 0.125rem 0;
    padding: 0;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    line-height: inherit;
    vertical-align: middle;
    display: inline-block !important;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}

/* Blank button should size to content, but wrapper will clamp if it would exceed line */
.output-area .blank-button {
    vertical-align: middle;
}

/* Answer state: allow wrapping to show full answer */
.output-area .blank-button[data-state="answer"] {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.blank-button.correct-answer {
    background: rgba(5, 150, 105, 0.2);
}

.blank-button.wrong-answer {
    background: rgba(220, 38, 38, 0.2);
}

.blank-button * {
    line-height: 1.8;
    vertical-align: middle;
    margin: 0;
    padding: 0;
    display: inline !important;
    font-size: inherit;
}

/* Preserve superscript and subscript formatting */
.blank-button sup,
.blank-button sub {
    font-size: 0.83em;
    line-height: 0;
    position: relative;
    vertical-align: middle;
    display: inline !important;
}

.blank-button sup {
    top: -0.5em;
}

.blank-button sub {
    bottom: -0.25em;
}

.blank-button div,
.blank-button p,
.blank-button br {
    display: inline !important;
}

.blank-button br::before {
    content: ' ';
}

.blank-button:hover {
    background: rgba(37, 99, 235, 0.1);
    transform: none;
}


/* .blank-button-wrapper rule removed - using .output-area .blank-button-wrapper instead with inline-block */

/* .feedback-buttons styling is now handled by .output-area .blank-button-wrapper .feedback-buttons above */

.feedback-btn {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid #e5e7eb;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
}

.feedback-btn:hover {
    transform: scale(1.1);
    border-color: #4908C2;
}

.feedback-check {
    color: #059669;
}

.feedback-check:hover {
    background: #d1fae5;
    border-color: #059669;
}

.feedback-check.active {
    background: #059669;
    color: white;
    border-color: #059669;
}

.feedback-x {
    color: #dc2626;
}

.feedback-x:hover {
    background: #fee2e2;
    border-color: #dc2626;
}

.feedback-x.active {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}

footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 2px solid #F5F0FF;
    color: #6b7280;
    font-size: 0.9rem;
}

footer p {
    margin: 0;
}

footer p.privacy-note {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #9ca3af;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1.5rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .output-area {
        font-size: 1rem;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 1rem 0.5rem;
    }
    
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
}
