:root {
    --bg: #f4f5f3;
    --text: #111111;
    --muted: #666666;
    --card: #ffffff;
    --border: #d8d8d8;
    --accent: #437255;
    --error-bg: #fff1f1;
    --error-border: #d33;
    --success-bg: #f2fbf5;
}

* {
    box-sizing: border-box;
}

html,
body {
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.container {
    width: min(900px, calc(100% - 32px));
    margin: 48px auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.page-header > div {
    flex: 1;
    min-width: 0;
}

h1 {
    margin: 0 0 8px;
    font-size: clamp(40px, 5vw, 56px);
    line-height: 1.05;
}

h2 {
    margin: 0 0 24px;
    font-size: clamp(28px, 3vw, 34px);
    line-height: 1.1;
}

.muted {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
    font-size: 18px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    margin-bottom: 20px;
}

form {
    margin: 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 22px;
    margin-bottom: 28px;
}

.login-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    margin-bottom: 28px;
}

label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    font-size: 16px;
}

input {
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    background: #ffffff;
}

button,
.logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 0 34px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    font-size: 16px;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.logout:hover {
    opacity: 0.92;
}

input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

button:disabled,
.button-disabled {
    background: #999999 !important;
    color: #ffffff;
    opacity: 1;
    cursor: not-allowed;
    pointer-events: none;
}

.logout {
    background: #222222;
    white-space: nowrap;
    align-self: flex-start;
    margin-top: 4px;
    flex-shrink: 0;
}

.credits-status {
    display: block;
    width: 100%;
    margin: 18px 0 0;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
}

.credits-status.credits-ok {
    color: var(--accent) !important;
}

.credits-status.credits-empty {
    color: #9d1111 !important;
}

.error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 10px;
    padding: 12px;
    margin: 0 0 22px;
    color: #9d1111;
}

.hidden {
    display: none;
}

.error-box {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: #9d1111;
}

.success-box {
    background: var(--success-bg);
}

.result {
    position: relative;
    overflow: hidden;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.result-grid div {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.result-grid span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 8px;
}

.result-grid strong {
    display: block;
    font-size: 20px;
    word-break: break-word;
}

/* Confetti fisici via JavaScript */
.confetti {
    pointer-events: none;
    position: fixed;
    width: 0;
    height: 0;
    z-index: 9999;
    overflow: visible;
}

.confetti span {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--s);
    height: calc(var(--s) * 1.7);
    border-radius: 2px;
    background: var(--accent);
    opacity: 1;
    will-change: transform, opacity;
}

.confetti span:nth-child(3n) {
    background: #222222;
}

.confetti span:nth-child(3n + 1) {
    background: #d8d8d8;
}

.confetti span:nth-child(4n) {
    border-radius: 999px;
}

.powered-by {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 28px;
    text-align: center;
}

.powered-text {
    width: 100%;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

.powered-text em {
    color: var(--text);
    font-style: italic;
    font-weight: 400;
}

.powered-by img {
    width: 90px;
    height: auto;
    max-width: 90px;
    display: block;
    margin: 0 auto;
}

@media (max-width: 720px) {
    .container {
        width: min(100% - 24px, 900px);
        margin: 28px auto;
    }

    .page-header {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 16px;
    }

    .page-header > div {
        flex: 1;
        min-width: 0;
    }

    .grid,
    .result-grid {
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
    }

    .logout {
        width: auto;
        min-height: 44px;
        padding: 0 22px;
        margin-top: 0;
        flex-shrink: 0;
    }

    .card {
        padding: 20px;
    }
}