:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --text-color: #e0e0e0;
    --border-color: #333;
    --error-color: #ff8a80;
    --font-family: 'Noto Sans JP', sans-serif;
}

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

html, body {
    width: 100%;
    min-height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    overflow-x: hidden;
}

#api-key-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
    gap: 1.5rem;
    text-align: center;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    max-width: 450px;
    align-items: center;
}

#api-key-input {
    flex-grow: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    color: var(--text-color);
    font-family: var(--font-family);
    height: 50px; 
}

#api-key-input::placeholder {
    color: #888;
}

#submit-api-key {
    height: 50px;
}

.error-message {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: -1rem;
    min-height: 1rem;
}

#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    gap: 1.5rem;
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

#main-app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 1.5rem;
}

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

header p {
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.8;
}

main {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

#camera-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 4 / 3;
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--surface-color);
    border: 2px solid var(--border-color);
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror effect for user convenience */
}

#captured-image {
    width: 100%;
    max-width: 480px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 12px;
    border: 2px solid var(--primary-color);
}

.hidden {
    display: none !important;
}

#controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

button {
    padding: 0.75rem 1.5rem;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    color: #000;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

button:disabled {
    cursor: not-allowed;
    background: var(--surface-color);
    color: #666;
    opacity: 0.7;
    transform: none;
    box-shadow: none;
}

#result-container {
    width: 100%;
    padding: 1.5rem;
    background-color: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

#loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#loader p {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#result-text {
    text-align: left;
    white-space: pre-wrap;
    line-height: 1.8;
}

#result-text:not(.finished)::after {
    content: '▋';
    animation: blink 1s step-end infinite;
    opacity: 1;
    margin-left: 0.2em;
    color: var(--primary-color);
}

@keyframes blink {
    from, to { opacity: 1; }
    50% { opacity: 0; }
}