:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #64748b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 3rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.main-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.editor-section {
    margin-bottom: 1.5rem;
    position: relative;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.editor-section label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 1rem;
    margin: 0;
}

.highlight-toggle {
    display: flex;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.highlighted-view {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    font-size: 1rem;
    font-family: 'Monaco', 'Courier New', monospace;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    display: none;
    cursor: text;
}

.highlighted-view.active {
    display: block;
}

#inputText {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    font-size: 1rem;
    font-family: 'Monaco', 'Courier New', monospace;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    transition: all 0.2s;
    resize: vertical;
    line-height: 1.5;
}

#inputText.hidden {
    display: none;
}

#inputText:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.highlighted-view:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Byte size highlighting */
.byte-1 {
    background-color: #dbeafe;
    color: #1e40af;
}

.byte-2 {
    background-color: #fce7f3;
    color: #9f1239;
}

.byte-3 {
    background-color: #fef3c7;
    color: #92400e;
}

.byte-4 {
    background-color: #d1fae5;
    color: #065f46;
}

/* Legend */
.legend {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    transition: opacity 0.2s;
}

.legend.hidden {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.legend-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    flex: 1;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--background);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    flex: 1;
}

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

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

.size-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.size-card {
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.size-card:hover {
    transform: translateY(-2px);
}

.size-card.bytes {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.size-card.kilobytes {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.size-card.megabytes {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.size-value {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
    font-family: 'Monaco', 'Courier New', monospace;
}

.size-label {
    font-size: 0.875rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Monaco', 'Courier New', monospace;
}

.encoding-info {
    padding: 1.5rem;
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.encoding-info h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#encodingDetails {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.encoding-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.encoding-type {
    font-family: 'Monaco', 'Courier New', monospace;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.encoding-count {
    font-weight: 600;
    color: var(--text-primary);
}

.encoding-bytes {
    color: var(--primary-color);
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
}

.info-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.info-section h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.info-section ul {
    list-style: none;
    padding-left: 0;
    margin-bottom: 1.5rem;
}

.info-section li {
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
    position: relative;
    color: var(--text-secondary);
}

.info-section li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: 600;
}

.info-section li strong {
    color: var(--text-primary);
}

.example {
    padding: 1rem;
    background: var(--background);
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    color: var(--text-secondary);
}

.example strong {
    color: var(--text-primary);
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .header h1 {
        font-size: 2rem;
    }

    .main-content {
        padding: 1.5rem;
    }

    .size-cards {
        grid-template-columns: 1fr;
    }

    .stats-section {
        grid-template-columns: repeat(2, 1fr);
    }

    .size-value {
        font-size: 2rem;
    }

    #inputText {
        min-height: 150px;
    }
}