/* ============================================================
   MELOD-LE — Estil inspirat en Wordle original (light mode)
   ============================================================ */

:root {
    /* Paleta Wordle */
    --bg: #ffffff;
    --text: #1a1a1b;
    --text-dim: #787c7e;
    --border: #d3d6da;
    --border-strong: #878a8c;
    --key-bg: #d3d6da;
    --key-bg-hover: #bfc2c6;

    --correct: #6aaa64;
    --present: #c9b458;
    --absent:  #787c7e;

    --btn-dark: #1a1a1b;
    --btn-dark-hover: #000000;

    --modal-backdrop: rgba(0, 0, 0, 0.5);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-strong: 0 8px 40px rgba(0, 0, 0, 0.18);

    --font: "Helvetica Neue", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 12px;
    -webkit-font-smoothing: antialiased;
}

/* ============ TOP BAR ============ */
.topbar {
    width: 100%;
    max-width: 480px;
    display: flex;
    align-items: center;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    font-family: "Times New Roman", Georgia, serif;
    font-weight: 700;
    font-size: 1.7rem;
    letter-spacing: 0.5px;
    text-align: center;
    line-height: 1;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    transition: background 0.15s ease;
    font-family: inherit;
}

.icon-btn:hover { background: var(--border); }
.icon-btn.hidden { visibility: hidden; }

.spacer-l { flex: 1; }

/* ============ VIEWS ============ */
.view {
    width: 100%;
    max-width: 480px;
    flex: 1;
    min-height: 0;
    max-height: 760px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 4px 8px;
    animation: fadeIn 0.25s ease;
}

.view.hidden { display: none; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============ LANDING ============ */
.splash {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 16px;
    padding: 14px;
}

.splash-icon { margin-bottom: 6px; }

.preview-row {
    display: flex;
    gap: 5px;
}

.preview-cell {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.3px;
    color: var(--text);
    text-transform: uppercase;
    animation: flipIn 0.6s ease both;
}

.preview-cell:nth-child(1) { animation-delay: 0.1s; }
.preview-cell:nth-child(2) { animation-delay: 0.25s; }
.preview-cell:nth-child(3) { animation-delay: 0.4s; }
.preview-cell:nth-child(4) { animation-delay: 0.55s; }
.preview-cell:nth-child(5) { animation-delay: 0.7s; }

.preview-cell.correct { background: var(--correct); border-color: var(--correct); color: white; }
.preview-cell.present { background: var(--present); border-color: var(--present); color: white; }
.preview-cell.absent  { background: var(--absent);  border-color: var(--absent);  color: white; }

@keyframes flipIn {
    0%   { transform: rotateX(0); }
    50%  { transform: rotateX(-90deg); }
    100% { transform: rotateX(0); }
}

.splash-title {
    font-family: "Times New Roman", Georgia, serif;
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1;
}

.splash-tagline {
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text);
    max-width: 340px;
}

.splash-sub {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-top: -6px;
}

.splash-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 240px;
    margin-top: 4px;
}

.splash-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.3px;
    margin-top: 10px;
}

/* ============ BOTONS ============ */
.btn {
    border: 2px solid transparent;
    border-radius: 999px;
    padding: 12px 22px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    letter-spacing: 0.2px;
}

.btn:active { transform: scale(0.97); }

.btn-play {
    background: var(--btn-dark);
    color: white;
    border-color: var(--btn-dark);
}

.btn-play:hover {
    background: var(--btn-dark-hover);
    border-color: var(--btn-dark-hover);
}

.btn-outlined {
    background: transparent;
    color: var(--text);
    border-color: var(--text);
}

.btn-outlined:hover {
    background: var(--text);
    color: white;
}

.btn-dark {
    background: var(--btn-dark);
    color: white;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.9rem;
    border-color: var(--btn-dark);
}

.btn-dark:hover { background: var(--btn-dark-hover); }
.btn-dark:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
    background: white;
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.9rem;
}

.btn-ghost:hover { background: var(--border); }

.btn-listen {
    background: white;
    color: var(--text);
    border: 2px solid var(--text);
    border-radius: 999px;
    padding: 8px 18px;
    font-size: 0.88rem;
}

.btn-listen:hover {
    background: var(--text);
    color: white;
}

/* ============ SELECTOR DE NIVELLS ============ */
.levels-header {
    text-align: center;
    flex-shrink: 0;
}

.levels-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.progress-summary {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.progress-summary strong { color: var(--text); }

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.level-card {
    background: white;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    color: var(--text);
    text-align: center;
    min-height: 0;
}

.level-card:hover:not(.locked) {
    border-color: var(--text);
    transform: translateY(-2px);
}

.level-card .level-num {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
}

.level-card .level-name {
    font-size: 0.7rem;
    color: var(--text-dim);
    line-height: 1.2;
}

.level-card.completed {
    background: var(--correct);
    border-color: var(--correct);
}
.level-card.completed .level-num,
.level-card.completed .level-name { color: white; }
.level-card.completed .level-num::after {
    content: " ✓";
    font-size: 0.8rem;
}

.level-card.current {
    border-color: var(--text);
    border-width: 3px;
}

.level-card.locked {
    cursor: not-allowed;
    background: #f5f5f6;
    opacity: 0.55;
}

.level-card.locked .level-num::before {
    content: "🔒 ";
    font-size: 0.75rem;
}

/* ============ VISTA JOC ============ */
.game-header {
    text-align: center;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.level-indicator {
    display: inline-block;
    background: var(--text);
    color: white;
    padding: 4px 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.3px;
}

.melody-title {
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.88rem;
}

main {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.controls {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.grid {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    padding: 2px;
    flex: 1;
    min-height: 0;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    min-height: 0;
}

.cell {
    background: white;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
    color: var(--text);
    text-transform: uppercase;
    min-height: 0;
}

.cell.filled {
    border-color: var(--border-strong);
    animation: pop 0.12s ease;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.cell.locked {
    background: #f0f0f1;
    border-color: var(--border);
    color: var(--text-dim);
}

.cell.flip { animation: flipReveal 0.5s ease forwards; }

@keyframes flipReveal {
    0%   { transform: rotateX(0); }
    50%  { transform: rotateX(-90deg); }
    100% { transform: rotateX(0); }
}

.cell.correct { background: var(--correct); border-color: var(--correct); color: white; }
.cell.present { background: var(--present); border-color: var(--present); color: white; }
.cell.absent  { background: var(--absent);  border-color: var(--absent);  color: white; }

.row.shake { animation: shake 0.5s ease; }

.row.won .cell { animation: bounce 0.6s ease; }
.row.won .cell:nth-child(1) { animation-delay: 0.0s; }
.row.won .cell:nth-child(2) { animation-delay: 0.1s; }
.row.won .cell:nth-child(3) { animation-delay: 0.2s; }
.row.won .cell:nth-child(4) { animation-delay: 0.3s; }
.row.won .cell:nth-child(5) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 20% { transform: translateY(0); }
    40% { transform: translateY(-18px); }
    60% { transform: translateY(0); }
    80% { transform: translateY(-6px); }
    100% { transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

button:focus-visible,
.level-card:focus-visible,
.key:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 2px;
}

/* ============ TECLAT ============ */
.keyboard {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    flex-shrink: 0;
}

.key {
    background: var(--key-bg);
    color: var(--text);
    border: none;
    border-radius: 4px;
    padding: 12px 2px;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease;
    font-family: inherit;
    text-transform: uppercase;
}

.key:hover { background: var(--key-bg-hover); }
.key:active { transform: scale(0.94); }

.key.correct { background: var(--correct); color: white; }
.key.present { background: var(--present); color: white; }
.key.absent  { background: var(--absent);  color: white; }

.action-bar {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    flex-shrink: 0;
}

.action-bar .btn { flex: 1; }

/* ============ MISSATGES ============ */
.message {
    text-align: center;
    min-height: 20px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    flex-shrink: 0;
    transition: opacity 0.3s ease;
}

.message:empty { min-height: 0; padding: 0; }

.message.success {
    background: var(--correct);
    color: white;
}

.message.error {
    background: #ffe3e3;
    color: #a00;
    border: 1px solid #f5a0a0;
}

.message.info {
    background: var(--text);
    color: white;
}

/* ============ FOOTER ============ */
footer {
    width: 100%;
    max-width: 480px;
    padding: 6px 0 10px;
    text-align: center;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.btn-reset {
    background: transparent;
    color: var(--text-dim);
    border: none;
    padding: 4px 10px;
    font-size: 0.72rem;
    cursor: pointer;
    font-family: inherit;
    text-decoration: underline;
    transition: color 0.15s ease;
}

.btn-reset:hover { color: #c0392b; }

/* ============ MODAL ============ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--modal-backdrop);
    cursor: pointer;
}

.modal-box {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 28px 24px 20px;
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-strong);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding-bottom: 3px;
    transition: background 0.15s ease;
}

.modal-close:hover { background: var(--border); }

.modal-title {
    font-family: "Times New Roman", Georgia, serif;
    font-size: 1.6rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.modal-lead {
    font-size: 0.95rem;
    margin-bottom: 14px;
}

.modal-rules {
    padding-left: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 14px;
}

.modal-rules li { margin-bottom: 2px; }

.modal-divider {
    height: 1px;
    background: var(--border);
    margin: 14px 0;
}

.modal-subtitle {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.example {
    margin-bottom: 12px;
}

.example-row {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}

.ex-cell {
    width: 34px;
    height: 34px;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.3px;
    color: var(--text);
    background: white;
}

.ex-cell.correct { background: var(--correct); border-color: var(--correct); color: white; }
.ex-cell.present { background: var(--present); border-color: var(--present); color: white; }
.ex-cell.absent  { background: var(--absent);  border-color: var(--absent);  color: white; }

.example p {
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.4;
}

.modal-foot {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-align: center;
}

/* ============ RESPONSIVE ============ */
@media (max-height: 720px) {
    .splash-title { font-size: 2rem; }
    .splash-tagline { font-size: 0.9rem; }
    .preview-cell { width: 36px; height: 36px; font-size: 1rem; }
    .cell { font-size: 0.85rem; }
    .key { padding: 10px 2px; font-size: 0.78rem; }
}

@media (max-width: 380px) {
    .brand { font-size: 1.4rem; }
    .cell { font-size: 0.8rem; }
    .key { font-size: 0.72rem; padding: 10px 1px; }
}
