:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --border-radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    letter-spacing: -0.025em;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.camera-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.video-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    border-radius: 12px;
    overflow: hidden;
    background-color: #0f172a;
    aspect-ratio: 4/3;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.target-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    height: 35%;
    border: 3px dashed rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
    max-width: 320px;
    justify-content: center;
    font-size: 1.125rem;
    padding: 1rem;
    box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.39);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.secondary-btn {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.secondary-btn:hover {
    background-color: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.status-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* PROCESSING BOX */
.processing-box {
    width: 100%;
    max-width: 640px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
    font-size: 0.95rem;
    text-align: left;
}

.step {
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.step.active {
    color: var(--primary-color);
    font-weight: 600;
}

.step.done {
    color: var(--secondary-color);
    font-weight: 600;
}

.raw-text-container, .extracted-name-container {
    margin-top: 1.25rem;
    padding: 1rem;
    background: #e2e8f0;
    border-radius: 8px;
    font-family: monospace;
    white-space: pre-wrap;
    max-height: 180px;
    overflow-y: auto;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.extracted-name-container {
    background: #dcfce7;
    color: #166534;
    font-size: 1.1rem;
    font-weight: bold;
    border-color: #86efac;
}

.name-edit-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 1.05rem;
    font-weight: 600;
    border: 2px solid #86efac;
    border-radius: 8px;
    background: #f0fdf4;
    color: #166534;
    outline: none;
    margin-top: 0.4rem;
    transition: border-color 0.15s;
}

.name-edit-input:focus {
    border-color: var(--primary-color);
    background: white;
}

.name-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: #64748b;
    margin-top: 0.3rem;
}

/* ── Match Results Section ─────────────────────────────────────────── */
.match-results-section {
    margin-top: 1.25rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.match-count {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.fuzzy-btn {
    background-color: #6366f1;
    color: white;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    gap: 0.35rem;
    font-weight: 500;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.fuzzy-btn:hover {
    background-color: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
}

.match-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 360px;
    overflow-y: auto;
}

.match-card {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto;
    gap: 0.25rem 0.75rem;
    align-items: center;
    padding: 0.75rem 1rem;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.match-card:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
    transform: translateX(4px);
}

.match-card.selected {
    border-color: var(--secondary-color);
    background: #f0fdf4;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.match-card .match-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    grid-column: 1;
    grid-row: 1;
}

.match-card .match-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    grid-column: 1;
    grid-row: 2;
    display: flex;
    gap: 0.75rem;
}

.match-card .match-meta span {
    background: #f1f5f9;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
}

.match-card .match-score {
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    grid-column: 2;
    grid-row: 1 / 3;
    white-space: nowrap;
}

.match-score.good {
    background: #dcfce7;
    color: #166534;
}

.match-score.ok {
    background: #fef9c3;
    color: #854d0e;
}

.match-score.low {
    background: #fee2e2;
    color: #991b1b;
}

.match-card .match-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.85rem;
    background: var(--secondary-color);
    color: white;
    grid-column: 3;
    grid-row: 1 / 3;
    white-space: nowrap;
}

.match-card .match-btn:hover {
    background: var(--secondary-hover);
}

.match-none {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ── RESULTS SECTION ────────────────────────────────────────────────── */
.results-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.results-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

th {
    font-weight: 600;
    color: var(--text-main);
    background-color: #f8fafc;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
}

tbody tr {
    transition: background-color 0.15s ease;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f1f5f9;
}
