:root {
    --sky: #0ea5e9;
    --deep: #132238;
    --green: #22c55e;
    --gold: #facc15;
    --red: #ef4444;
    --blue: #2563eb;
    --ink: #172033;
    --paper: #ffffff;
    --line: #d7e2ef;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: linear-gradient(#7dd3fc, #f0fdf4 56%, #e0f2fe);
}

a {
    color: inherit;
}

button,
.button {
    border: 2px solid #0f172a;
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font-weight: 800;
    padding: 10px 14px;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 3px 0 #0f172a;
}

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

.primary {
    background: var(--gold);
}

.full {
    width: 100%;
    margin-top: 10px;
}

.hidden {
    display: none !important;
}

.notice {
    background: #fff7cc;
    border: 1px solid #eab308;
    border-radius: 8px;
    padding: 10px;
    font-weight: 700;
}

.small {
    font-size: 13px;
}

.logo {
    height: 50px;
    width: auto;
    display: block;
}

.logo-link {
    display: inline-flex;
    align-items: center;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

.gate-page,
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
}

.gate {
    width: min(1040px, 100%);
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    gap: 24px;
    margin-top: 48px;
}

.gate-panel,
.auth-card,
.panel,
.sidebar {
    background: rgba(255, 255, 255, .94);
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 16px 30px rgba(15, 23, 42, .12);
}

.gate-panel h1,
.auth-card h1 {
    font-size: clamp(34px, 7vw, 72px);
    line-height: .9;
    margin: 0 0 12px;
}

.gate-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.auth-card {
    width: min(420px, 100%);
    display: grid;
    gap: 14px;
    margin-top: 48px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
}

textarea {
    font-family: Consolas, monospace;
}

.flash {
    border: 2px solid var(--blue);
    border-radius: 8px;
    padding: 10px;
    background: #dbeafe;
    font-weight: 800;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    background: #0f172a;
    color: white;
    border-bottom: 4px solid var(--gold);
}

.topbar button,
.topbar > a:not(.logo-link) {
    color: #0f172a;
    background: #fff;
    border-radius: 8px;
    padding: 9px 12px;
    text-decoration: none;
    font-weight: 900;
}

.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(420px, 1fr) 360px;
    gap: 16px;
    padding: 16px;
    align-items: start;
}

.sidebar h1 {
    margin-bottom: 0;
}

.role {
    display: inline-block;
    background: #dcfce7;
    border-radius: 999px;
    padding: 4px 10px;
    margin-top: 4px;
    font-weight: 900;
}

.coin-box {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    margin: 16px 0 8px;
    padding: 12px;
    border-radius: 8px;
    background: #fff7cc;
    border: 2px solid #facc15;
}

#coinBalance {
    display: grid;
    place-items: center;
    min-width: 56px;
    min-height: 56px;
    border-radius: 50%;
    background: var(--gold);
    border: 3px solid #b45309;
    font-size: 22px;
    font-weight: 900;
}

.mini-admin {
    margin-top: 18px;
    border-top: 2px solid var(--line);
}

.world-area {
    min-width: 0;
}

.world-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    background: rgba(255,255,255,.88);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 12px;
}

.world-head h2 {
    margin: 0 0 6px;
}

.builder-tools {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto auto;
    gap: 8px;
}

.world-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(34px, 1fr));
    aspect-ratio: 12 / 8;
    gap: 4px;
    width: 100%;
}

.world-cell {
    min-width: 0;
    min-height: 0;
    border: 2px solid rgba(15,23,42,.22);
    box-shadow: none;
    border-radius: 6px;
    background: #86efac;
    font-size: clamp(10px, 1.1vw, 14px);
    padding: 0;
    overflow: hidden;
}

.world-cell[data-category="building"] { background: #e5e7eb; }
.world-cell[data-category="nature"] { background: #4ade80; }
.world-cell[data-category="props"] { background: #fdba74; }
.world-cell[data-category="avatar"] { background: #c084fc; }
.world-cell[data-category="special"] { background: #67e8f9; }
.world-cell.start { outline: 4px solid var(--green); }
.world-cell.finish { outline: 4px solid var(--red); }
.world-cell.player::after {
    content: "P";
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #111827;
    color: white;
    font-weight: 900;
}

.panel-stack {
    display: grid;
    gap: 16px;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.tabs .active {
    background: var(--gold);
}

.shop-list {
    display: grid;
    gap: 8px;
    max-height: 560px;
    overflow: auto;
    padding-right: 4px;
}

.shop-row,
.friend-row,
.chat-row,
.friend-add {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.shop-row {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.shop-row small {
    display: block;
    margin-top: 3px;
    color: #475569;
}

.chat-log {
    min-height: 220px;
    max-height: 320px;
    overflow: auto;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
    margin-bottom: 10px;
}

.chat-log div {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 8px;
    background: white;
}

.friend-columns {
    display: grid;
    gap: 12px;
}

.friend-row {
    grid-template-columns: 1fr auto auto auto;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.friend-row button {
    padding: 6px 8px;
    box-shadow: none;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%) translateY(80px);
    background: #0f172a;
    color: white;
    padding: 12px 18px;
    border-radius: 8px;
    opacity: 0;
    transition: .2s ease;
    font-weight: 900;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.admin-page {
    display: grid;
    gap: 16px;
    padding: 16px;
}

.legal-page {
    width: min(920px, 100%);
    margin: 0 auto;
    padding: 28px 16px 86px;
}

.legal-card {
    background: rgba(255, 255, 255, .96);
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 16px 30px rgba(15, 23, 42, .12);
}

.legal-card h1 {
    margin: 0 0 12px;
    font-size: clamp(34px, 6vw, 58px);
}

.legal-card h2 {
    margin-top: 24px;
}

.legal-card li {
    margin: 8px 0;
}

.contact-form {
    display: grid;
    gap: 14px;
}

.coin-store {
    padding: 28px 16px 70px;
}

.coin-store-head {
    text-align: center;
    margin-bottom: 18px;
}

.coin-store-head h1 {
    font-size: clamp(34px, 6vw, 58px);
    margin: 0 0 8px;
}

.coin-store-head p {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.coin-card-wrap {
    text-align: center;
}

.coin-card {
    background: #111;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    color: #fff;
    width: 250px;
    display: inline-block;
    margin: 15px;
    position: relative;
    vertical-align: top;
}

.coin-card h2 {
    font-size: 24px;
}

.coin-card .coins {
    font-size: 20px;
    margin: 10px 0;
}

.coin-card .price {
    font-size: 22px;
    font-weight: bold;
    color: #00ffcc;
}

.coin-card button {
    margin-top: 15px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    background: #00ffcc;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    box-shadow: none;
}

.coin-card button:hover {
    background: #00ccaa;
}

.badge {
    background: gold;
    color: #000;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
    position: absolute;
    top: 10px;
    right: 10px;
}

.site-footer {
    display: flex;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
    padding: 18px;
    margin-top: 24px;
    background: #0f172a;
    color: white;
    border-top: 4px solid var(--gold);
}

.site-footer a {
    color: white;
    font-weight: 900;
    text-decoration: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

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

.toggles {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.toggles label {
    display: inline-flex;
    align-items: center;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: grid;
        grid-template-columns: 180px 1fr;
        gap: 12px;
    }
    .panel-stack {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .gate {
        grid-template-columns: 1fr;
    }
    .sidebar,
    .world-head,
    .builder-tools {
        display: grid;
        grid-template-columns: 1fr;
    }
    .topbar {
        overflow-x: auto;
    }
    .world-grid {
        grid-template-columns: repeat(12, 34px);
        overflow-x: auto;
    }
    .coin-card {
        width: 90%;
        max-width: 300px;
    }
}
