:root {
    --bg: #0f0f13;
    --panel: #171821;
    --accent: #7c4dff;
    --accent2: #ffb300;
    --muted: #9aa0a6;
    --text: #e8eaed;
    --ok: #43a047;
    --danger: #e53935;
    --border: #2a2c37;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    line-height: 1.5;
}

.container {
    width: min(1100px, 92vw);
    margin: 24px auto 48px;
    position: relative;
}

h1, h2, h3 {
    margin: 0 0 12px;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 22px;
    color: #c9ccf5;
}

label {
    display: block;
    margin: 10px 0 6px;
    color: #c8d1ff;
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    background: #0b0c12;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    transition: border 0.2s ease;
}

    input:focus, textarea:focus {
        border-color: var(--accent);
        outline: none;
    }

textarea {
    min-height: 100px;
    resize: vertical;
}

button {
    background: var(--accent);
    color: #fff;
    border: 0;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
}

    button:hover {
        filter: brightness(1.1);
        transform: translateY(-1px);
    }

    button:active {
        transform: translateY(0);
    }

    button.secondary {
        background: #273043;
    }

    button.danger {
        background: var(--danger);
    }

    button.ghost {
        background: transparent;
        border: 1px solid var(--border);
    }

    button.small {
        padding: 6px 10px;
        font-size: 12px;
    }

    button:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none !important;
    }

    /* Loader para botões */
    button .loader {
        display: inline-block;
        width: 12px;
        height: 12px;
        border: 2px solid #ffffff;
        border-radius: 50%;
        border-top-color: transparent;
        animation: spin 1s linear infinite;
        margin-right: 5px;
    }

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Painel esquerdo (setup) rolável */
.scrollable-panel {
    max-height: 80vh;
    overflow-y: auto;
    padding-right: 8px;
}

    .scrollable-panel::-webkit-scrollbar {
        width: 6px;
    }

    .scrollable-panel::-webkit-scrollbar-track {
        background: var(--bg);
    }

    .scrollable-panel::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 3px;
    }

        .scrollable-panel::-webkit-scrollbar-thumb:hover {
            background: var(--muted);
        }

/* Layout de configuração */
.setup-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 18px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

/* Estilos para modelos de verso */
.models-wrap {
    margin: 12px 0;
}

.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin: 10px 0;
}

.model-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

    .model-item img {
        width: 80px;
        height: 120px;
        object-fit: cover;
        border-radius: 8px;
        cursor: pointer;
        border: 2px solid transparent;
        transition: all 0.2s ease;
    }

        .model-item img.selected {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(124, 77, 255, 0.3);
        }

        .model-item img:hover {
            border-color: var(--accent2);
        }

    .model-item button {
        padding: 4px 8px;
        font-size: 11px;
    }

.no-models {
    text-align: center;
    padding: 20px;
    color: var(--muted);
    font-style: italic;
}

/* Miniaturas dos itens salvos */
.saved-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.saved-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: rgba(42, 44, 55, 0.5);
    border-radius: 10px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

    .saved-item:hover {
        background: rgba(42, 44, 55, 0.8);
        border-color: var(--border);
        transform: translateY(-2px);
    }

    .saved-item img {
        width: 56px;
        height: 84px;
        object-fit: cover;
        border-radius: 8px;
        flex-shrink: 0;
        border: 1px solid #222;
        box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    }

    .saved-item .fields {
        flex: 1;
        font-size: 14px;
        min-width: 0;
    }

        .saved-item .fields p {
            margin: 3px 0;
            line-height: 1.4;
        }

        .saved-item .fields b {
            color: #c8d1ff;
            margin-right: 4px;
        }

    .saved-item .num {
        margin-top: 6px;
        font-size: 11px;
        color: var(--muted);
    }

    .saved-item button {
        padding: 6px 10px;
        font-size: 12px;
        border-radius: 8px;
    }

.card-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 80px;
}

.empty-list {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    font-style: italic;
}

/* Remover setas internas do input number */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Mesa Principal */
.table-wrap {
    position: relative;
    width: min(1000px, 92vw);
    height: 64vh;
    margin: 10px auto 0;
    background: radial-gradient(ellipse at center, #1a103d 0%, #0a061f 100%);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: visible;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
}

.card-arc {
    position: absolute;
    inset: 0;
}

/* Carta */
.card {
    position: absolute;
    width: 120px;
    height: 180px;
    transform-style: preserve-3d;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    will-change: transform, left, top;
    user-select: none;
    z-index: 1;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}

    .card:hover {
        box-shadow: 0 0 25px rgba(124, 77, 255, 0.8);
        transform: translate(-50%, -50%) scale(1.05) !important;
    }

    .card .inner {
        position: relative;
        width: 100%;
        height: 100%;
        transform-style: preserve-3d;
        transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    }

.card-side {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #222;
    background: #111;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

    .card-side img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

.card-front {
    transform: rotateY(180deg);
}

/* Estados da Carta */
.card.center {
    transform: translate(-50%, -50%) scale(1.3) rotate(0deg) !important;
    z-index: 100;
    box-shadow: 0 0 20px rgba(124, 77, 255, 0.4);
}

.card.zoomed {
    transform: translate(-50%, -50%) scale(1.8) rotate(0deg) !important;
    z-index: 200;
    box-shadow: 0 0 30px rgba(124, 77, 255, 0.7);
}

.card.flipped .inner {
    transform: rotateY(180deg);
}

/* Info */
.info {
    text-align: center;
    margin-top: 16px;
    min-height: 96px;
    background: rgba(23, 24, 33, 0.7);
    border-radius: 12px;
    padding: 12px;
    backdrop-filter: blur(5px);
    border: 1px solid var(--border);
}

    .info h3 {
        margin: 6px 0;
        font-size: 20px;
        color: var(--accent);
    }

    .info p {
        margin: 4px auto;
        max-width: 780px;
        color: #d6d6e7;
        line-height: 1.5;
    }

    .info b {
        color: #c8d1ff;
    }

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 10px;
    background: rgba(23, 24, 33, 0.5);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.small-input {
    width: 6ch !important;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Utilitários */
.inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.full {
    grid-column: 1 / -1;
}

/* Notificações Toast */
.toast-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    background: var(--panel);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    z-index: 10000;
    animation: fadeIn 0.3s ease-in;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-width: 300px;
}

    .toast-message.success {
        border-left-color: var(--ok);
    }

    .toast-message.error {
        border-left-color: var(--danger);
    }

/* Efeitos de embaralhamento */
.shuffle-effect {
    animation: shuffleAnimation 0.8s ease-in-out;
}

@keyframes shuffleAnimation {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }

    50% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8) rotate(180deg);
    }

    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

/* Animações */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Elementos de jogo */
.game-stats {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(23, 24, 33, 0.8);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--muted);
    z-index: 100;
    backdrop-filter: blur(5px);
    border: 1px solid var(--border);
}

.refresh-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(23, 24, 33, 0.8);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    z-index: 100;
    backdrop-filter: blur(5px);
    transition: all 0.2s ease;
}

    .refresh-btn:hover {
        background: var(--accent);
        color: white;
        transform: translateY(-1px);
    }

    .refresh-btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none !important;
    }

/* Notificação de embaralhamento */
.shuffle-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(124, 77, 255, 0.9);
    color: white;
    padding: 20px 30px;
    border-radius: 15px;
    z-index: 10000;
    font-size: 18px;
    text-align: center;
    backdrop-filter: blur(10px);
    animation: shufflePulse 2s ease-in-out;
    box-shadow: 0 0 30px rgba(124, 77, 255, 0.5);
}

@keyframes shufflePulse {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
}

/* Mensagem de erro */
.error-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--danger);
    color: white;
    padding: 20px;
    border-radius: 10px;
    z-index: 10000;
    text-align: center;
    max-width: 80%;
    box-shadow: 0 4px 20px rgba(229, 57, 53, 0.3);
}

/* Responsivo */
@media (max-width: 768px) {
    .setup-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .container {
        margin: 16px auto 32px;
        padding: 0 10px;
    }

    .panel {
        padding: 12px;
    }

    .card {
        width: 100px;
        height: 150px;
    }

    .info {
        margin-top: 12px;
        min-height: 80px;
        padding: 8px;
        font-size: 14px;
    }

    .models-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 8px;
    }

    .model-item img {
        width: 70px;
        height: 105px;
    }

    .saved-item {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

        .saved-item img {
            align-self: center;
        }

        .saved-item .fields {
            text-align: left;
        }

    .card-actions {
        flex-direction: row;
        justify-content: center;
        width: 100%;
    }

    .topbar {
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }

    .game-stats, .refresh-btn {
        position: relative;
        top: unset;
        right: unset;
        left: unset;
        margin: 5px 0;
        width: fit-content;
    }

    .table-wrap {
        height: 55vh;
    }
}

@media (max-width: 480px) {
    .container {
        margin: 10px auto 24px;
    }

    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 18px;
    }

    button {
        padding: 8px 12px;
        font-size: 13px;
    }

    .card {
        width: 85px;
        height: 130px;
    }

    .info {
        font-size: 13px;
        padding: 6px;
    }

    .saved-item {
        padding: 8px;
    }

        .saved-item img {
            width: 50px;
            height: 75px;
        }
}

/* Melhorias de acessibilidade */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visível para acessibilidade */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --bg: #000000;
        --panel: #111111;
        --text: #ffffff;
        --border: #444444;
    }

    .card-side {
        border: 2px solid #000;
    }

    .saved-item {
        border: 1px solid #444;
    }
}

/* Dark mode suportado nativamente */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0a0a0a;
        --panel: #1a1a1a;
        --border: #333333;
    }
}