:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #f5f7f2;
    --line: #d8ded4;
    --ink: #202728;
    --muted: #65716c;
    --accent: #17756f;
    --accent-dark: #105651;
    --danger: #b93c32;
    --success: #2f8a56;
    --shadow: 0 16px 44px rgba(24, 34, 34, .12);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

a {
    color: var(--accent);
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

[hidden],
.is-hidden {
    display: none !important;
}

.app-main {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.app-main--full {
    width: 100%;
    max-width: none;
    height: 100dvh;
    overflow: hidden;
    padding: 0;
}

.language-switcher,
.account-menu,
.suggestion-box {
    position: fixed;
    z-index: 1200;
}

.language-switcher {
    top: 12px;
    left: 12px;
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.language-switcher a {
    display: grid;
    min-width: 36px;
    min-height: 30px;
    place-items: center;
    border-radius: 6px;
    color: var(--ink);
    font-size: .8rem;
    font-weight: 800;
    text-decoration: none;
}

.language-switcher a.is-active,
.language-switcher a:hover {
    background: var(--surface-soft);
    color: var(--accent-dark);
}

.account-menu {
    top: 12px;
    right: 12px;
}

.account-menu__toggle,
.suggestion-box__toggle {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--ink);
}

.account-menu__toggle span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 2px 0;
    border-radius: 999px;
    background: currentColor;
}

.account-menu__dropdown,
.profile-modal,
.settings-modal,
.game-account-modal,
.suggestion-modal,
.conversation-modal,
.player-profile-modal,
.terms-modal {
    position: fixed;
    z-index: 1300;
    width: min(440px, calc(100vw - 24px));
    max-height: calc(100dvh - 88px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--ink);
}

.account-menu__dropdown,
.profile-modal,
.settings-modal,
.game-account-modal {
    top: 58px;
    right: 12px;
}

.suggestion-box {
    top: 12px;
    right: 62px;
}

.suggestion-modal {
    top: 58px;
    right: 12px;
}

.account-menu__profile {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.account-menu__profile img,
.profile-modal__identity img,
.profile-card img,
.profile-avatar {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 999px;
}

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

.account-menu__profile span,
.modal-copy,
.form-note,
.field-note,
.form-footer,
.race-selected-description,
.profile-modal__bio,
.metric-label {
    color: var(--muted);
}

.account-menu__item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    width: 100%;
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    padding: 0 10px;
    background: transparent;
    color: var(--ink);
    text-align: left;
}

.account-menu__item:hover {
    background: var(--surface-soft);
}

.account-menu__item--danger {
    color: var(--danger);
}

.account-menu__logout {
    margin: 0;
}

.settings-modal__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.settings-modal__top h2,
.section-heading h1 {
    margin: 0;
    line-height: 1.15;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: .76rem;
    font-weight: 900;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.settings-modal__close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: 1.25rem;
}

.profile-modal__identity,
.profile-card {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.profile-modal__identity img,
.profile-card img,
.profile-avatar {
    width: 62px;
    height: 62px;
}

.profile-modal__identity h3,
.profile-modal__identity p {
    margin: 0;
}

.profile-modal__stats,
.profile-grid,
.game-stat-grid,
.race-bonus-grid,
.game-progress-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.profile-modal__stats article,
.metric-card,
.game-stat-grid article,
.race-bonus-grid article,
.game-progress-grid article,
.profile-card,
.page-section {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric-number,
.profile-modal__stats strong,
.game-stat-grid strong,
.race-bonus-grid strong,
.game-progress-grid strong {
    display: block;
    color: var(--accent-dark);
    font-size: 1.4rem;
    font-weight: 900;
}

.stacked-form,
.settings-modal__form,
.settings-form,
.suggestion-form,
.game-account-form {
    display: grid;
    gap: 12px;
}

label,
fieldset {
    display: grid;
    gap: 6px;
    min-width: 0;
    margin: 0;
    color: var(--ink);
    font-weight: 700;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

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

.primary-button,
.secondary-button {
    min-height: 38px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0 14px;
    background: var(--accent);
    color: #fff;
    font-weight: 900;
}

.secondary-button {
    border-color: var(--line);
    background: var(--surface-soft);
    color: var(--ink);
}

.text-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-weight: 800;
    text-align: left;
    text-decoration: none;
}

.text-button:hover,
.text-button:focus-visible {
    color: var(--accent-dark);
}

.alert,
.settings-modal__status {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--surface-soft);
}

.alert-error,
.settings-modal__status.is-error {
    border-color: #e5b3ad;
    background: #fff0ee;
    color: var(--danger);
}

.alert-success,
.settings-modal__status.is-success {
    border-color: #b8d7c4;
    background: #effaf3;
    color: #257046;
}

.level-table-wrap,
.race-locked-note {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: var(--surface-soft);
}

.field-label,
.field-note,
.form-note {
    overflow-wrap: anywhere;
}

.page-section {
    margin: 32px 0;
}

.section-heading {
    margin-bottom: 16px;
}

.terms-check,
.conversation-user-check {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
}

.settings-toggle {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.settings-toggle input {
    position: relative;
    width: 46px;
    height: 26px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0;
    appearance: none;
    background: #dce3dc;
    transition: background-color .18s ease, border-color .18s ease;
}

.settings-toggle input::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 2px 7px rgba(24, 34, 34, .2);
    transition: transform .18s ease;
}

.settings-toggle input:checked {
    border-color: var(--accent);
    background: var(--accent);
}

.settings-toggle input:checked::before {
    transform: translateX(20px);
}

.settings-toggle input:focus-visible {
    outline: 2px solid var(--accent-dark);
    outline-offset: 2px;
}

.level-table-scroll {
    overflow: auto;
}

.level-table {
    width: 100%;
    border-collapse: collapse;
}

.level-table th,
.level-table td {
    border-bottom: 1px solid var(--line);
    padding: 8px;
    text-align: left;
}

.chat-app {
    --online-column: 250px;
    --chat-footer-height: minmax(110px, 19vh);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--online-column);
    grid-template-rows: 58px minmax(0, 1fr) var(--chat-footer-height);
    row-gap: 10px;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #fff;
}

.chat-app::before {
    content: "";
    grid-column: 1 / -1;
    grid-row: 1;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.map-zone {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 0;
    overflow: hidden;
    background-color: #fff;
    place-items: center;
}

.city-map {
    position: relative;
    width: min(100%, calc((100dvh - 58px - max(110px, 19vh) - 20px) * 1672 / 941));
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1672 / 941;
}

.city-map img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
}

.map-hotspot {
    position: absolute;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

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

.map-hotspot--mine {
    left: 40.7%;
    top: 43.1%;
    width: 12.9%;
    height: 14.4%;
    border-radius: 43% 47% 38% 34%;
    outline: 2px solid rgba(255, 246, 169, .72);
    outline-offset: 2px;
    filter: drop-shadow(0 0 7px rgba(255, 229, 105, .55));
}

.map-hotspot--mine::before {
    content: "";
    position: absolute;
    inset: -6px;
    border: 2px solid rgba(255, 252, 191, .8);
    border-radius: inherit;
    opacity: .72;
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, .28),
        0 0 18px rgba(255, 220, 79, .8),
        inset 0 0 18px rgba(255, 244, 156, .22);
    transition: opacity .18s ease, transform .18s ease, box-shadow .18s ease;
}

.map-hotspot--mine:hover::before,
.map-hotspot--mine:focus-visible::before {
    opacity: 1;
    transform: scale(1.03);
    box-shadow:
        0 0 0 3px rgba(255, 255, 255, .45),
        0 0 26px rgba(255, 223, 75, 1),
        inset 0 0 22px rgba(255, 244, 156, .35);
}

.map-hotspot--mine:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 5px;
}

.chat-dock {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 3;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--online-column);
    min-height: 0;
    border-top: 1px solid var(--line);
    background: #fff;
}

.chat-stream {
    display: grid;
    grid-column: 1 / 3;
    grid-template-rows: minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--line);
    background: #fff;
}

.online-panel {
    display: grid;
    grid-column: 3;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    max-width: 250px;
    min-height: 0;
    background: #fff;
}

.online-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 12px;
    border-bottom: 1px solid var(--line);
    font-size: .85rem;
    font-weight: 900;
}

.online-panel__header strong {
    display: grid;
    width: 24px;
    height: 22px;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-soft);
}

.online-panel__header .chat-private-launcher {
    margin-left: auto;
}

.message-list,
.online-list,
.conversation-thread__messages,
.conversation-list {
    min-height: 0;
    overflow: auto;
}

.message-list {
    padding: 10px 12px;
    font-size: .9rem;
}

.message-item,
.message-row,
.message-body {
    min-width: 0;
}

.message-body,
.message-text {
    margin: 0;
    overflow-wrap: anywhere;
}

.message-time {
    margin-right: 6px;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
}

.message-author {
    color: var(--accent);
    font-weight: 900;
}

.message-copy {
    color: var(--ink);
}

.message-form,
.conversation-compose {
    border-top: 1px solid var(--line);
    background: #fff;
}

.message-form {
    padding: 5px 6px;
}

.conversation-compose {
    padding: 10px 12px;
}

.message-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px;
    align-items: center;
}

.message-form input {
    min-height: 22px;
    padding: 3px 7px;
    font-size: .84rem;
}

.message-form .primary-button {
    min-height: 22px;
    padding: 0 9px;
    border-radius: 6px;
    font-size: .78rem;
}

.emoji-button,
.chat-private-launcher {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--ink);
    font-weight: 900;
}

.message-form .emoji-button {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: .78rem;
}

.chat-private-launcher {
    position: relative;
    width: 32px;
    height: 30px;
}

.chat-private-launcher.has-unread::after {
    content: attr(data-unread);
    position: absolute;
    top: -7px;
    right: -7px;
    display: grid;
    min-width: 18px;
    height: 18px;
    place-items: center;
    border-radius: 999px;
    padding: 0 5px;
    background: var(--danger);
    color: #fff;
    font-size: .68rem;
}

.online-list {
    display: grid;
    align-content: start;
    gap: 3px;
    padding: 10px;
}

.online-user {
    position: relative;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    padding: 3px 6px;
    background: transparent;
    color: var(--ink);
    text-align: left;
}

.online-user:hover,
.online-user:focus-visible {
    background: var(--surface-soft);
}

.online-user::before {
    content: "";
    position: absolute;
    left: 25px;
    top: 6px;
    width: 8px;
    height: 8px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #38b16b;
}

.online-user img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 999px;
}

.online-user span,
.conversation-list__item strong,
.conversation-list__item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.online-empty {
    margin: 0;
    color: var(--muted);
}

.chat-tip {
    position: fixed;
    left: 12px;
    bottom: calc(max(110px, 19vh) + 8px);
    z-index: 1100;
    color: var(--danger);
    font-size: .85rem;
    font-weight: 900;
}

.chat-tip:not(.is-visible) {
    opacity: 0;
}

.emoji-picker-panel {
    position: fixed;
    z-index: 1600;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow);
}

.emoji-picker-panel emoji-picker {
    width: min(380px, calc(100vw - 24px));
    height: min(430px, calc(100dvh - 110px));
}

.conversation-modal {
    right: 16px;
    bottom: calc(max(110px, 19vh) + 16px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(840px, calc(100vw - 32px));
    height: min(620px, calc(100dvh - max(110px, 19vh) - 32px));
    min-height: 0;
}

.conversation-layout {
    display: grid;
    grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
    gap: 12px;
    min-height: 0;
}

.conversation-sidebar,
.conversation-thread {
    display: grid;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.conversation-sidebar {
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
}

.conversation-thread {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.conversation-thread__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 38px;
    border-bottom: 1px solid var(--line);
    padding: 6px 10px;
}

.conversation-thread__top strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-settings-toggle {
    width: 34px;
    min-height: 30px;
    padding: 0;
}

.conversation-group-settings {
    display: grid;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    padding: 10px;
    background: var(--surface-soft);
}

.conversation-group-settings[hidden],
.conversation-thread__top[hidden] {
    display: none;
}

.conversation-group-settings fieldset {
    max-height: 150px;
    overflow: auto;
    background: #fff;
}

.conversation-group-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.danger-button {
    border-color: #e2b4ae;
    background: #fff0ee;
    color: var(--danger);
}

.conversation-thread__messages {
    display: grid;
    align-content: start;
    gap: 5px;
    padding: 10px;
}

.conversation-message,
.conversation-empty {
    margin: 0;
    overflow-wrap: anywhere;
}

.conversation-message time {
    margin-right: 6px;
    color: var(--muted);
    font-size: .78rem;
}

.conversation-message strong {
    color: var(--accent);
}

.conversation-list {
    display: grid;
    align-content: start;
    gap: 6px;
}

.conversation-list__item {
    display: grid;
    gap: 2px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
    color: var(--ink);
    text-align: left;
}

.conversation-list__item:hover,
.conversation-list__item.is-active {
    background: var(--surface-soft);
}

.conversation-list__item span {
    color: var(--muted);
    font-size: .8rem;
}

.conversation-group-form[hidden],
.conversation-compose[hidden] {
    display: none;
}

.player-profile-modal {
    top: 72px;
    right: 16px;
}

.error-page {
    width: min(640px, 100%);
    margin: 80px auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 24px;
    background: #fff;
    box-shadow: var(--shadow);
}

@media (max-width: 900px) {
    .chat-app {
        --online-column: 250px;
        --chat-footer-height: 155px;
        grid-template-rows: 58px minmax(0, 1fr) var(--chat-footer-height);
    }

    .chat-tip {
        bottom: 163px;
    }

    .conversation-modal {
        bottom: 171px;
        height: min(560px, calc(100dvh - 187px));
    }
}

@media (max-width: 640px) {
    .chat-app {
        --online-column: 1fr;
        grid-template-columns: 1fr;
        grid-template-rows: 58px minmax(280px, 1fr) auto auto;
        min-height: 100dvh;
        height: auto;
    }

    .chat-app::before,
    .map-zone,
    .chat-dock,
    .chat-stream,
    .online-panel {
        grid-column: 1;
    }

    .map-zone {
        grid-row: 2;
        min-height: 300px;
    }

    .chat-dock {
        grid-row: 3 / 5;
        display: grid;
        grid-template-columns: 1fr;
        border-top: 1px solid var(--line);
    }

    .chat-stream {
        grid-column: 1;
        min-height: 260px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .online-panel {
        grid-column: 1;
        min-height: 180px;
    }

    .form-row,
    .profile-grid,
    .profile-modal__stats,
    .conversation-layout {
        grid-template-columns: 1fr;
    }

    .account-menu__dropdown,
    .profile-modal,
    .settings-modal,
    .game-account-modal,
    .suggestion-modal,
    .conversation-modal,
    .player-profile-modal {
        left: 10px;
        right: 10px;
        width: auto;
    }

    .conversation-modal {
        top: 64px;
        bottom: 12px;
        height: auto;
    }
}
