/* ==========================================================================
   1. VARIABLES I TIPOGRAFIA DINÀMICA PER A MÒBIL
   ========================================================================== */
:root {
    --bg-main: #18181b;
    --bg-card: #27272a;
    --bg-subtle: #3f3f46;
    --bg-option: #4a4a52;
    --bg-option-hover: #63636e;
    --text-main: #fafafa;
    --text-muted: #d4d4d8;
    --text-light: #ffffff;
    --primary: #ffcc00;
    --primary-bg: #854d0e;
    --success: #22c55e;
    --danger: #ef4444;
    --border-color: #52525b;
}

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: clamp(17px, 4.5vw, 22px);
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
}

.mobile-app {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
}

.app-header h1 {
    font-size: clamp(1.6rem, 6.5vw, 2.3rem);
    margin: 4px 0 10px 0;
    text-align: center;
    color: var(--primary);
    font-weight: 800;
}

.app-content {
    flex: 1;
    width: 100%;
    position: relative;
}

.screen {
    width: 100%;
}

/* ==========================================================================
   2. BOTONS I TARGETES A MIDA MÀXIMA
   ========================================================================== */
button {
    font-family: inherit;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    touch-action: manipulation;
}

.card-box {
    background: var(--bg-card);
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 12px;
    font-size: 1.15rem;
    line-height: 1.5;
}

.section-title {
    color: var(--primary);
    text-align: center;
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1.6rem;
}

/* ==========================================================================
   3. MENÚ PRINCIPAL
   ========================================================================== */
.user-badge {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.15rem;
}

#current-nickname {
    color: var(--success);
    font-size: 1.25rem;
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 8px 14px;
    font-size: 1.05rem;
}

.menu-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-group {
    display: flex;
    gap: 8px;
}

.btn-small {
    background: var(--bg-subtle);
    color: var(--text-main);
    padding: 8px 14px;
    font-size: 1.05rem;
}

.btn-highlight {
    color: var(--primary);
    border: 1px solid var(--primary);
}

.levels-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.levels-container button {
    background-color: var(--primary);
    color: #111;
    padding: 16px 14px;
    font-size: 1.25rem;
    line-height: 1.4;
    text-align: left;
    width: 100%;
}

.levels-container button span {
    font-size: 1rem !important;
    display: block;
    margin-top: 4px;
    color: #222;
}

.scores-card {
    background: var(--bg-card);
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.scores-card h3 {
    margin: 0 0 10px 0;
    font-size: 1.15rem;
    color: var(--text-muted);
    text-align: center;
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
}

.score-table th {
    padding: 8px 2px;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.05rem;
    color: var(--text-light);
}

.score-table td {
    padding: 10px 2px;
}

.score-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
}

.trophy-btn {
    cursor: pointer;
    font-size: 1.25rem;
}

.donation-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 25px;
}

.btn-aixeta {
    background: #e11d48;
    color: white;
    width: 100%;
    padding: 15px;
    font-size: 1.15rem;
}

.btn-share-link {
    background: var(--bg-subtle);
    color: var(--text-light);
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
}

/* ==========================================================================
   4. PANTALLA DE JOC (COMPACTA I OPTIMITZADA EN VERTICAL)
   ========================================================================== */
#game-screen {
    position: relative;
    width: 100%;
    padding-bottom: 10px;
}

/* Capa de petjades frontal semitransparent */
#timer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    opacity: 0.38;
    overflow: hidden;
}

/* Capçalera de joc escurçada */
.game-topbar {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 6px;
    position: relative;
    z-index: 2;
}

#level-info {
    flex: 1;
    background: var(--bg-card);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1.35;
    color: var(--text-light);
}

.btn-abandonar {
    background: var(--bg-card);
    color: var(--primary);
    padding: 0 14px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

#sub-task {
    color: var(--primary);
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
    font-size: 1.15rem;
    position: relative;
    z-index: 2;
}

/* Marcador compactat al màxim */
.scoreboard {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 3px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    line-height: 1;
    position: relative;
    z-index: 2;
}

#timer2 {
    font-size: 1.7rem;
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
    line-height: 1;
    margin: 0;
}

#score-display {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin: 0;
}

/* Dades de la tirada estilitzades i amb menys alçada residual */
.dades {
    background: var(--bg-card);
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: clamp(1.15rem, 4.8vw, 1.45rem);
    line-height: 1.3;
    text-align: center;
    position: relative;
    z-index: 2;
    border: 1px solid var(--border-color);
}

.dades strong {
    color: var(--primary);
    font-size: 1.15em;
}

.opcions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    position: relative;
    z-index: 2;
}

.opcio {
    background: var(--bg-option);
    color: var(--text-main);
    padding: 16px 14px;
    border-radius: 10px;
    font-size: clamp(1.2rem, 5.2vw, 1.45rem);
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.opcio:active {
    background: var(--bg-option-hover);
    border-color: var(--primary);
}

#feedback {
    min-height: 1.8rem;
    text-align: center;
    font-weight: 800;
    font-size: 1.15rem;
    margin-bottom: 6px;
    position: relative;
    z-index: 2;
}

#helper-text {
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 10px;
    position: relative;
    z-index: 2;
}

/* Selector de números en graella (Nivell D-E) */
.grid-dir {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.grid-dir button {
    padding: 14px 4px;
    font-size: 1.35rem;
    font-weight: 800;
}

/* ==========================================================================
   5. MODALS, AJUDA I PERFILS
   ========================================================================== */
.share-box {
    text-align: center;
    margin: 15px 0;
}

.share-box p {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.share-buttons {
    display: flex;
    gap: 8px;
}

.btn-social {
    flex: 1;
    padding: 14px 6px;
    font-size: 1.05rem;
    color: white;
}

.btn-wa { background: #22c55e; }
.btn-x { background: #000; border: 1px solid #444; }
.btn-tg { background: #0284c7; }
.btn-clip { background: #52525b; flex: 0 0 50px; font-size: 1.3rem; }

.btn-full-gray {
    background: var(--bg-subtle);
    color: var(--text-main);
    width: 100%;
    padding: 16px;
    font-size: 1.2rem;
    margin-top: 15px;
}

.btn-full-gold {
    background: var(--primary);
    color: #111;
    width: 100%;
    padding: 16px;
    font-size: 1.25rem;
    margin-top: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.15rem;
}

.btn-reroll {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 8px 12px;
    font-size: 1rem;
}

#new-profile-comarca {
    padding: 10px;
    border-radius: 8px;
    background: var(--bg-main);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    font-size: 1.05rem;
    width: 60%;
}

.btn-create-profile {
    background: var(--success);
    color: #111;
    padding: 15px;
    width: 100%;
    font-size: 1.2rem;
}

.help-text {
    font-size: 1.15rem;
    line-height: 1.6;
}

.help-text p {
    margin-bottom: 12px;
}

.help-text ul {
    margin: 10px 0;
    padding-left: 25px;
}

.help-text li {
    margin-bottom: 6px;
}

.btn-revoke-consent {
    background: var(--primary-bg);
    color: var(--primary);
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    margin-top: 12px;
}

/* ==========================================================================
   6. BANNER DE COOKIES
   ========================================================================== */
#cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #18181b;
    border-top: 3px solid var(--primary);
    padding: 18px 14px;
    z-index: 99999;
    font-size: 1.05rem;
    line-height: 1.5;
    display: none;
}

.cookie-buttons {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.btn-cookie-acc {
    background: var(--success);
    color: white;
    flex: 1;
    padding: 15px;
    font-size: 1.15rem;
}

.btn-cookie-rej {
    background: var(--bg-subtle);
    color: white;
    flex: 1;
    padding: 15px;
    font-size: 1.15rem;
}

/* ==========================================================================
   7. MODE CLAR
   ========================================================================== */
body.light-mode {
    --bg-main: #f4f4f5;
    --bg-card: #ffffff;
    --bg-subtle: #e4e4e7;
    --bg-option: #d4d4d8;
    --bg-option-hover: #a1a1aa;
    --text-main: #09090b;
    --text-muted: #52525b;
    --text-light: #18181b;
    --primary: #d97706;
    --border-color: #d4d4d8;
}

body.light-mode .levels-container button {
    background-color: #f59e0b;
    color: #000;
}

body.light-mode .opcio {
    color: #09090b;
    border-color: #d4d4d8;
}

body.light-mode .scoreboard {
    background: rgba(255, 255, 255, 0.85);
}