:root {
    font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    font-weight: 400;
    color: #213547;
    background-color: #ffffff;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    display: flex;
    justify-content: center;
    min-width: 320px;
    min-height: 100vh;
}

#app {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
    text-align: center;
}

.app-container {
    width: 100%;
}

/* Loading screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.loading-text {
    font-size: 1.2em;
    color: #646cff;
    margin-top: 1rem;
}

.loading-progress {
    width: 80px;
    height: 80px;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 3px;
}

.loading-progress circle:last-child {
    stroke: #646cff;
    stroke-dasharray: 251.33;
    animation: loading-spin 1.5s linear infinite;
    transform-origin: center;
}

@keyframes loading-spin {
    0% { stroke-dashoffset: 251.33; transform: rotate(0deg); }
    50% { stroke-dashoffset: 62.83; }
    100% { stroke-dashoffset: 251.33; transform: rotate(360deg); }
}

/* Main counter */
.domino-counter {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.domino-counter h1 {
    font-size: 1.8em;
    line-height: 1.1;
    margin: 0.5rem 0;
    color: #1a1a2e;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 1.1em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.25s, opacity 0.25s;
    text-decoration: none;
    font-family: inherit;
}

.btn.primary {
    background-color: #646cff;
    color: white;
}

.btn.primary:hover {
    background-color: #535bf2;
}

.btn.ghost {
    background: transparent;
    border: 1px solid #646cff;
    color: #646cff;
}

.btn.ghost:hover {
    background: rgba(100, 108, 255, 0.1);
}

.btn.gray {
    background-color: #6c757d;
    color: white;
}

.btn.gray:hover {
    background-color: #5a6268;
}

.btn.small {
    padding: 6px 14px;
    font-size: 1em;
    font-weight: 700;
    min-width: 40px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Tips overlay */
.tips-overlay {
    background: rgba(100, 108, 255, 0.08);
    border: 1px solid rgba(100, 108, 255, 0.2);
    border-radius: 12px;
    padding: 16px 20px;
    width: 100%;
    text-align: left;
}

.tips-overlay p {
    margin: 6px 0;
    font-size: 0.95em;
    color: #555;
    padding-left: 8px;
    border-left: 3px solid #646cff;
}

/* Capture section */
.capture-section {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Preview */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    width: 100%;
}

.image-preview {
    max-width: 100%;
    max-height: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.action-section {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* Processing */
.processing-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 0;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e0e0e0;
    border-top-color: #646cff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-text {
    font-size: 1.2em;
    color: #646cff;
    font-weight: 500;
}

/* Results */
.results-section {
    width: 100%;
    text-align: left;
}

.results-section h2 {
    text-align: center;
    color: #1a1a2e;
    margin-bottom: 16px;
}

.results-list {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    font-size: 1.1em;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.result-label {
    font-weight: 500;
    color: #333;
}

.correction-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pip-count {
    font-size: 1.3em;
    font-weight: 700;
    color: #2ecc71;
    min-width: 32px;
    text-align: center;
    margin-left: auto;
}

/* Grand total */
.grand-total {
    margin-top: 16px;
    border-top: 2px solid #646cff;
    padding-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.grand-total h3 {
    margin: 0;
    color: #646cff;
    font-size: 1.4em;
}

/* Error */
.error {
    color: #e74c3c;
    background: #fdeaea;
    padding: 12px 16px;
    border-radius: 8px;
    white-space: pre-line;
    width: 100%;
    text-align: left;
}

/* Blazor error UI */
#blazor-error-ui {
    background: #e74c3c;
    color: white;
    padding: 8px 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    display: none;
    z-index: 1000;
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: 8px;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: 16px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color: rgba(255, 255, 255, 0.87);
        background-color: #242424;
    }

    .domino-counter h1 {
        color: #ffffff;
    }

    .results-section h2 {
        color: #ffffff;
    }

    .result-label {
        color: #ddd;
    }

    .result-item {
        border-bottom-color: #444;
    }

    .tips-overlay {
        background: rgba(100, 108, 255, 0.12);
        border-color: rgba(100, 108, 255, 0.3);
    }

    .tips-overlay p {
        color: #bbb;
    }

    .btn.small {
        background: #333;
        color: #fff;
        border-color: #555;
    }
}

/* Examples Overlay */
.examples-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 2000;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-align: left;
}

@media (prefers-color-scheme: dark) {
    .examples-overlay {
        background: #242424;
    }
}

.examples-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #646cff;
    padding-bottom: 10px;
    position: sticky;
    top: 0;
    background: inherit;
}

.examples-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.examples-section h3 {
    margin: 0;
    padding: 4px 8px;
    border-radius: 4px;
}

.examples-section.good h3 {
    background: #e8f8f5;
    color: #16a085;
}

.examples-section.bad h3 {
    background: #fdf2f2;
    color: #e74c3c;
}

@media (prefers-color-scheme: dark) {
    .examples-section.good h3 {
        background: #1b4d3e;
        color: #2ecc71;
    }

    .examples-section.bad h3 {
        background: #4a1c1c;
        color: #ff6b6b;
    }
}

.example-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.example-image {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
    background: #f0f0f0;
}

.example-desc {
    font-size: 1.1em;
    line-height: 1.5;
    color: #333;
    font-weight: 500;
}

@media (prefers-color-scheme: dark) {
    .example-image {
        background: #333;
    }
    .example-desc {
        color: #ddd;
    }
}

.examples-bullets {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 12px;
    border-left: 5px solid #646cff;
}

@media (prefers-color-scheme: dark) {
    .examples-bullets {
        background: #2d2d2d;
    }
}

.examples-bullets ul {
    margin: 0;
    padding-left: 20px;
}

.examples-bullets li {
    margin-bottom: 8px;
    font-size: 1.1em;
}
