:root {
    --page: #2b1c11;
    --paper: #f4e4bc;
    --paper-dark: #e0c38b;
    --edge: #7d5a2b;
    --edge-dark: #3d2815;
    --text: #2a2117;
    --muted: #6d5840;
    --gold: #d7a84f;
    --gold-light: #ffe2a2;
    --red: #a22a20;
    --green: #2f8a39;
    --yellow: #c89c1a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        linear-gradient(rgba(35, 22, 12, 0.88), rgba(35, 22, 12, 0.88)),
        url("https://dspl.innogamescdn.com/asset/8b28a2b1a4/graphic/background/bg-tile.jpg");
    font: 13px Arial, Helvetica, sans-serif;
}

a { color: #6f3e16; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    padding: 8px 20px;
    color: #f8edd0;
    background: linear-gradient(#6f4a28, #3f2818);
    border-bottom: 1px solid #1f1209;
}

.brand {
    color: #f8edd0;
    font-weight: 700;
    text-decoration: none;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topnav a { color: #f8edd0; }

.page {
    width: min(1240px, calc(100% - 24px));
    margin: 18px auto 40px;
}

.panel-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    color: #f8edd0;
}

h1 {
    margin: 0 0 4px;
    font-size: 24px;
    letter-spacing: 0;
}

p { margin: 0; }

.auth-shell {
    display: grid;
    min-height: calc(100vh - 90px);
    place-items: center;
}

.auth-box { width: min(380px, 100%); }

.tw-box {
    overflow: hidden;
    background: var(--paper);
    border: 1px solid var(--edge-dark);
    box-shadow: 0 2px 0 rgba(255,255,255,0.16) inset, 0 8px 28px rgba(0,0,0,0.28);
}

.box-head {
    padding: 8px 10px;
    color: #f8edd0;
    font-weight: 700;
    background: linear-gradient(#7b512c, #4b301c);
    border-bottom: 1px solid #332011;
}

.box-head-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.box-body { padding: 12px; }

.stack {
    display: grid;
    gap: 10px;
}

.grid {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
}

.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.create-form,
.actions,
.inline-form {
    display: flex;
    align-items: end;
    gap: 8px;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.assign-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto;
    gap: 6px;
    align-items: center;
    min-width: 260px;
}

.assign-form select,
.assign-form input {
    min-height: 26px;
}

.field {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-weight: 700;
}

input,
textarea,
select {
    width: 100%;
    min-height: 30px;
    padding: 5px 7px;
    color: var(--text);
    background: #fff8e6;
    border: 1px solid #9a7b45;
    font: inherit;
}

textarea {
    resize: vertical;
    font-family: Consolas, "Courier New", monospace;
}

.btn {
    min-height: 30px;
    padding: 5px 10px;
    color: #2d210f;
    background: linear-gradient(var(--gold-light), var(--gold));
    border: 1px solid #7e5a27;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
}

.btn.primary { background: linear-gradient(#d8f0b5, #86b958); }
.btn.danger { background: linear-gradient(#f1b3a8, #c8594f); }
.btn.small {
    min-height: 24px;
    padding: 3px 8px;
    font-size: 12px;
}

.text-link { text-align: center; }

.notice {
    padding: 8px;
    background: #fff4d4;
    border: 1px solid #c7a45a;
}

.notice.error {
    color: #8f1c14;
    background: #ffe2dc;
    border-color: #ba6a61;
}

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

.tw-table {
    width: 100%;
    border-collapse: collapse;
    background: #f7ebcd;
}

.tw-table th,
.tw-table td {
    padding: 8px;
    border: 1px solid #c2a66f;
    text-align: left;
    vertical-align: top;
}

.tw-table th {
    background: #d5b879;
    color: #3a2818;
}

.tw-table.compact th,
.tw-table.compact td { padding: 6px; }

.empty {
    text-align: center;
    color: var(--muted);
}

.dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.35);
    vertical-align: -1px;
}

.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

.lock-indicator {
    position: relative;
    display: inline-block;
    width: 13px;
    height: 11px;
    margin: 0 1px;
    border: 1px solid rgba(0,0,0,0.35);
    border-radius: 2px;
    background: var(--red);
    vertical-align: -2px;
}

.lock-indicator::before {
    content: "";
    position: absolute;
    left: 2px;
    top: -8px;
    width: 7px;
    height: 8px;
    border: 2px solid var(--red);
    border-bottom: 0;
    border-radius: 7px 7px 0 0;
}

.lock-indicator::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 3px;
    width: 3px;
    height: 5px;
    border-radius: 2px;
    background: #4b1c17;
}

.stat-grid,
.resource-grid,
.troop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.stat,
.resource,
.troop {
    padding: 8px;
    background: #fff6dc;
    border: 1px solid #c2a66f;
}

.icon-stat {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    grid-template-areas:
        "icon label"
        "icon value";
    align-items: center;
    column-gap: 8px;
    min-height: 48px;
}

.icon-stat img {
    grid-area: icon;
    width: 18px;
    height: 18px;
    justify-self: center;
}

.icon-stat strong {
    grid-area: label;
}

.icon-stat span {
    grid-area: value;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat strong,
.resource strong,
.troop strong {
    display: block;
    margin-bottom: 4px;
    color: #5a351e;
}

.settings-layout {
    display: grid;
    gap: 12px;
}

.hidden { display: none !important; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(22, 13, 7, 0.72);
}

.modal-window {
    width: min(1120px, 100%);
    max-height: calc(100vh - 36px);
    overflow: hidden;
    background: var(--paper);
    border: 1px solid var(--edge-dark);
    box-shadow: 0 18px 48px rgba(0,0,0,0.42);
}

.settings-modal-window {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.settings-editor {
    min-height: 0;
    overflow: auto;
    padding: 12px;
}

.settings-section {
    padding: 0 0 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid #b99458;
}

.settings-section h2 {
    margin: 0 0 10px;
    font-size: 15px;
    color: #4f301a;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.settings-field {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(100px, 1.1fr);
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-weight: 700;
}

.settings-field-check input {
    justify-self: start;
    width: auto;
    min-height: auto;
}

.settings-table input,
.settings-table select {
    min-width: 88px;
}

.modal-actions {
    position: sticky;
    bottom: -12px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 0 0;
    background: var(--paper);
    border-top: 1px solid #b99458;
}

.log-list {
    height: 320px;
    overflow: auto;
    padding: 8px;
    background: #fff8e6;
}

.log-entry {
    padding: 5px 0;
    border-bottom: 1px solid #dcc491;
}

.log-entry.error { color: #9f2118; font-weight: 700; }
.muted { color: var(--muted); }

@media (max-width: 820px) {
    .panel-header,
    .create-form,
    .inline-form {
        align-items: stretch;
        flex-direction: column;
    }

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

    .assign-form {
        grid-template-columns: 1fr;
        min-width: 220px;
    }

    .settings-field {
        grid-template-columns: 1fr;
    }

    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }
}
