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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
    padding: 2rem 1rem;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    opacity: 0.9;
    font-size: 1.1rem;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1.5rem;
}

.random-section {
    text-align: center;
    margin-bottom: 2rem;
    padding: 2rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.random-result {
    margin-top: 1.5rem;
}

.random-card {
    display: inline-block;
    cursor: pointer;
    padding: 1rem;
    border-radius: 8px;
    transition: transform 0.2s;
    max-width: 250px;
}

.random-card:hover {
    transform: translateY(-4px);
}

.random-card img {
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
}

.random-card h3 {
    margin-top: 0.5rem;
    color: #333;
}

.hint {
    color: #999;
    font-size: 0.85rem;
}

.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar input {
    flex: 1;
    min-width: 200px;
    padding: 0.6rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    border-color: #667eea;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover {
    opacity: 0.85;
}

.btn-primary { background: #667eea; color: white; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn-success { background: #28a745; color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn-large { padding: 1rem 2rem; font-size: 1.2rem; }
.btn-small { padding: 0.3rem 0.8rem; font-size: 0.8rem; }

.category-select {
    padding: 0.6rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    background: white;
    outline: none;
    transition: border-color 0.2s;
    cursor: pointer;
}
.category-select:focus {
    border-color: #667eea;
}

.category-tag {
    display: inline-block;
    background: #e8eaff;
    color: #667eea;
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}
.category-tag-lg {
    font-size: 0.9rem;
    padding: 0.2rem 0.8rem;
    vertical-align: middle;
}

.match-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
}
.match-high { background: #28a745; }
.match-mid { background: #ffc107; color: #333; }
.match-low { background: #dc3545; }

.ingredient-search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.ingredient-search-bar input {
    flex: 1;
    min-width: 250px;
    padding: 0.6rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.ingredient-search-bar input:focus {
    border-color: #667eea;
}
.ingredient-query-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #e8f5e9;
    color: #2e7d32;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

.ing-check {
    display: inline-block;
    width: 1.2rem;
    font-weight: 700;
}
.ingredient-matched { background: #f0fff0; }
.ingredient-matched .ing-check { color: #28a745; }
.ingredient-missing { background: #fff5f5; }
.ingredient-missing .ing-check { color: #dc3545; }

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

.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.table th {
    background: #f8f9fa;
    padding: 0.8rem 1rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
}

.table td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #eee;
}

.table-img {
    width: 100px;
    height: 75px;
    object-fit: cover;
    border-radius: 4px;
}

.clickable {
    cursor: pointer;
}

.clickable:hover {
    background: #f8f9ff;
}

.empty {
    text-align: center;
    color: #999;
    padding: 2rem !important;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    margin-top: 1rem;
    padding: 1rem;
}

.pagination select {
    padding: 0.4rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.page-info {
    color: #666;
}

.detail-view {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.detail-card h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    color: #333;
}

.detail-image {
    margin-bottom: 1.5rem;
}

.detail-image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    object-fit: cover;
}

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h3 {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
    color: #555;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.3rem;
    display: inline-block;
}

.method-content {
    white-space: pre-wrap;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 6px;
    line-height: 1.8;
}

.video-link {
    display: inline-block;
    color: #fe2c55;
    text-decoration: none;
    font-size: 1.1rem;
    padding: 0.5rem 1rem;
    border: 2px solid #fe2c55;
    border-radius: 6px;
    transition: all 0.2s;
}

.video-link:hover {
    background: #fe2c55;
    color: white;
}

.form-view {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.form-view h2 {
    margin: 1rem 0 1.5rem;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: #555;
}

.required {
    color: #dc3545;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: #667eea;
}

.form-preview {
    margin-top: 0.5rem;
    max-width: 300px;
    border-radius: 6px;
}

.upload-area {
    border: 2px dashed #ddd;
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
}

.upload-area:hover {
    border-color: #667eea;
    background: #f0f0ff;
}

.upload-placeholder {
    color: #999;
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.upload-hint {
    font-size: 0.8rem;
    color: #bbb;
    margin-top: 0.3rem;
}

.upload-preview {
    position: relative;
    display: inline-block;
}

.upload-preview img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 6px;
    object-fit: cover;
}

.upload-remove {
    position: absolute;
    top: 4px;
    right: 4px;
}

.upload-progress {
    margin-top: 0.5rem;
    color: #667eea;
    font-weight: 600;
}

.ingredient-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

.ingredient-row input {
    flex: 1;
    padding: 0.5rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.form-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.toast.success { background: #28a745; }
.toast.error { background: #dc3545; }

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

@media (max-width: 768px) {
    .container {
        padding: 0.75rem;
    }

    .header {
        padding: 1.2rem 1rem;
    }
    .header h1 {
        font-size: 1.5rem;
    }
    .subtitle {
        font-size: 0.95rem;
    }

    .random-section {
        padding: 1.2rem;
        margin-bottom: 1.2rem;
    }
    .btn-large {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
        width: 100%;
    }

    .search-bar {
        flex-direction: column;
    }
    .search-bar input {
        min-width: 0;
        width: 100%;
    }
    .search-bar .btn,
    .search-bar .category-select {
        width: 100%;
    }

    .ingredient-search-bar {
        flex-direction: column;
    }
    .ingredient-search-bar input {
        min-width: 0;
        width: 100%;
    }
    .ingredient-search-bar .btn {
        width: 100%;
    }

    .dish-table, .dish-table thead, .dish-table tbody, .dish-table th, .dish-table td, .dish-table tr {
        display: block;
    }
    .dish-table thead tr {
        display: none;
    }
    .dish-table tbody tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        padding: 0.75rem;
        border-bottom: 1px solid #eee;
        position: relative;
    }
    .dish-table tbody tr td {
        padding: 0.25rem;
        border: none;
    }
    .dish-table tbody tr td:nth-child(1) {
        display: none;
    }
    .dish-table tbody tr td:nth-child(2) {
        flex: 1;
        font-size: 1rem;
        font-weight: 600;
        padding-left: 0.5rem;
        min-width: 0;
        word-break: break-word;
    }
    .dish-table tbody tr td:nth-child(3) {
        flex: 0 0 100%;
        padding: 0.15rem 0.25rem 0 0.25rem;
        order: 10;
    }
    .dish-table tbody tr td:nth-child(4) {
        order: -1;
    }
    .dish-table tbody tr td:nth-child(4) .table-img {
        width: 60px;
        height: 60px;
        border-radius: 8px;
    }
    .dish-table tbody tr td:nth-child(5),
    .dish-table tbody tr td:nth-child(6) {
        width: 100%;
        padding-top: 0.5rem;
        padding-left: 0;
        display: flex;
        gap: 0.5rem;
        order: 20;
    }
    .dish-table tbody tr td:nth-child(5) .btn,
    .dish-table tbody tr td:nth-child(6) .btn {
        flex: 1;
        text-align: center;
    }
    .dish-table tbody tr td:nth-child(5):not(:has(.btn)) {
        display: inline-block;
        width: auto;
        order: 5;
        padding: 0.15rem 0.25rem 0 0.25rem;
    }

    .table th, .table td {
        padding: 0.5rem 0.6rem;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .pagination .btn {
        padding: 0.5rem 1rem;
    }
    .pagination select {
        font-size: 0.9rem;
    }
    .page-info {
        font-size: 0.85rem;
    }

    .detail-view {
        padding: 1rem;
    }
    .detail-card h2 {
        font-size: 1.4rem;
    }
    .detail-section h3 {
        font-size: 1.1rem;
    }

    .form-view {
        padding: 1rem;
    }
    .form-view h2 {
        font-size: 1.3rem;
    }
    .ingredient-row {
        flex-direction: column;
    }
    .ingredient-row input {
        width: 100%;
    }
    .ingredient-row .btn {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }
    .form-actions .btn {
        width: 100%;
        text-align: center;
        padding: 0.8rem;
    }

    .toast {
        left: 20px;
        right: 20px;
        text-align: center;
        top: 16px;
    }

    .video-link {
        display: block;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .random-card {
        max-width: 100%;
    }
    .random-card img {
        width: 100%;
        height: auto;
        aspect-ratio: 4/3;
    }

    .form-preview {
        max-width: 100%;
    }
}
