:root {
    --bg: #070605;
    --ivory: #f4efe6;
    --champagne: #e4d2b0;
    --gold: #c6a36a;
    --copper: #b87333;
    --ruby: #9a2a3a;
    --bordeaux: #6e1c2b;
    --muted: rgba(228, 210, 176, 0.72);
    --line: rgba(198, 163, 106, 0.38);
    --serif: "Cormorant Garamond", "Times New Roman", serif;
    --sans: Karla, "Helvetica Neue", sans-serif;
}

.sommelier,
.sommelier * { box-sizing: border-box; }

.som-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sommelier {
    position: relative;
    height: calc(100dvh - 172px);
    min-height: 640px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    background: var(--bg);
    color: var(--ivory);
    color-scheme: dark;
    font-family: var(--sans);
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
}

.som-top {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 14px 20px 6px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    z-index: 3;
}

.som-logo {
    display: flex;
    align-items: center;
    line-height: 0;
}

.som-logo img {
    width: auto;
    height: 18px;
}

.som-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--champagne);
}

.som-status i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 0 0 rgba(198, 163, 106, 0.4);
}

.som-stage {
    position: relative;
    z-index: 1;
    min-height: 0;
}

.som-core {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.som-core::before {
    content: "";
    position: absolute;
    left: 6%;
    right: 6%;
    top: 16%;
    bottom: 16%;
    background: radial-gradient(circle, rgba(120, 24, 40, 0.28) 0%, transparent 68%);
    pointer-events: none;
}

.som-core canvas,
.som-core-plate {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.sommelier [hidden] {
    display: none !important;
}

.som-dock {
    position: absolute;
    inset: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 16px 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    z-index: 2;
}

.som-panel,
.som-shelf:not(.is-empty) {
    border: 1px solid rgba(198, 163, 106, 0.2);
    border-radius: 18px;
    background: transparent;
}

.som-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px 14px 10px;
    background: rgba(7, 6, 5, 0.28);
}

.som-shelf {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 34%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
}

.som-shelf.is-empty {
    max-height: none;
    padding: 2px 4px 0;
    background: transparent;
    border: 0;
    backdrop-filter: none;
}

.som-shelf-label {
    margin: 0;
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(198, 163, 106, 0.8);
}

.som-shelf-empty {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.4;
    color: rgba(228, 210, 176, 0.55);
}

.som-intro {
    margin-top: 0;
}

.som-restart {
    align-self: flex-start;
    margin: 0 0 12px;
    padding: 8px 14px;
    border: 1px solid rgba(198, 163, 106, 0.62);
    border-radius: 999px;
    background: rgba(7, 6, 5, 0.55);
    color: var(--champagne);
    font-family: var(--sans);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    cursor: pointer;
}

.som-restart:hover,
.som-restart:focus-visible {
    border-color: var(--champagne);
    color: var(--ivory);
    background: rgba(110, 28, 43, 0.45);
    outline: none;
}

.som-thread {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(198, 163, 106, 0.35) transparent;
}

.som-log {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding-bottom: 4px;
}

.som-turn + .som-turn {
    padding-top: 16px;
    border-top: 1px solid rgba(198, 163, 106, 0.16);
}

.som-kicker {
    margin: 0 0 6px;
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--gold);
}

.som-title {
    margin: 0;
    max-width: 16ch;
    font-family: var(--serif);
    font-weight: 500;
    font-size: 1.9rem;
    line-height: 0.98;
    letter-spacing: -0.02em;
    color: var(--ivory);
}

.som-lead,
.som-answer {
    max-width: 42rem;
    margin: 10px 0 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: rgba(244, 239, 230, 0.86);
}

.som-answer {
    max-width: 40rem;
    margin: 14px 0 0;
    padding: 10px 14px 12px;
    border-left: 2px solid rgba(198, 163, 106, 0.75);
    background: rgba(7, 6, 5, 0.62);
    font-family: var(--serif);
    font-size: 1.28rem;
    font-weight: 500;
    line-height: 1.4;
    color: #fff8f0;
}

.som-turn:not(.is-pending) .som-progress { display: none; }

.som-ask {
    width: fit-content;
    max-width: min(82%, 34rem);
    margin: 0 0 0 auto;
    padding: 10px 14px;
    border: 1px solid rgba(198, 163, 106, 0.32);
    border-radius: 16px 16px 4px 16px;
    background: rgba(7, 6, 5, 0.42);
    font-family: var(--sans);
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    color: var(--champagne);
}

.som-progress {
    width: 72px;
    height: 1px;
    margin: 12px 0 0;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0;
    transform: scaleX(0.4);
    transform-origin: left center;
}

.sommelier[data-state="analyzing"] .som-progress {
    opacity: 1;
}

.som-wines {
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;
    gap: 10px;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(198, 163, 106, 0.35) transparent;
}

.som-wine {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    flex: 0 0 min(78%, 280px);
    margin-top: 0;
    padding: 8px 12px 8px 4px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(16, 13, 11, 0.9), rgba(32, 14, 18, 0.92));
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.som-wine:hover,
.som-wine:focus-visible {
    border-color: var(--gold);
    color: inherit;
    outline: none;
}

.som-wine img {
    width: 76px;
    height: 124px;
    object-fit: contain;
    object-position: center;
    border-radius: 11px;
    border: 1px solid #9a948c;
    background: #fff;
    box-shadow:
        0 0 8px rgba(110, 28, 43, 0.22),
        0 3px 7px rgba(7, 6, 5, 0.32);
}

.som-wine-name {
    margin: 0;
    font-family: var(--serif);
    font-weight: 500;
    font-size: 1.45rem;
    line-height: 1;
    letter-spacing: 0;
    color: var(--ivory);
}

.som-wine-meta,
.som-wine-price,
.som-wine-note {
    margin: 0;
}

.som-wine-meta {
    margin-top: 5px;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.som-wine-price {
    margin-top: 8px;
    color: var(--champagne);
    font-size: 0.92rem;
    white-space: nowrap;
}

.som-wine-note {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    margin-top: 6px;
    overflow: hidden;
    font-size: 0.84rem;
    line-height: 1.4;
    color: rgba(244, 239, 230, 0.78);
}

.som-wine-reason {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    margin: 4px 0 0;
    overflow: hidden;
    font-size: 0.78rem;
    line-height: 1.35;
    color: rgba(244, 239, 230, 0.62);
}

.som-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: auto;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}

.som-chips::-webkit-scrollbar { display: none; }

.som-chip {
    flex: 0 0 auto;
    max-width: 86vw;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--champagne);
    font-size: 0.8rem;
    line-height: 1.35;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    cursor: pointer;
}

.som-chip:hover,
.som-chip:focus-visible {
    border-color: rgba(228, 210, 176, 0.75);
    background: rgba(110, 28, 43, 0.28);
    outline: none;
}

.som-chip:disabled,
.som-composer button:disabled {
    opacity: 0.45;
    cursor: default;
}

.som-composer-wrap {
    padding: 8px 0 0;
    z-index: 3;
}

.som-composer {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: none;
    margin: 0;
    padding: 5px 5px 5px 16px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(7, 6, 5, 0.38);
}

.sommelier[data-state="listening"] .som-composer {
    border-color: rgba(228, 210, 176, 0.72);
}

.sommelier[data-state="analyzing"] .som-composer {
    border-color: rgba(154, 42, 58, 0.7);
}

.som-composer input[type="text"],
.som-composer input[type="text"]:hover,
.som-composer input[type="text"]:focus,
.som-composer input[type="text"]:disabled {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 42px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    background-color: transparent;
    box-shadow: none;
    outline: none;
    color: var(--ivory);
    font-family: var(--sans);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: normal;
    line-height: 1.3;
    text-transform: none;
    caret-color: var(--gold);
}

.som-composer input[type="text"]::placeholder { color: rgba(228, 210, 176, 0.45); }

.som-composer button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid rgba(198, 163, 106, 0.65);
    border-radius: 50%;
    background: transparent;
    color: var(--champagne);
    letter-spacing: normal;
    text-transform: none;
    cursor: pointer;
}

.som-composer button:hover,
.som-composer button:focus-visible,
.som-chip:focus-visible,
.som-logo:focus-visible {
    outline: 1px solid var(--champagne);
    outline-offset: 3px;
}

.som-composer button:hover { background: rgba(198, 163, 106, 0.12); }

@media (min-width: 960px) {
    .som-top { padding: 22px 40px 0; }
    .som-logo img { height: 22px; }

    .som-dock {
        top: 16px;
        right: auto;
        bottom: 24px;
        left: 50%;
        width: min(1360px, 76%);
        transform: translateX(-50%);
        display: grid;
        grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.72fr);
        gap: 16px;
        align-items: stretch;
        padding: 0;
    }

    .som-panel {
        padding: 18px 18px 14px;
    }

    .som-shelf {
        max-height: none;
        padding: 18px 16px 14px;
    }

    .som-shelf.is-empty {
        align-self: start;
        justify-self: stretch;
    }

    .som-wines {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        gap: 10px;
    }

    .som-wine { flex: 0 0 auto; }

    .som-intro { margin-top: 0; }

    .som-title { font-size: clamp(2.1rem, 2.8vw, 3.1rem); }
    .som-lead { font-size: 1.02rem; }
    .som-answer { font-size: 1.4rem; }

    .som-chips {
        flex-wrap: wrap;
        overflow: visible;
    }

    .som-chip { max-width: none; }
}

@media (max-width: 959px) {
    .sommelier {
        height: auto;
        min-height: 875px;
    }

    .som-chips {
        flex-wrap: wrap;
        margin-top: 22px;
        overflow: visible;
    }

    .som-chip {
        max-width: 100%;
        white-space: normal;
    }
}

@media (max-width: 959px) {
    .som-shelf-empty {
        font-size: 1.05rem;
        line-height: 1.45;
        color: rgba(228, 210, 176, 0.88);
    }

    .som-composer-wrap {
        margin-bottom: 14px;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .sommelier[data-state="available"] .som-status i {
        animation: som-dot 3.8s ease-in-out infinite;
    }

    .sommelier[data-state="analyzing"] .som-progress {
        animation: som-scan 1.5s ease-in-out infinite;
    }

    .sommelier[data-state="listening"] .som-status i,
    .sommelier[data-state="analyzing"] .som-status i {
        animation: som-dot 1.2s ease-in-out infinite;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sommelier,
    .sommelier *,
    .sommelier *::before,
    .sommelier *::after {
        animation: none !important;
        transition: none !important;
    }
}

@keyframes som-dot {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

@keyframes som-scan {
    0% { transform: scaleX(0.25); opacity: 0.35; }
    50% { transform: scaleX(1); opacity: 1; }
    100% { transform: scaleX(0.3); opacity: 0.4; }
}
