* {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    margin: 0;
    padding: 20px;
    background: #f8f9fa;
    color: #2c3e50;
}

.header-bar {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.utility-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.utility-btn {
    padding: 8px 16px;
    border: 2px solid #4a90e2;
    border-radius: 20px;
    background: white;
    color: #4a90e2;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}

.utility-btn:hover {
    background: #4a90e2;
    color: white;
    transform: translateY(-1px);
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 8px;
    padding: 15px;
    min-width: 280px;
    z-index: 200;
    margin-top: 5px;
}

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

.dropdown-content p {
    margin: 6px 0;
    color: #34495e;
    font-size: 13px;
    line-height: 1.5;
}

.dropdown-content code {
    background: #f0f2f5;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: Monaco, Consolas, monospace;
    font-size: 12px;
    color: #2980b9;
}

.page-title {
    color: #2c3e50;
    font-size: 22px;
    font-weight: 600;
    margin: 8px 0 14px 0;
}

.preset-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.preset-bar label {
    color: #7f8c8d;
    font-size: 14px;
}

#presetSelect {
    padding: 8px 12px;
    border: 2px solid #d8dee5;
    border-radius: 20px;
    background: white;
    color: #2c3e50;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

#presetSelect:focus {
    border-color: #4a90e2;
}

.primary-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 20px;
    background: #4a90e2;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.primary-btn:hover {
    background: #357abd;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74,144,226,0.3);
}

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

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.config-card {
    background: white;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

details.config-card summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

details.config-card summary::-webkit-details-marker {
    display: none;
}

details.config-card summary h3::after {
    content: "▶";
    font-size: 11px;
    margin-left: auto;
    transition: transform 0.2s;
    color: #95a5a6;
}

details[open].config-card summary h3::after {
    transform: rotate(90deg);
}

details.config-card .config-textarea {
    margin-top: 10px;
}

.config-card-rule {
    grid-column: span 2;
}

.config-card h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-card h3::before {
    content: "";
    width: 4px;
    height: 16px;
    background: #4a90e2;
    border-radius: 2px;
}

.config-textarea {
    width: 100%;
    border: 2px solid #e8ecef;
    border-radius: 8px;
    padding: 10px 12px;
    font-family: Monaco, Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    color: #34495e;
    background: #fbfcfd;
}

.config-textarea:focus {
    border-color: #4a90e2;
    background: white;
}

#categoryInput {
    min-height: 180px;
}

#replaceInput {
    min-height: 180px;
}

#ruleInput {
    min-height: 280px;
}

.input-card {
    background: white;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.input-card h3 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-card h3::before {
    content: "";
    width: 4px;
    height: 16px;
    background: #4a90e2;
    border-radius: 2px;
}

.word-textarea {
    width: 100%;
    border: 2px solid #e8ecef;
    border-radius: 8px;
    padding: 10px 12px;
    font-family: Monaco, Consolas, "Courier New", monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    min-height: 100px;
    color: #2c3e50;
    background: #fbfcfd;
    transition: border-color 0.2s;
}

.word-textarea:focus {
    border-color: #4a90e2;
    background: white;
}

.word-textarea.input-error {
    border-color: #e74c3c;
    background: #fdf2f0;
}

.input-error-message {
    color: #e74c3c;
    font-size: 13px;
    margin-top: 6px;
    min-height: 0;
    display: none;
    white-space: pre-line;
    line-height: 1.5;
}

.input-error-message.show {
    display: block;
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.run-btn {
    padding: 10px 24px;
    font-size: 15px;
}

.secondary-btn {
    border: 2px solid #4a90e2;
    border-radius: 20px;
    background: white;
    color: #4a90e2;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.secondary-btn:hover {
    background: #4a90e2;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74,144,226,0.25);
}

.result-card {
    background: white;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.result-card h3 {
    margin: 0 0 12px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-card h3::before {
    content: "";
    width: 4px;
    height: 16px;
    background: #2ecc71;
    border-radius: 2px;
}

.result-area, .debug-area {
    min-height: 60px;
}

.empty-state {
    color: #95a5a6;
    font-size: 14px;
    padding: 16px;
    text-align: center;
    font-style: italic;
}

.error-state {
    color: #e74c3c;
    font-size: 14px;
    padding: 12px;
    background: #fdf2f0;
    border-left: 3px solid #e74c3c;
    border-radius: 4px;
    font-family: Monaco, Consolas, monospace;
}

.result-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

.result-table thead th {
    background: #f0f4f8;
    color: #2c3e50;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 2px solid #d8dee5;
}

.result-table thead th:first-child {
    border-top-left-radius: 6px;
}

.result-table thead th:last-child {
    border-top-right-radius: 6px;
}

.result-table tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid #eef1f4;
    font-family: 'Times New Roman', serif;
    color: #34495e;
}

.result-table tbody tr:last-child td {
    border-bottom: none;
}

.result-table tbody tr:hover {
    background: #fafbfc;
}

.cell-source {
    color: #7f8c8d;
    font-style: italic;
}

.cell-final {
    color: #2980b9;
    font-weight: 600;
}

.cell-stage {
    color: #34495e;
}

.error-row td {
    background: #fdf2f0;
    color: #e74c3c;
    font-family: Monaco, Consolas, monospace;
    font-size: 13px;
}

.debug-block {
    margin-bottom: 16px;
    padding: 12px 14px;
    background: #fbfcfd;
    border-left: 3px solid #4a90e2;
    border-radius: 4px;
}

.debug-word {
    color: #2c3e50;
    font-weight: 600;
    margin-bottom: 8px;
    font-family: 'Times New Roman', serif;
    font-size: 15px;
}

.debug-list {
    margin: 0;
    padding-left: 20px;
    color: #34495e;
    font-family: Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.7;
}

.debug-list li {
    margin: 2px 0;
}

@media (max-width: 760px) {
    .config-grid {
        grid-template-columns: 1fr;
    }
    .config-card-rule {
        grid-column: span 1;
    }
    body {
        padding: 12px;
    }
}

/* Dark Mode */
[data-theme="dark"] body {
    background: #1a1a2e;
    color: #e0e0e0;
}

[data-theme="dark"] .header-bar {
    background: #16213e;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

[data-theme="dark"] .page-title {
    color: #e8e8e8;
}

[data-theme="dark"] .utility-btn {
    background: #1a1a2e;
    border-color: #3a6db5;
    color: #6cb4e8;
}

[data-theme="dark"] .utility-btn:hover {
    background: #3a6db5;
    color: #fff;
}

[data-theme="dark"] .dropdown-content {
    background: #16213e;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="dark"] .dropdown-content p {
    color: #c0c0c0;
}

[data-theme="dark"] .dropdown-content code {
    background: #1a1a2e;
    color: #6cb4e8;
}

[data-theme="dark"] .preset-bar label {
    color: #999;
}

[data-theme="dark"] #presetSelect {
    background: #1a1a2e;
    border-color: #444;
    color: #e0e0e0;
}

[data-theme="dark"] .primary-btn {
    background: #3a6db5;
}

[data-theme="dark"] .primary-btn:hover {
    background: #2a5a9a;
}

[data-theme="dark"] .secondary-btn {
    background: #1a1a2e;
    border-color: #3a6db5;
    color: #6cb4e8;
}

[data-theme="dark"] .secondary-btn:hover {
    background: #3a6db5;
    color: #fff;
}

[data-theme="dark"] .config-card,
[data-theme="dark"] .input-card,
[data-theme="dark"] .result-card {
    background: #16213e;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

[data-theme="dark"] .config-card h3,
[data-theme="dark"] .input-card h3,
[data-theme="dark"] .result-card h3 {
    color: #e8e8e8;
}

[data-theme="dark"] details.config-card summary h3::after {
    color: #666;
}

[data-theme="dark"] .config-textarea,
[data-theme="dark"] .word-textarea {
    background: #1a1a2e;
    border-color: #333;
    color: #e0e0e0;
}

[data-theme="dark"] .config-textarea:focus,
[data-theme="dark"] .word-textarea:focus {
    border-color: #3a6db5;
    background: #1e1e30;
}

[data-theme="dark"] .result-table thead th {
    background: #1a1a2e;
    color: #c0c0c0;
    border-bottom-color: #444;
}

[data-theme="dark"] .result-table tbody td {
    color: #c8c8c8;
    border-bottom-color: #2a2a3e;
}

[data-theme="dark"] .result-table tbody tr:hover {
    background: #1e1e30;
}

[data-theme="dark"] .cell-source {
    color: #888;
}

[data-theme="dark"] .cell-final {
    color: #6cb4e8;
}

[data-theme="dark"] .debug-block {
    background: #1a1a2e;
    border-left-color: #3a6db5;
}

[data-theme="dark"] .debug-word {
    color: #e0e0e0;
}

[data-theme="dark"] .debug-list {
    color: #b0b0b0;
}

[data-theme="dark"] .empty-state {
    color: #666;
}

[data-theme="dark"] .error-state {
    background: #2a1a1a;
    color: #f08080;
}

/* Random Number Generator Panel */
.rng-panel {
    min-width: 260px;
}

.rng-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
}

.rng-row label {
    font-size: 13px;
    color: #7f8c8d;
    min-width: 36px;
}

.rng-row select,
.rng-row input {
    padding: 6px 10px;
    border: 1.5px solid #d8dee5;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: white;
    color: #2c3e50;
    transition: border-color 0.2s;
}

.rng-row select { flex: 1; }
.rng-row input[type="number"] { width: 70px; }
.rng-row input[type="text"] { flex: 1; }

.rng-row select:focus,
.rng-row input:focus {
    border-color: #4a90e2;
}

.rng-gen-btn {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    font-size: 13px;
}

.rng-result {
    margin-top: 10px;
    padding: 8px 10px;
    background: #f0f4f8;
    border-radius: 6px;
    font-family: Monaco, Consolas, monospace;
    font-size: 13px;
    color: #2c3e50;
    min-height: 20px;
    word-break: break-all;
}

.rng-result:empty { display: none; }

[data-theme="dark"] .rng-row label { color: #999; }

[data-theme="dark"] .rng-row select,
[data-theme="dark"] .rng-row input {
    background: #1a1a2e;
    border-color: #444;
    color: #e0e0e0;
}

[data-theme="dark"] .rng-result {
    background: #1a1a2e;
    color: #e0e0e0;
}
