@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-muted: #5c6370;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --border: #e2e8f0;
    --success: #059669;
    --error: #dc2626;
    --radius: 14px;
    --shadow: 0 2px 12px rgba(26, 26, 46, 0.08);
    --header-bg: #1a1a2e;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    padding-bottom: calc(24px + var(--safe-bottom));
}

.hidden { display: none !important; }

.header {
    background: var(--header-bg);
    color: #fff;
    padding: 20px 16px 16px;
}

.header__inner { max-width: 720px; margin: 0 auto; }

.logo {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    margin-top: 4px;
    font-size: 0.9rem;
    opacity: 0.75;
}

.header__row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.header__logout {
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    color: #fff;
    border-radius: 10px;
    padding: 8px 12px;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.header__user {
    margin-top: 8px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px 22px;
    box-shadow: var(--shadow);
}

.login-card__title {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-card__hint,
.login-card__pwa {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.login-card__pwa {
    margin-top: 20px;
    margin-bottom: 0;
    font-size: 0.8rem;
}

.login-form .field-label:first-child {
    margin-top: 0;
}

.login-remember {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 16px;
    font-size: 0.9rem;
    color: var(--text);
}

.login-remember input {
    width: 18px;
    height: 18px;
}

.login-error {
    color: var(--error);
    font-size: 0.875rem;
    margin-bottom: 12px;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.tabs__btn {
    flex: 1;
    padding: 10px 6px;
    border: none;
    background: transparent;
    font: inherit;
    font-weight: 500;
    font-size: 0.82rem;
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    line-height: 1.25;
}

.tabs__btn--active {
    background: var(--accent-soft);
    color: var(--accent);
}

.main {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

.panel { display: none; }
.panel--active { display: block; }

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card--actions { margin-top: 8px; }

.card--actions .btn--secondary {
    width: 100%;
    margin-top: 8px;
}

.card--actions .btn--secondary:first-of-type {
    margin-top: 0;
}

.card__title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.card__hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.photo-upload {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--bg);
    transition: border-color 0.15s;
}

.photo-upload-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.photo-upload-actions .btn {
    flex: 1;
}

.photo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.photo-placeholder__icon { font-size: 2.5rem; }

.photo-preview {
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: contain;
    display: block;
}

.ref-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.ref-picker--compact {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    margin-bottom: 12px;
}

.ref-item {
    border: 2px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    background: var(--surface);
}

.ref-item:active { transform: scale(0.98); }

.ref-item--selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ref-item img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
}

.ref-item__title {
    padding: 8px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.empty-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 0.9rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    width: 100%;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--accent);
    color: #fff;
}

.btn--primary:not(:disabled):active { background: var(--accent-hover); }

.btn--secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    margin-top: 8px;
}

.btn--outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: auto;
    padding: 10px 16px;
    font-size: 0.9rem;
}

.btn--large { margin-top: 8px; min-height: 52px; }

.input, .textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font: inherit;
    font-size: 1rem;
    margin-bottom: 12px;
    background: var(--surface);
}

.textarea { resize: vertical; min-height: 72px; }

.field-label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
    margin-top: 12px;
}

.field-label:first-child { margin-top: 0; }

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.ref-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-name {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.refs-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ref-card {
    display: flex;
    gap: 12px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
    align-items: center;
}

.ref-card img {
    width: 88px;
    height: 66px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.ref-card__body { flex: 1; min-width: 0; }

.ref-card__title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.ref-card__delete {
    background: none;
    border: none;
    color: var(--error);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.history-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.history-card__date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.history-card__ref {
    font-weight: 600;
    font-size: 0.95rem;
}

.history-card__hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.history-card__delete {
    background: none;
    border: none;
    color: var(--error);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
    flex-shrink: 0;
}

.history-card__sources {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
}

.history-card__source {
    flex: 1;
    min-width: 0;
}

.history-card__source-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.history-card__source img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 10px;
    display: block;
}

.history-card__variants {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}

.history-card__variant img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 10px;
    display: block;
}

.history-card__variant-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    text-align: center;
    margin-top: 6px;
    color: var(--text-muted);
}

.history-card__variant {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-card__video {
    width: 100%;
    border-radius: 10px;
    background: #000;
    max-height: 240px;
}

.history-card__video-btn {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.history-card__video-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

@media (min-width: 560px) {
    .tabs__btn { font-size: 0.9rem; padding: 12px 8px; }
}

.loading {
    text-align: center;
    padding: 40px 16px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading__sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.loading-progress {
    max-width: 320px;
    margin: 16px auto 0;
}

.loading-progress__track {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.loading-progress__bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #60a5fa);
    border-radius: 999px;
    transition: width 0.4s ease;
}

.loading-progress__label {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 10px;
    text-align: center;
}

.variant-card__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 12px 12px;
}

.variant-card__regen {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.variant-card__regen:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.results__header {
    margin-bottom: 16px;
}

.results__header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.results__hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.variants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

@media (min-width: 560px) {
    .variants-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

.variant-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 3px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s;
}

.variant-card--selected {
    border-color: var(--accent);
}

.variant-card img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
}

.variant-card__label {
    padding: 12px;
    font-weight: 600;
    text-align: center;
    font-size: 0.95rem;
}

.variant-video {
    margin-top: 16px;
}

.variant-video__title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.variant-video__player {
    width: 100%;
    border-radius: var(--radius);
    background: #000;
    max-height: 420px;
}

.toast {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    left: 16px;
    right: 16px;
    max-width: 400px;
    margin: 0 auto;
    padding: 14px 18px;
    background: var(--header-bg);
    color: #fff;
    border-radius: 12px;
    font-size: 0.9rem;
    text-align: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.toast--error { background: var(--error); }

.pwa-install {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(88px + var(--safe-bottom));
    z-index: 190;
    max-width: 400px;
    margin: 0 auto;
}

.pwa-install__inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.pwa-install__text {
    flex: 1;
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.35;
}

.pwa-install__btn {
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.pwa-install__close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.zoomable-img {
    cursor: zoom-in;
}

.debug-prompts {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border: 1px dashed var(--border);
}

.debug-prompts summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    user-select: none;
}

.debug-prompts__body {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.debug-prompt-block__title {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.debug-prompt-block__label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-top: 8px;
}

.debug-prompt-block__label:first-child {
    margin-top: 0;
}

.debug-prompt-block pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, 'Cascadia Code', monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    max-height: none;
    overflow: visible;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(3, 3, 3, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.lightbox__close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
}

.lightbox__img {
    max-width: 100%;
    max-height: calc(100vh - 80px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    object-fit: contain;
    border-radius: 4px;
}

.lightbox__caption {
    margin-top: 12px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    text-align: center;
    max-width: 90%;
}

@media (min-width: 768px) {
    .header { padding: 28px 24px 20px; }
    .logo { font-size: 1.5rem; }
    .main { padding: 24px; }
    .tabs { padding: 8px 24px; max-width: 720px; margin: 0 auto; }
}
