:root {
    --bg: #101316;
    --panel: #1a2026;
    --panel-2: #222a31;
    --line: #36414c;
    --text: #f5f7f9;
    --muted: #a9b3bd;
    --accent: #54d3bd;
    --danger: #f05a5a;
    --tower: #ffd166;
}

* {
    box-sizing: border-box;
    scrollbar-color: #4c7892 #0b151d;
    scrollbar-width: thin;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: #0b151d;
}

*::-webkit-scrollbar-thumb {
    border: 2px solid #0b151d;
    border-radius: 4px;
    background: #4c7892;
}

*::-webkit-scrollbar-thumb:hover {
    background: #6697b3;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, #101316 0%, #151d20 52%, #201a17 100%);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.hub-back-link[hidden] {
    display: none;
}

.hub-back-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    margin: 14px 0 0 16px;
    padding: 0 12px;
    border: 1px solid rgba(84, 211, 189, 0.45);
    border-radius: 999px;
    background: rgba(16, 19, 22, 0.78);
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

main {
    min-height: 100vh;
}

.lobby-view {
    width: min(1120px, calc(100% - 36px));
    margin: 0 auto;
    padding: 28px 0 72px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.app-header h1,
.board-toolbar h1 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 3.4rem);
    letter-spacing: 0;
}

.app-header p,
.board-toolbar p {
    margin: 8px 0 0;
    color: var(--muted);
}

.lobby-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.panel,
.sidebar,
.board-toolbar,
.rule-panel {
    border: 1px solid var(--line);
    background: rgba(26, 32, 38, 0.92);
}

.panel {
    padding: 18px;
}

.panel h2,
.sidebar h2 {
    margin: 0 0 14px;
    font-size: 1rem;
}

label {
    display: grid;
    gap: 7px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 10px;
    background: #0f1418;
    color: var(--text);
}

button {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 12px;
    background: var(--panel-2);
    color: var(--text);
    font-weight: 700;
}

button:hover {
    border-color: var(--accent);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    border-color: var(--line);
}

button:disabled:hover {
    border-color: var(--line);
}

.danger-button {
    border-color: rgba(240, 90, 90, 0.7);
    color: #ffd8d8;
}

.form-error {
    min-height: 20px;
    margin-top: 10px;
    color: #ffb4b4;
    font-size: 0.85rem;
}

.room-list,
.players-list {
    display: grid;
    gap: 10px;
}

.room-card {
    display: grid;
    gap: 5px;
    width: 100%;
    min-height: 58px;
    text-align: left;
}

.room-card-code {
    color: var(--accent);
    font-size: 1.1rem;
}

.empty-list,
.rule-empty {
    color: var(--muted);
}

.game-view {
    display: grid;
    grid-template-columns: 280px minmax(640px, 1fr) 300px;
    gap: 14px;
    align-items: start;
    min-height: calc(100vh - 64px);
    padding: 14px;
}

.sidebar {
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    overflow: auto;
    padding: 16px;
}

.left-sidebar,
.right-sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.room-block {
    display: grid;
    gap: 10px;
}

.room-code {
    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 800;
}

.roll-button {
    min-height: 52px;
    border-color: rgba(84, 211, 189, 0.75);
    color: var(--accent);
    font-size: 1.05rem;
}

.last-roll {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
}

.toggle-row input {
    width: 18px;
    min-height: 18px;
    accent-color: var(--accent);
}

.roll-dot,
.player-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.player-card {
    display: grid;
    grid-template-columns: 14px 1fr auto;
    gap: 10px;
    align-items: center;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    background: #141a1f;
}

.player-card.offline {
    opacity: 0.55;
}

.player-card div {
    display: grid;
    min-width: 0;
}

.player-card strong,
.player-card span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-card span {
    color: var(--muted);
    font-size: 0.8rem;
}

.kick-button {
    min-height: 30px;
    color: #ffb4b4;
}

.board-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    min-width: 0;
}

.board-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 16px;
}

.board-toolbar h1 {
    font-size: 1.35rem;
}

.board-wrap {
    position: relative;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--line);
    background: #0c1013;
}

.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--board-size), minmax(0, 1fr));
    grid-auto-rows: auto;
    gap: 5px;
    min-height: 0;
    width: 100%;
    padding: 8px;
}

.path-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: visible;
}

.path-route {
    fill: none;
    stroke: rgba(84, 211, 189, 0.34);
    stroke-width: 0.07;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.square {
    position: relative;
    display: grid;
    grid-template-rows: 12px 28px 1fr;
    align-items: start;
    gap: 0px;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 1px solid #34414c;
    border-radius: 4px;
    padding: 6px;
    background: #172027;
    color: var(--text);
    text-align: left;
    z-index: 1;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}


.path-wall-top {
    border-top-color: rgba(84, 211, 189, 0.78);
    border-top-width: 3px;
}

.path-wall-right {
    border-right-color: rgba(84, 211, 189, 0.78);
    border-right-width: 3px;
}

.path-wall-bottom {
    border-bottom-color: rgba(84, 211, 189, 0.78);
    border-bottom-width: 3px;
}

.path-wall-left {
    border-left-color: rgba(84, 211, 189, 0.78);
    border-left-width: 3px;
}

.square > * {
    position: relative;
    z-index: 1;
}

.square:hover {
    border-color: var(--accent);
}

.square.selected {
    border-color: #ffe08a;
    box-shadow: 0 0 0 3px rgba(255, 224, 138, 0.55);
}

.square-tower {
    border-color: rgba(255, 209, 102, 0.75);
    background:
        linear-gradient(135deg, rgba(255, 209, 102, 0.18), transparent),
        #2b271c;
}

.square-start,
.square-finish {
    border-color: rgba(84, 211, 189, 0.8);
    background:
        linear-gradient(135deg, rgba(84, 211, 189, 0.22), transparent),
        #152624;
}

.square-number {
    color: var(--accent);
    font-size: 0.62rem;
    font-weight: 900;
}

.square img {
    width: 28px;
    height: 28px;
    margin-top: -8px;
    object-fit: contain;
    justify-self: center;
}

.square-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #d9e1e7;
    font-size: 11px;
    line-height: 1.24;
}

.piece-stack {
    position: absolute;
    inset: auto 0 0 0;
    height: 50px;
    pointer-events: none;
}

.player-piece {
    position: absolute;
    width: 26px;
    height: 26px;
    min-height: 26px;
    border: 2px solid #fff;
    border-radius: 50%;
    padding: 0;
    color: #101316;
    font-size: 0.72rem;
    font-weight: 900;
    pointer-events: auto;
    will-change: transform;
}

.player-piece.offline {
    filter: grayscale(1);
    opacity: 0.7;
}

.player-piece.piece-moved {
    animation: piece-hop 0.34s ease-out;
}

@keyframes piece-hop {
    0% {
        transform: translateY(0) scale(1);
    }

    35% {
        transform: translateY(-12px);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

.player-piece.piece-current-turn {
    box-shadow: 0 0 0 3px #ffe08a, 0 0 10px 3px rgba(255, 224, 138, 0.75);
    animation: piece-pulse 1.4s ease-in-out infinite;
}

@keyframes piece-pulse {
    0%, 100% {
        box-shadow: 0 0 0 3px #ffe08a, 0 0 8px 2px rgba(255, 224, 138, 0.6);
    }

    50% {
        box-shadow: 0 0 0 4px #ffe08a, 0 0 14px 5px rgba(255, 224, 138, 0.9);
    }
}

.player-card.current-turn {
    border-color: #ffe08a;
    box-shadow: 0 0 0 2px rgba(255, 224, 138, 0.5);
    background: #1c2118;
}

.drinks-wrap {
    display: grid;
    gap: 4px;
    margin-top: 4px;
}

.drinks-row {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 6px;
}

.drinks-count {
    color: var(--tower);
    font-size: 0.78rem;
    font-weight: 800;
}

.drinks-row > .drink-adjust-button,
.drink-adjust-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px !important;
    box-sizing: border-box;
    width: 28px;
    min-width: 28px;
    max-width: 28px;
    height: 28px;
    min-height: 28px;
    max-height: 28px;
    padding: 0;
    font-size: 0.85rem;
    font-weight: 900;
    line-height: 1;
}

.turn-assign-button {
    min-height: 28px;
    margin-top: 6px;
    border-color: rgba(255, 224, 138, 0.6);
    color: #ffe08a;
    font-size: 0.72rem;
}

.secondary-button {
    border-color: var(--line);
    color: var(--text);
}

.die-overlay-list {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap-reverse;
    justify-content: center;
    align-items: flex-end;
    gap: 10px;
    z-index: 50;
    pointer-events: none;
}

.die-overlay-item {
    display: grid;
    justify-items: center;
    gap: 4px;
    animation: die-pop 1.7s ease;
}

.die-overlay-label {
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(8, 10, 12, 0.75);
    font-size: 0.72rem;
    font-weight: 800;
}

.die-face {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    width: 84px;
    height: 84px;
    padding: 10px;
    border: 2px solid var(--die-color, var(--accent));
    border-radius: 14px;
    background: #f5f7f9;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 4px color-mix(in srgb, var(--die-color, var(--accent)) 30%, transparent);
}

@keyframes die-pop {
    0% {
        transform: scale(0.4) rotate(-12deg);
        opacity: 0;
    }

    15% {
        transform: scale(1.08) rotate(4deg);
        opacity: 1;
    }

    25% {
        transform: scale(1) rotate(0deg);
    }

    80% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: scale(0.9) rotate(0deg);
        opacity: 0;
    }
}

.die-pip {
    align-self: center;
    justify-self: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: transparent;
}

.die-pip-filled {
    background: var(--die-color, #101316);
}

.rule-heading {
    font-weight: 800;
}

.rule-waiting {
    padding: 8px 10px;
    border: 1px dashed var(--line);
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.85rem;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
    background: rgba(8, 10, 12, 0.72);
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    position: relative;
    display: grid;
    gap: 14px;
    width: min(480px, 100%);
    max-height: 80vh;
    overflow: auto;
    padding: 22px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 999px;
    font-size: 1.2rem;
    font-weight: 900;
    line-height: 1;
}

.modal-box h2 {
    margin: 0;
}

.modal-box p {
    margin: 0;
    color: var(--muted);
    line-height: 1.4;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.selection-player-list {
    display: grid;
    gap: 8px;
}

.selection-player-option {
    text-align: left;
}

.selection-player-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 600;
}

.slider-value {
    margin-top: 6px;
    color: var(--tower);
    font-weight: 700;
    text-align: center;
}

.rule-panel {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.rule-panel img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.rule-panel p {
    margin: 0;
    line-height: 1.45;
}

.rule-tag {
    width: fit-content;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 900;
}

.rule-tower {
    color: var(--tower);
}

.chat-log,
.game-log {
    flex: 1;
    min-height: 90px;
    max-height: 340px;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--line);
    background: #0f1418;
}

.game-log {
    flex: 0 0 150px;
    min-height: 120px;
    max-height: 170px;
}

.chat-entry {
    display: grid;
    gap: 3px;
    margin-bottom: 10px;
}

.chat-entry span {
    color: #d9e1e7;
    line-height: 1.35;
}

.game-log-entry {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 8px;
    margin-bottom: 8px;
    align-items: start;
}

.game-log-time {
    color: var(--muted);
    font-size: 0.72rem;
}

.game-log-text {
    padding-left: 8px;
    border-left: 3px solid var(--accent);
    color: #d9e1e7;
    font-size: 0.82rem;
    line-height: 1.3;
}

.chat-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

@media (max-width: 1180px) {
    .game-view {
        grid-template-columns: 240px minmax(520px, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
        height: auto;
        min-height: 100vh;
    }

    .right-sidebar {
        position: static;
        grid-column: 1 / -1;
        max-height: 360px;
    }
}

@media (max-width: 820px) {
    .lobby-grid {
        grid-template-columns: 1fr;
    }

    .game-view {
        display: block;
        padding: 56px 10px 14px;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

    .sidebar,
    .board-shell {
        margin-bottom: 12px;
    }

    .board-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }
}
