:root {
    --bg: #eef6f2;
    --surface: #ffffff;
    --surface-strong: #f8fbf8;
    --text: #17312b;
    --muted: #667872;
    --line: #d8e7e0;
    --accent: #2f8f74;
    --accent-dark: #176c59;
    --coral: #ef7d6f;
    --gold: #f4c95d;
    --shadow: 0 18px 45px rgba(29, 70, 59, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(135deg, rgba(47, 143, 116, 0.14), rgba(239, 125, 111, 0.10)),
        var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 30px 20px 18px;
}

.user-chip {
    margin: 0;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.76);
    color: var(--accent-dark);
    font-size: 0.9rem;
    font-weight: 700;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--accent-dark);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(2rem, 4vw, 3.5rem);
}

h2 {
    font-size: 1.2rem;
}

.main-nav {
    display: inline-flex;
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.76);
}

.main-nav a,
.nav-form button {
    min-width: 104px;
    padding: 10px 14px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.main-nav a.active,
.main-nav a:hover,
.nav-form button:hover {
    background: var(--accent);
    color: #ffffff;
}

.nav-form {
    margin: 0;
}

.page-shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px 44px;
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(100%, 420px);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow);
}

.auth-panel h1 {
    font-size: clamp(2rem, 8vw, 3rem);
}

.auth-error {
    margin: 18px 0 0;
    padding: 11px 12px;
    border-radius: 7px;
    background: #ffe8e4;
    color: #a33428;
    font-weight: 700;
}

.auth-switch {
    margin: 16px 0 0;
    color: var(--muted);
    text-align: center;
}

.auth-switch a {
    color: var(--accent-dark);
    font-weight: 700;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 10px 0 18px;
}

.summary-tile,
.entry-form,
.table-panel,
.chart-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow);
}

.summary-tile {
    min-height: 112px;
    padding: 18px;
}

.summary-tile span {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-weight: 700;
}

.summary-tile strong {
    display: block;
    font-size: clamp(1.8rem, 4vw, 2.7rem);
    line-height: 1;
}

.tracker-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.entry-form,
.table-panel,
.chart-panel {
    padding: 18px;
}

.field {
    margin-top: 18px;
}

label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface-strong);
    color: var(--text);
    outline: 0;
}

input {
    height: 46px;
    padding: 0 12px;
}

textarea {
    min-height: 90px;
    padding: 12px;
    resize: vertical;
}

input:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 143, 116, 0.16);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.autocomplete {
    position: relative;
}

.option-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: none;
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.option-list.open {
    display: block;
}

.option-button {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    width: 100%;
    min-height: 56px;
    padding: 8px 10px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.option-button:hover {
    background: #edf8f3;
}

.option-button img,
.mini-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: #dfeee8;
}

.option-name {
    display: block;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.option-meta {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.82rem;
}

.primary-button,
.ghost-button,
.delete-button {
    border: 0;
    border-radius: 7px;
    font-weight: 700;
    cursor: pointer;
}

.primary-button {
    width: 100%;
    min-height: 46px;
    margin-top: 18px;
    background: var(--accent);
    color: #ffffff;
}

.primary-button:hover {
    background: var(--accent-dark);
}

.ghost-button {
    padding: 8px 11px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--accent-dark);
}

.delete-button {
    padding: 7px 9px;
    background: #ffe8e4;
    color: #a33428;
}

.form-message {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--accent-dark);
    font-weight: 700;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-heading span {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.missing-heading {
    align-items: end;
}

.missing-heading > div {
    display: grid;
    gap: 4px;
}

.compact-search {
    max-width: 260px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
}

.entity-cell {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 160px;
}

.entity-cell span {
    font-weight: 700;
}

.empty-state {
    display: none;
    margin: 20px 0 4px;
    color: var(--muted);
    text-align: center;
}

.empty-state.visible {
    display: block;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.stats-section {
    margin-top: 22px;
}

.stats-section > h2 {
    margin-bottom: 14px;
}

.compact-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bar-chart {
    display: grid;
    gap: 12px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) 38px;
    gap: 10px;
    align-items: center;
}

.meta-bar-row {
    grid-template-columns: minmax(96px, 150px) minmax(0, 1fr) 38px;
}

.bar-label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.bar-label span {
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    height: 16px;
    overflow: hidden;
    border-radius: 999px;
    background: #dfeee8;
}

.bar-fill {
    height: 100%;
    min-width: 8px;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--coral));
}

.bar-value {
    color: var(--muted);
    font-weight: 700;
    text-align: right;
}

.missing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 10px;
    max-height: 520px;
    overflow: auto;
    padding-right: 4px;
}

.missing-villager {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 64px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
}

.missing-villager img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: #dfeee8;
}

.missing-villager strong,
.missing-villager span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.missing-villager span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.82rem;
}

.island-info-panel {
    margin-top: 10px;
}

.island-info-grid {
    display: grid;
    gap: 18px;
}

.island-info-card {
    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
    gap: 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
}

.island-info-card > img {
    width: 100%;
    border-radius: 7px;
    object-fit: cover;
}

.island-info-body p {
    margin: 0 0 14px;
    color: var(--muted);
    line-height: 1.5;
}

.island-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin: 0;
}

.island-facts div {
    min-width: 0;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #ffffff;
}

.island-facts dt {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
}

.island-facts dd {
    margin: 3px 0 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}

@media (max-width: 850px) {
    .site-header,
    .tracker-layout,
    .stats-grid,
    .compact-stats-grid {
        grid-template-columns: 1fr;
    }

    .site-header {
        display: grid;
    }

    .main-nav {
        width: 100%;
    }

    .user-chip {
        width: fit-content;
    }

    .main-nav a {
        flex: 1;
        min-width: 0;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .bar-row {
        grid-template-columns: minmax(96px, 140px) minmax(0, 1fr) 32px;
    }

    .missing-heading {
        align-items: stretch;
        display: grid;
    }

    .compact-search {
        max-width: none;
    }

    .island-info-card,
    .island-facts {
        grid-template-columns: 1fr;
    }
}
