:root {
    --bg: #f1f3f5;
    --panel: #ffffff;
    --line: #d0d7de;
    --text: #111827;
    --muted: #667085;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

body.rtl {
    direction: rtl;
}

.app-wrap {
    width: 100%;
    max-width: 1120px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
}

.topbar-inner {
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.lang-box {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lang-box label {
    color: var(--muted);
    font-size: 0.84rem;
}

.lang-box select {
    width: 82px;
}

main {
    flex: 1 0 auto;
    padding-top: 12px;
}

.block {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    padding: 14px;
}

.controls-card {
    margin-top: 12px;
}

.photo-wrap {
    width: 100%;
    aspect-ratio: 4 / 3;
    min-height: 300px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    padding: 0;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.05),
        0 1px 2px rgba(16, 24, 40, 0.04);
}

.photo-wrap::before,
.photo-wrap::after {
    content: none;
}

#dogPhoto {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
    border-radius: 0;
    transition: opacity 0.18s ease;
}

#dogPhoto.loading {
    opacity: 0.24;
}

#photoLoader {
    position: absolute;
    z-index: 2;
}

.loader-hidden {
    display: none;
}

.action-line {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.action-line::-webkit-scrollbar {
    height: 6px;
}

.action-line::-webkit-scrollbar-thumb {
    background: #c9d4e2;
    border-radius: 99px;
}

.action-btn,
.icon-btn {
    border-radius: 8px;
    white-space: nowrap;
    min-height: 40px;
    font-weight: 600;
}

.icon-btn {
    min-width: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.meta {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #475467;
    font-size: 0.85rem;
}

.source-row {
    margin-top: 6px;
    display: flex;
    gap: 6px;
    align-items: baseline;
    flex-wrap: wrap;
}

.source-label {
    color: #34485e;
    font-size: 0.86rem;
    font-weight: 600;
}

.source-link {
    display: inline-block;
    color: #0f4aa3;
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
    word-break: break-all;
}

.source-link:hover {
    text-decoration: underline;
}

.controls-title {
    display: none;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.field .form-label {
    margin-bottom: 4px;
    font-size: 0.84rem;
    color: var(--muted);
}

.field .form-select {
    border-radius: 10px;
}

.thumb-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.favorites-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.thumb-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    padding: 0;
}

.thumb-item img {
    display: block;
    width: 100%;
    height: 78px;
    object-fit: cover;
}

.thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.74);
    color: #fff;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    padding: 0;
}

.empty-text {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.9rem;
}

.footer {
    margin-top: auto;
    border-top: 1px solid var(--line);
    color: var(--muted);
    background: #fff;
    padding: 10px 0;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.footer-github {
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1;
    text-decoration: none;
}

.footer-github:hover {
    color: #24292f;
}

@media (min-width: 900px) {
    main.app-wrap {
        display: grid;
        grid-template-columns: 1.65fr 1fr;
        gap: 14px;
    }

    .viewer-card {
        grid-column: 1;
    }

    .controls-card {
        grid-column: 2;
        align-self: start;
        margin-top: 0;
    }

    .history-card {
        grid-column: 1 / -1;
        grid-row: 3;
    }

    .photo-wrap {
        min-height: 520px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .thumb-list {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }

    .favorites-list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
