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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
}

.container {
    width: 100%;
    max-width: 600px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: #86868b;
    font-size: 1rem;
    margin-top: 0.25rem;
}

/* Form */
#lookup-form {
    margin-bottom: 1.5rem;
}

.input-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

select,
input[type="text"],
button {
    font-size: 1rem;
    padding: 0.65rem 0.9rem;
    border: 1px solid #d2d2d7;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

select:focus,
input[type="text"]:focus {
    border-color: #0071e3;
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

select {
    flex: 0 0 auto;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%2386868b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

input[type="text"] {
    flex: 1 1 0;
    min-width: 0;
}

button {
    flex: 0 0 auto;
    background: #0071e3;
    color: #fff;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover:not(:disabled) {
    background: #0077ed;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem 0;
    color: #86868b;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid #d2d2d7;
    border-top-color: #0071e3;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* Error */
.error {
    background: #fff0f0;
    color: #d00;
    border: 1px solid #fcc;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

/* Results */
.results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.result-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    animation: fadeIn 0.3s ease;
}

.result-card h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #86868b;
    margin-bottom: 0.5rem;
}

.result-card p {
    font-size: 1.05rem;
    line-height: 1.6;
}

.foreign-text {
    font-weight: 600;
}

.translation {
    color: #6e6e73;
    margin-top: 0.25rem;
    font-style: italic;
}

#related-vocab {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#related-vocab li {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 1rem;
}

#related-vocab li:last-child {
    border-bottom: none;
}

#related-vocab .vocab-word {
    font-weight: 600;
}

#related-vocab .vocab-translation {
    color: #6e6e73;
}

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

/* Utility */
.hidden {
    display: none !important;
}

/* Nav bar */
.nav-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.nav-link {
    padding: 0.45rem 1.1rem;
    border-radius: 8px;
    text-decoration: none;
    color: #6e6e73;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

.nav-link:hover {
    background: #e8e8ed;
    color: #1d1d1f;
}

.nav-link.active {
    background: #0071e3;
    color: #fff;
}

/* Saved notice */
.saved-notice {
    text-align: center;
    color: #34c759;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.5rem;
    animation: fadeIn 0.3s ease;
}

/* Result meta (tags + difficulty on lookup page) */
.result-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.diff-a1 { background: #e8f5e9; color: #2e7d32; }
.diff-a2 { background: #e0f2f1; color: #00695c; }
.diff-b1 { background: #e3f2fd; color: #1565c0; }
.diff-b2 { background: #ede7f6; color: #4527a0; }
.diff-c1 { background: #fff3e0; color: #e65100; }
.diff-c2 { background: #fce4ec; color: #c62828; }

.difficulty-badge { text-transform: uppercase; }

/* Tag chips */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    background: #f0f0f5;
    color: #6e6e73;
}

.tag-chip.editable {
    background: #e8e8ed;
    color: #1d1d1f;
}

.tag-remove {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 0.15rem;
    line-height: 1;
}

.tag-remove:hover {
    color: #d00;
}

.tag-add-btn {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    background: none;
    border: 1px dashed #ccc;
    color: #999;
    cursor: pointer;
}

.tag-add-btn:hover {
    border-color: #0071e3;
    color: #0071e3;
}

.tags-display {
    display: inline-flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.filter-bar select {
    flex: 1 1 0;
    min-width: 0;
    font-size: 0.9rem;
    padding: 0.5rem 2rem 0.5rem 0.7rem;
}

/* History container */
.history-container {
    max-width: 700px;
}

/* History list */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* History card */
.history-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.history-card.expanded {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-header {
    padding: 0.9rem 1.2rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.card-header:hover {
    background: #fafafa;
}

.card-main {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.card-query {
    font-weight: 700;
    font-size: 1.05rem;
}

.card-language {
    font-size: 0.8rem;
    color: #86868b;
}

.card-meaning {
    font-size: 0.9rem;
    color: #6e6e73;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.card-reviews {
    font-size: 0.8rem;
    color: #86868b;
}

.card-date {
    font-size: 0.8rem;
    color: #86868b;
    margin-left: auto;
}

.card-tags {
    display: inline-flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

/* Card details (expanded) */
.card-details {
    padding: 0 1.2rem 1.2rem;
    border-top: 1px solid #f0f0f0;
}

.detail-section {
    margin-top: 1rem;
}

.detail-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #86868b;
    margin-bottom: 0.3rem;
}

.detail-section p {
    font-size: 0.95rem;
    line-height: 1.5;
}

.detail-vocab {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-vocab li {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.editable-tags {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}

/* Card actions */
.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f0f0f0;
}

.btn-review,
.btn-delete {
    padding: 0.4rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    font-weight: 600;
    background: #0071e3;
    color: #fff;
    transition: background 0.2s;
}

.btn-review:hover,
.btn-delete:hover {
    background: #005bb5;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #86868b;
}

.empty-state a {
    color: #0071e3;
    text-decoration: none;
}

/* Load more */
.load-more-btn {
    display: block;
    width: 100%;
    margin-top: 1rem;
    padding: 0.7rem;
    border-radius: 10px;
    border: 1px solid #d2d2d7;
    background: #fff;
    color: #0071e3;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.load-more-btn:hover {
    background: #f0f0f5;
}

/* Responsive */
@media (max-width: 480px) {
    .input-row {
        flex-direction: column;
    }

    select,
    input[type="text"],
    button {
        width: 100%;
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-bar select {
        width: 100%;
    }

    .card-main {
        flex-direction: column;
        gap: 0.2rem;
    }

    .card-meaning {
        white-space: normal;
    }

    .card-date {
        margin-left: 0;
    }
}
