:root {
    --bg-deep: #12353c;
    --bg-mid: #1f5560;
    --ink: #12282d;
    --ink-soft: #3a5d64;
    --line: rgba(18, 53, 60, 0.14);
    --panel: rgba(241, 248, 247, 0.94);
    --accent: #0f766e;
    --accent-deep: #0b5a54;
    --ok: #0f766e;
    --shadow: 0 18px 50px rgba(8, 28, 32, 0.2);
    --radius: 18px;
    --font: Ubuntu, Arial, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body,
button,
input,
select,
textarea,
svg text {
    font-family: var(--font);
}

html,
body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    background:
        radial-gradient(1100px 640px at 8% -8%, rgba(15, 118, 110, 0.22), transparent 55%),
        radial-gradient(900px 560px at 96% 4%, rgba(37, 99, 235, 0.12), transparent 48%),
        linear-gradient(155deg, #d5e8e6 0%, #eef5f4 45%, #dce9e7 100%);
}

body {
    min-height: 100vh;
}

button,
input,
select {
    font: inherit;
}

#app {
    min-height: 100vh;
}

.screen {
    display: none;
    min-height: 100vh;
}

.screen.is-active {
    display: block;
}

.brand {
    margin: 0;
    font-size: clamp(2.4rem, 7vw, 4.6rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 0.95;
    color: var(--bg-deep);
}

.brand--sm {
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.setup-shell {
    width: min(920px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2.5rem 0 3rem;
    display: grid;
    gap: 1.75rem;
}

.setup-hero h1 {
    margin: 0.55rem 0 0;
    font-size: clamp(1.15rem, 2.5vw, 1.45rem);
    font-weight: 500;
    color: var(--ink-soft);
}

.setup-lead {
    margin: 0.75rem 0 0;
    max-width: 34rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

.setup-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.1rem;
    margin-top: 1rem;
}

.link-btn {
    border: 0;
    padding: 0;
    background: none;
    color: var(--accent-deep);
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

.link-btn:hover {
    color: var(--bg-deep);
}

.info-shell {
    width: min(760px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.75rem 0 3rem;
    display: grid;
    gap: 1.25rem;
}

.info-header .brand {
    margin-top: 0.85rem;
}

.info-header h1 {
    margin: 0.45rem 0 0;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    letter-spacing: -0.03em;
    color: var(--bg-deep);
}

.info-lead {
    margin: 0.55rem 0 0;
    color: var(--ink-soft);
    line-height: 1.45;
    max-width: 36rem;
}

.info-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.35rem 1.3rem 1.45rem;
    display: grid;
    gap: 1.25rem;
}

.howto-steps {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.9rem;
    counter-reset: howto;
}

.howto-steps li {
    position: relative;
    padding: 0.95rem 1rem 0.95rem 3.4rem;
    border-radius: 14px;
    background: rgba(18, 53, 60, 0.04);
    border: 1px solid transparent;
}

.howto-steps li::before {
    counter-increment: howto;
    content: counter(howto);
    position: absolute;
    left: 0.85rem;
    top: 0.95rem;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 9px;
    display: grid;
    place-items: center;
    background: var(--bg-deep);
    color: #f3fffd;
    font-size: 0.9rem;
    font-weight: 700;
}

.howto-steps h2,
.info-tips h2,
.rules-panel h2 {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
    color: var(--bg-deep);
}

.howto-steps p,
.info-tips p,
.info-tips li,
.rules-panel p,
.rules-panel li {
    margin: 0;
    color: var(--ink-soft);
    line-height: 1.5;
}

.info-tips ul,
.rules-panel ul,
.rules-panel ol {
    margin: 0.45rem 0 0;
    padding-left: 1.2rem;
    display: grid;
    gap: 0.35rem;
}

.rules-panel {
    gap: 1.4rem;
}

.rules-panel section {
    padding-bottom: 1.15rem;
    border-bottom: 1px solid var(--line);
}

.rules-panel section:last-of-type {
    border-bottom: 0;
    padding-bottom: 0;
}

.rules-panel code {
    font-family: var(--font);
    font-size: 0.92em;
    padding: 0.1em 0.35em;
    border-radius: 6px;
    background: rgba(18, 53, 60, 0.08);
    color: var(--bg-deep);
}

.info-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.side-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}

.setup-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem 1.35rem 1.5rem;
    display: grid;
    gap: 1.25rem;
    backdrop-filter: blur(8px);
}

.setup-field {
    display: grid;
    gap: 0.55rem;
}

.setup-field > label,
.field-label {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

select,
input[type='text'] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    background: #fff;
    color: var(--ink);
}

select:focus,
input[type='text']:focus {
    outline: 2px solid rgba(15, 118, 110, 0.35);
    outline-offset: 1px;
}

.player-names {
    display: grid;
    gap: 0.55rem;
}

.name-row {
    display: grid;
    grid-template-columns: 18px auto 1fr;
    gap: 0.65rem;
    align-items: center;
}

.name-row__swatch,
.order-item__swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.name-row__label {
    font-size: 0.9rem;
    color: var(--ink-soft);
    white-space: nowrap;
}

.order-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.45rem;
}

.order-item {
    display: grid;
    grid-template-columns: 28px 14px 1fr;
    gap: 0.65rem;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border-radius: 12px;
    background: rgba(15, 42, 46, 0.04);
    border: 1px solid transparent;
    cursor: grab;
    user-select: none;
}

.order-item.is-dragging {
    opacity: 0.55;
    border-color: rgba(15, 118, 110, 0.4);
}

.order-item__pos {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--bg-deep);
    color: #f7faf9;
    font-size: 0.85rem;
    font-weight: 700;
}

.hint {
    margin: 0;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.setup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 0.78rem 1.1rem;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #f3fffd;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-deep);
}

.btn-secondary {
    background: var(--bg-deep);
    color: #f3fafa;
}

.btn-ghost {
    background: transparent;
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

.btn-sm {
    padding: 0.45rem 0.75rem;
    font-size: 0.88rem;
}

.game-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(280px, 340px) 1fr;
    gap: 1rem;
    padding: 1rem;
}

.side-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: calc(100vh - 2rem);
    overflow: auto;
}

.side-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.panel-block h2 {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--bg-deep);
}

.players-list {
    display: grid;
    gap: 0.5rem;
}

.player-card {
    display: grid;
    grid-template-columns: 8px 1fr;
    gap: 0.7rem;
    padding: 0.7rem 0.75rem;
    border-radius: 12px;
    background: rgba(15, 42, 46, 0.04);
    border: 1px solid transparent;
}

.player-card.is-current {
    border-color: color-mix(in srgb, var(--player-color) 55%, transparent);
    background: color-mix(in srgb, var(--player-color) 12%, white);
}

.player-card__color {
    width: 8px;
    border-radius: 999px;
    background: var(--player-color);
}

.player-card__name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
}

.player-card__stats {
    margin-top: 0.25rem;
    display: flex;
    gap: 0.75rem;
    font-size: 0.88rem;
    color: var(--ink-soft);
}

.turn-dot,
.winner-badge {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}

.turn-dot {
    background: var(--player-color);
    color: #fff;
}

.winner-badge {
    background: rgba(31, 122, 92, 0.15);
    color: var(--ok);
}

.status-grid {
    margin: 0;
    display: grid;
    gap: 0.55rem;
}

.status-grid > div {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 0.5rem;
    align-items: baseline;
}

.status-grid dt {
    margin: 0;
    font-size: 0.82rem;
    color: var(--ink-soft);
}

.status-grid dd {
    margin: 0;
    font-weight: 500;
    text-align: right;
}

.events-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.4rem;
    max-height: 180px;
    overflow: auto;
}

.events-list li {
    font-size: 0.86rem;
    line-height: 1.35;
    color: var(--ink-soft);
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    background: rgba(15, 42, 46, 0.04);
}

.board-wrap {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 2rem);
    padding: 0.5rem;
}

.board {
    width: min(100%, calc(100vh - 2.5rem), 860px);
    aspect-ratio: 1;
}

.game-board-svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 16px 28px rgba(8, 24, 28, 0.18));
}

.board-backdrop {
    fill: #10272c;
}

.cell-path {
    stroke: rgba(15, 42, 46, 0.35);
    stroke-width: 1.2;
    transition: fill 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

.cell-available:hover {
    filter: brightness(1.08);
}

.cell-locked {
    opacity: 0.42;
}

.cell-occupied {
    opacity: 1;
}

.cell-pending-ring {
    stroke-width: 2;
}

.pending-ring-marker {
    stroke-width: 3;
    stroke-dasharray: 8 6;
    opacity: 0.85;
    filter: url(#pending-glow);
}

.cell-value {
    font-weight: 700;
    user-select: none;
}

.center-circle {
    stroke: rgba(255, 255, 255, 0.35);
    stroke-width: 2;
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.center-locked {
    opacity: 0.55;
}

.center-pending {
    stroke-width: 3;
    stroke-dasharray: 6 4;
}

.center-available:hover {
    filter: brightness(1.1);
}

.center-label {
    fill: #fffaf4;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.center-value {
    fill: #fffaf4;
    font-size: 28px;
    font-weight: 700;
}

.results-overlay {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    padding: 1rem;
    background: rgba(10, 24, 28, 0.55);
    backdrop-filter: blur(4px);
    z-index: 40;
}

.results-overlay.is-open {
    display: grid;
}

.results-modal {
    width: min(480px, 100%);
    background: #f4fbfa;
    border-radius: 20px;
    padding: 1.5rem 1.4rem 1.35rem;
    box-shadow: var(--shadow);
    display: grid;
    gap: 1rem;
    animation: pop-in 0.28s ease;
}

.results-title {
    margin: 0;
    text-align: center;
    font-size: clamp(2rem, 6vw, 2.8rem);
    letter-spacing: -0.03em;
    color: var(--bg-deep);
}

.results-lead,
.results-winner {
    margin: 0;
    text-align: center;
    line-height: 1.45;
}

.results-winner {
    font-weight: 700;
    color: var(--ok);
}

.results-scores {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.45rem;
}

.results-scores li {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.6rem 0.7rem;
    border-radius: 10px;
    background: rgba(15, 42, 46, 0.05);
    border-left: 4px solid var(--player-color);
}

.results-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%) translateY(120%);
    background: var(--bg-deep);
    color: #f4fafa;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    font-size: 0.92rem;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
    z-index: 50;
    max-width: min(90vw, 420px);
    text-align: center;
}

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

@keyframes pop-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 900px) {
    .game-shell {
        grid-template-columns: 1fr;
        padding: 0.75rem;
    }

    .side-panel {
        max-height: none;
        order: 2;
    }

    .board-wrap {
        order: 1;
        min-height: auto;
        padding: 0;
    }

    .board {
        width: min(100%, 92vw);
    }
}

@media (max-width: 560px) {
    .setup-shell,
    .info-shell {
        width: calc(100% - 1.25rem);
        padding-top: 1.5rem;
    }

    .setup-actions,
    .info-actions {
        flex-direction: column;
    }

    .setup-actions .btn,
    .info-actions .btn {
        width: 100%;
    }

    .howto-steps li {
        padding-left: 3.1rem;
    }

    .side-panel__head {
        flex-direction: column;
        align-items: flex-start;
    }

    .name-row {
        grid-template-columns: 14px 1fr;
        grid-template-rows: auto auto;
    }

    .name-row__label {
        grid-column: 2;
    }

    .name-row input {
        grid-column: 1 / -1;
    }

    .center-label {
        font-size: 11px;
    }

    .center-value {
        font-size: 22px;
    }
}
