:root {
    --bg-top: #fff5df;
    --bg-bottom: #f3f8ec;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(128, 97, 40, 0.08); /* Softer borders */
    --text-main: #2d2418;
    --text-light: #6b5d46;
    --primary: #FF7043; /* More modern orange */
    --primary-dark: #E64A19;
    --accent: #43A047; /* Modern green */
    --accent-dark: #2E7D32;
    --chip-bg: rgba(255, 255, 255, 0.7);
    --chip-active: #fff0d8;
    --shadow: 0 12px 32px rgba(232, 124, 56, 0.08);
    --shadow-hover: 0 20px 48px rgba(232, 124, 56, 0.15);
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text-main);
    background:
            radial-gradient(circle at top left, rgba(255, 112, 67, 0.12), transparent 40%),
            radial-gradient(circle at top right, rgba(67, 160, 71, 0.12), transparent 40%),
            linear-gradient(135deg, var(--bg-top), var(--bg-bottom));
    background-attachment: fixed;
}

/* Animations Core */
@keyframes fadeUp {
    0% { opacity: 0; transform: translateY(16px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

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

.page-shell {
    max-width: 520px;
    margin: 0 auto;
    padding: 20px 16px 32px;
    animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.hero-card,
.content-card,
.summary-card,
.menu-card,
.state-card,
.detail-panel {
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.hero-card {
    padding: 24px;
    border-radius: 32px;
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.hero-content {
    position: relative;
    z-index: 1;
}

.hero-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 10px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--primary-dark);
    background: rgba(255, 112, 67, 0.12);
    border-radius: 99px;
}

.hero-card h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.hero-desc {
    margin: 10px 0 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-light);
    position: relative;
    z-index: 1;
}

.content-card {
    margin-top: 16px;
    padding: 20px;
    border-radius: 32px;
}

.section-label {
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-light);
}

.tab-list,
.people-list {
    display: grid;
    gap: 12px;
}

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

.people-list {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 16px;
    padding: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.people-list::-webkit-scrollbar {
    display: none;
}

.tab-button,
.people-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 90px;
    min-height: 90px;
    border-radius: 32px;
    background: transparent;
    color: var(--text-main);
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-tap-highlight-color: transparent;
    padding: 12px 0;
    outline: none;
}

.people-button:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.9);
}

.tab-button .icon,
.tab-button .icon,
.people-button .icon {
    margin-bottom: 4px;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.people-button .icon img {
    display: block;
    max-width: 100%;
}

.tab-button .text,
.people-button .text {
    font-size: 15px;
    font-weight: 700;
    margin-top: 4px;
}

.tab-button:hover,
.people-button:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.9);
}

.tab-button.active {
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(255, 112, 67, 0.15), inset 0 0 0 2px var(--primary);
    color: var(--primary-dark);
    transform: translateY(-2px);
}

.people-button.active {
    background: #ffffff;
    border: 2px solid #FF7043;
    box-shadow: 0 10px 25px rgba(255, 112, 67, 0.12);
    color: #FF7043;
    transform: translateY(-2px) scale(1.02);
}

.tab-button.active .icon,
.people-button.active .icon {
    transform: scale(1.1);
}

.action-section {
    margin-top: 24px;
}

.primary-button {
    width: 100%;
    min-height: 60px;
    border-radius: 22px;
    background: linear-gradient(135deg, var(--primary), #FF5722);
    color: #ffffff;
    font-size: 17px;
    font-weight: 700;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(255, 87, 34, 0.22);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    outline: none;
}

.primary-button:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 16px 32px rgba(255, 87, 34, 0.32);
    filter: brightness(1.05);
}

.primary-button:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 4px 12px rgba(255, 87, 34, 0.2);
}

.primary-button.loading {
    /* Maintain original theme during loading to avoid jarring color flash */
    color: #ffffff !important;
    background: linear-gradient(135deg, var(--primary), #FF5722) !important;
    box-shadow: 0 8px 16px rgba(255, 87, 34, 0.15) !important;
    cursor: wait;
    transform: scale(0.97) !important;
    pointer-events: none;
    opacity: 0.9; /* Slight dimming for state feedback */
}

.primary-button.loading svg {
    animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

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

.action-tip {
    margin: 12px 4px 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-light);
    text-align: center;
}

.summary-card {
    margin-top: 20px;
    padding: 20px;
    border-radius: 24px;
}

.summary-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.summary-text {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-light);
}

.tips-list {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.tip-item {
    padding: 12px 16px;
    border-radius: 18px;
    background: rgba(67, 160, 71, 0.08);
    color: var(--accent-dark);
    font-size: 13px;
    line-height: 1.5;
    font-weight: 500;
}

.menu-list {
    display: grid;
    gap: 16px;
    margin-top: 16px;
}

.menu-card {
    padding: 20px;
    border-radius: 28px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    animation: popIn 0.4s both;
}

.menu-card:nth-child(1) { animation-delay: 0.05s; }
.menu-card:nth-child(2) { animation-delay: 0.1s; }
.menu-card:nth-child(3) { animation-delay: 0.15s; }
.menu-card:nth-child(4) { animation-delay: 0.2s; }
.menu-card:nth-child(5) { animation-delay: 0.25s; }

.menu-card.clickable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.menu-card.clickable:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    background: #ffffff;
}

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

.menu-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.slot-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 99px;
    background: rgba(255, 112, 67, 0.1);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}

.category-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 99px;
    background: rgba(67, 160, 71, 0.1);
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 700;
}

.menu-body {
    margin: 14px 0;
}

.menu-name {
    margin: 0 0 6px;
    font-size: 20px;
    line-height: 1.35;
    font-weight: 800;
}

.menu-desc {
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-light);
}

.menu-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px dashed rgba(128, 97, 40, 0.15);
}

.menu-time {
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    opacity: 0.8;
}

.menu-action-hint {
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

.replace-button {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 68px;
    height: 28px;
    padding: 0 10px;
    border-radius: 99px;
    background: linear-gradient(135deg, #FFF0E8, #FFE0D2);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
    border: 1px solid rgba(255, 112, 67, 0.12);
    box-shadow: 0 4px 10px rgba(255, 112, 67, 0.1);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.replace-button:hover {
    background: linear-gradient(135deg, #FFE0D2, #FFCDBA);
    border-color: rgba(255, 112, 67, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(255, 112, 67, 0.15);
}

.replace-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba(255, 112, 67, 0.1);
}

/* State Cards */
.state-card {
    margin-top: 16px;
    padding: 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
}

.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 20px;
    color: var(--text-main);
    font-weight: 600;
    
    /* Smooth fade in to avoid flash */
    animation: fadeIn 0.3s ease-out;
}

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

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 112, 67, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

.state-card.error,
.detail-state.error {
    color: #D32F2F;
    background: rgba(211, 47, 47, 0.08);
    font-weight: 600;
}

/* Detail Panel Update */
.detail-mask {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(28, 22, 16, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    
    /* Animation definitions */
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.detail-mask.show {
    opacity: 1;
    visibility: visible;
}

.detail-panel {
    width: min(520px, 100%);
    max-height: 90vh;
    border-radius: 32px;
    overflow: hidden;
    
    /* Initial state for out animation */
    transform: translateY(100%) scale(0.95);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.detail-mask.show .detail-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 24px 16px;
    border-bottom: 1px solid rgba(128, 97, 40, 0.06);
}

.detail-tag {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.05em;
}

.detail-title {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.3;
}

.detail-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: #FF4C4C;
    color: #FFFFFF;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 76, 76, 0.3);
}

.detail-close:hover {
    background: #E60000;
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 6px 16px rgba(255, 76, 76, 0.4);
}

.detail-body {
    max-height: calc(90vh - 100px);
    overflow: auto;
    padding: 20px 24px 32px;
}

.detail-content {
    display: grid;
    gap: 20px;
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 99px;
    background: rgba(255, 112, 67, 0.1);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}

.detail-chip-stars {
    gap: 8px;
}

.detail-chip-label {
    color: var(--primary-dark);
}

.detail-stars {
    color: #FFA000;
    font-size: 14px;
}

.detail-section {
    display: grid;
    gap: 12px;
}

.detail-section-title {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
}

.detail-description {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-main);
    white-space: pre-line;
}

.detail-image-list {
    display: grid;
    gap: 12px;
}

.detail-image {
    display: block;
    width: 100%;
    border-radius: 20px;
    background: rgba(45, 36, 24, 0.05);
    object-fit: cover;
}

.detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.detail-list li {
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(67, 160, 71, 0.05);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-main);
}

.detail-step-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.detail-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px;
    height: 28px;
    border-radius: 14px;
    background: rgba(255, 112, 67, 0.12);
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 700;
}

.detail-step-text {
    flex: 1;
}

.detail-empty,
.detail-state {
    padding: 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.6;
    background: rgba(45, 36, 24, 0.04);
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.no-scroll {
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.share-mask {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Start from top to support scrolling */
    overflow-y: auto;
    padding: 32px 16px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
    background: rgba(18, 14, 10, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    -webkit-overflow-scrolling: touch;
}

.share-mask.show {
    opacity: 1;
    visibility: visible;
}

.share-panel {
    width: min(440px, 100%);
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: auto 0; /* Auto margins provide centering when content is smaller than viewport */
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    flex-shrink: 0;
}

.share-mask.show .share-panel {
    transform: translateY(0) scale(1);
}

.share-card {
    background: #ffffff;
    border-radius: 32px;
    padding: 32px;
    box-shadow: 0 32px 64px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.share-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 8px;
    background: linear-gradient(90deg, var(--primary), #FFAB91);
}

.share-header {
    text-align: center;
    margin-bottom: 28px;
}

.share-header-tag {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255, 112, 67, 0.1);
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 800;
    border-radius: 99px;
    margin-bottom: 12px;
}

.share-title {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.share-meta {
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-light);
    display: flex;
    justify-content: center;
    gap: 12px;
    font-weight: 500;
}

.share-body {
    display: grid;
    gap: 16px;
}

.share-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #fdfaf5;
    border-radius: 20px;
    border: 1px solid rgba(128, 97, 40, 0.05);
    
    /* Animation for smooth entrance - slowed down for elegance */
    opacity: 0;
    animation: popIn 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.share-item-icon {
    width: 44px;
    height: 44px;
    background: white;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}

.share-item-info {
    flex: 1;
}

.share-item-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
    opacity: 0.8;
}

.share-item-name {
    font-size: 17px;
    font-weight: 800;
    color: var(--text-main);
}

.share-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.share-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.share-brand-logo {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 14px;
}

.share-brand-name {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-main);
}

.share-qr-mock {
    font-size: 11px;
    color: var(--text-light);
    text-align: right;
    line-height: 1.4;
}

.share-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.share-close-btn {
    width: 100%;
    min-height: 52px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    color: white;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.share-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.share-hint {
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    margin: 0;
}

/* Secondary Button Style */
.secondary-button {
    margin-top: 12px;
    width: 100%;
    min-height: 54px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.6);
    color: var(--text-light);
    font-size: 15px;
    font-weight: 700;
    border: 1.5px solid rgba(128, 97, 40, 0.1);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.secondary-button:focus,
.secondary-button:active {
    outline: none;
}

.secondary-button:hover:not(:disabled) {
    background: #ffffff;
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 112, 67, 0.08);
}

.secondary-button:active:not(:disabled) {
    transform: translateY(1px);
}

/* Local Replacement State */
.menu-card.replacing {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(0.2);
    transform: scale(0.98);
    transition: all 0.3s ease;
}

.menu-card.replaced {
    animation: popIn 0.4s both;
}

@keyframes throwOutLeft {
    0% { transform: scale(1) rotate(0); opacity: 1; }
    100% { transform: translateX(-120px) translateY(40px) rotate(-15deg) scale(0.8); opacity: 0; }
}

@keyframes throwOutRight {
    0% { transform: scale(1) rotate(0); opacity: 1; }
    100% { transform: translateX(120px) translateY(40px) rotate(15deg) scale(0.8); opacity: 0; }
}

@keyframes dropOut {
    0% { transform: scale(1) translateY(0); opacity: 1; }
    100% { transform: scale(0.95) translateY(40px); opacity: 0; }
}

.menu-card.throwing-out-left {
    animation: throwOutLeft 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
    pointer-events: none;
}

.menu-card.throwing-out-right {
    animation: throwOutRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
    pointer-events: none;
}

/* ===== Action Row (two secondary buttons side by side) ===== */
.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

.action-row .secondary-button {
    margin-top: 0;
}

/* Highlight search button slightly */
.search-entry-btn {
    border-color: rgba(67, 160, 71, 0.2);
    color: var(--accent-dark);
}

.search-entry-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 8px 20px rgba(67, 160, 71, 0.1);
}

/* ===== Search Modal ===== */
@keyframes searchSlideDown {
    0%   { transform: translateY(-110%); }
    60%  { transform: translateY(4px); }
    80%  { transform: translateY(-2px); }
    100% { transform: translateY(0); }
}

@keyframes searchSlideUp {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-110%); }
}

@keyframes resultFadeUp {
    0%   { opacity: 0; transform: translateY(12px) scale(0.97); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.search-mask {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(18, 14, 10, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    /* Separate opacity/visibility from panel so they animate independently */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.search-mask.show {
    opacity: 1;
    visibility: visible;
}

.search-panel {
    display: flex;
    flex-direction: column;
    width: min(520px, 100%);
    max-height: 100dvh;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom-left-radius: 28px;
    border-bottom-right-radius: 28px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
    /* Start hidden above screen */
    transform: translateY(-110%);
    /* Spring-like transition for opening */
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
    will-change: transform;
}

.search-mask.show .search-panel {
    transform: translateY(0);
}

/* Exit animation when closing */
.search-panel.closing {
    transform: translateY(-110%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 1, 1) !important;
}

.search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(128, 97, 40, 0.08);
    background: rgba(255, 255, 255, 0.6);
}

.search-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-light);
    pointer-events: none;
    flex-shrink: 0;
}

.search-input {
    width: 100%;
    height: 46px;
    padding: 0 44px 0 44px;
    border-radius: 16px;
    border: 1.5px solid rgba(128, 97, 40, 0.12);
    background: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    color: var(--text-main);
    font-family: inherit;
    outline: none;
    transition: all 0.25s ease;
    -webkit-appearance: none;
    appearance: none;
}

.search-input::placeholder {
    color: var(--text-light);
    opacity: 0.7;
}

.search-input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(255, 112, 67, 0.1);
}

/* Hide native clear button from search input */
.search-input::-webkit-search-cancel-button {
    display: none;
}

.search-clear {
    position: absolute;
    right: 10px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(128, 97, 40, 0.08);
    border: none;
    border-radius: 50%;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-clear:hover {
    background: rgba(255, 112, 67, 0.12);
    color: var(--primary-dark);
}

.search-cancel {
    flex-shrink: 0;
    padding: 0 4px;
    height: 44px;
    background: none;
    border: none;
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
    transition: opacity 0.2s ease;
    font-family: inherit;
}

.search-cancel:hover {
    opacity: 0.7;
}

.search-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: calc(100dvh - 80px);
}

.search-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.7;
    text-align: center;
    opacity: 0.8;
}

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    font-size: 14px;
    color: var(--text-light);
    font-weight: 600;
}

.search-empty {
    padding: 32px 20px;
    text-align: center;
    font-size: 14px;
    color: var(--text-light);
    background: rgba(45, 36, 24, 0.04);
    border-radius: 18px;
    font-weight: 500;
}

.search-results {
    display: grid;
    gap: 10px;
}

.search-result-card {
    padding: 16px 18px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
    cursor: pointer;
    /* Only transition transform/shadow/bg, avoid expensive 'all' */
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                background 0.2s ease,
                border-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    /* Staggered entrance with smooth spring */
    opacity: 0;
    animation: resultFadeUp 0.38s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    will-change: transform, opacity;
}

.search-result-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    background: #ffffff;
    border-color: rgba(255, 112, 67, 0.2);
}

.search-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.search-result-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.search-tag {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 99px;
    background: rgba(67, 160, 71, 0.08);
    color: var(--accent-dark);
    font-size: 11px;
    font-weight: 600;
}

.search-result-name {
    font-size: 17px;
    font-weight: 800;
    line-height: 1.35;
    color: var(--text-main);
    margin-bottom: 10px;
}

.search-result-footer {
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    opacity: 0.85;
}

.search-result-hint {
    margin-left: auto;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
}
