/* ===== Crossquest — Dark theme ===== */

:root {
    --cq-green: #065f0b;
}

/* Prevent double-tap zoom on all interactive elements */
.cq-page * {
    touch-action: manipulation;
}

body:has(.cq-page) {
    background: #111827;
    overflow: hidden;
    height: 100vh;
}

body:has(.cq-page) header,
body:has(.cq-page) footer {
    display: none !important;
}

body:has(.cq-page) > .container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
}

.cq-page {
    background: #111827;
    height: 100vh;
    overflow-y: auto;
    color: #e5e7eb;
    padding: 1rem;
    max-width: 480px;
    margin: 0 auto;
}

/* Top icon row (home + ? on word page) */
.cq-icon-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

/* Home button (top-left of game header) */
.cq-home-btn {
    position: absolute;
    top: 0;
    left: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 1px solid #4b5563;
    background: #1f2937;
    color: #9ca3af;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    text-decoration: none;
}

.cq-home-btn:hover {
    background: #374151;
    color: #e5e7eb;
}

.cq-home-btn:hover img {
    filter: invert(1);
}

/* Header */
.cq-header {
    position: relative;
    text-align: center;
    margin-bottom: 1.5rem;
}

.cq-htp-btn {
    position: absolute;
    top: 0;
    right: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 1px solid #4b5563;
    background: #1f2937;
    color: #9ca3af;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.cq-htp-btn:hover {
    background: #374151;
    color: #e5e7eb;
}

/* How-to-play modal */
.cq-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.cq-modal-backdrop.cq-modal-visible {
    display: flex;
}

.cq-modal {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
    max-width: 420px;
    position: relative;
    color: #e5e7eb;
}

.cq-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}

.cq-modal-close:hover {
    color: #e5e7eb;
}

.cq-modal-title {
    font-size: 1.2rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 0.5rem;
    color: #f9fafb;
}

.cq-modal-sub {
    font-size: 0.85rem;
    color: #9ca3af;
    text-align: center;
    margin-bottom: 1.25rem;
    line-height: 1.4;
}

.cq-htp-examples {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

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

.cq-htp-row .cq-tile {
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
}

.cq-htp-label {
    font-size: 0.85rem;
    color: #d1d5db;
    margin: 0;
    line-height: 1.3;
    text-align: center;
    padding-bottom: 10px;
}

.cq-htp-strike {
    color: #4b5563;
}

.cq-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: #D4AF37;
    margin: 0 0 0.25rem;
}

.cq-date {
    font-size: 0.85rem;
    color: #9ca3af;
    margin: 0 0 0.25rem;
}

.cq-progress {
    font-size: 1rem;
    color: #d1d5db;
    margin: 0;
}

.cq-progress-sep {
    color: #6b7280;
    margin: 0 0.2em;
}

.cq-score-badge {
    margin-left: 0.75em;
    background: #5c4a10;
    border: 1px solid #D4AF37;
    color: #D4AF37;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.1em 0.5em;
    border-radius: 4px;
}

.cq-score-inline {
    color: #D4AF37;
    font-weight: 700;
}

.cq-entry-score {
    color: #D4AF37;
    font-weight: 700;
    font-size: 0.85rem;
    margin-left: auto;
}

.cq-entry-score-zero {
    color: #6b7280;
}

/* Win banner */
.cq-win-banner {
    background: linear-gradient(135deg, #92400e, #78350f);
    border: 1px solid #D4AF37;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: center;
    color: #D4AF37;
    font-weight: 700;
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

/* Complete banner (some words failed) */
.cq-complete-banner {
    background: linear-gradient(135deg, #1e3a5f, #172d4a);
    border: 1px solid #4b7ab5;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: center;
    color: #93c5fd;
    font-weight: 700;
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

.cq-win-icon {
    margin-right: 0.4em;
}

/* ===== Crossword grid ===== */
.cq-grid-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.cq-grid {
    border-collapse: collapse;
}

.cq-cell {
    width: 38px;
    height: 38px;
    min-width: 38px;
    text-align: center;
    vertical-align: middle;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0;
    user-select: none;
}

.cq-empty {
    background: transparent;
    border: none;
}

.cq-letter {
    background: #1f2937;
    border: 2px solid #374151;
    color: #d1d5db;
    border-radius: 3px;
}

.cq-cell-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 0.5rem;
    font-weight: 700;
    color: #9ca3af;
    line-height: 1;
    pointer-events: none;
}

.cq-letter {
    position: relative;
}

.cq-cell-clickable {
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.cq-cell-clickable:hover {
    background: #2d3748;
    border-color: #9ca3af;
}

.cq-cell-solved {
    background: #1a2e1a;
    border-color: #166534;
    color: #bbf7d0;
}

.cq-cell-failed {
    background: #2a1a1a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

.cq-cell-confirmed {
    background: #1a2535;
    border-color: #1d4ed8;
    color: #93c5fd;
}

/* ===== Word list below grid ===== */
.cq-word-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cq-entry {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    font-size: 0.9rem;
}

.cq-entry-active {
    background: #1f2937;
    border: 1px solid #374151;
    cursor: pointer;
    transition: background 0.15s;
}

.cq-entry-active:hover {
    background: #2d3748;
}

.cq-entry-solved {
    background: #1a2e1a;
    border: 1px solid #166534;
}

.cq-entry-failed {
    background: #2a1a1a;
    border: 1px solid #7f1d1d;
}

.cq-entry-num {
    color: #D4AF37;
    font-weight: 800;
    font-size: 0.85rem;
    min-width: 1.2rem;
    flex-shrink: 0;
}

.cq-entry-len {
    color: #9ca3af;
    min-width: 5rem;
    flex-shrink: 0;
}

.cq-entry-dir {
    color: #6b7280;
    font-size: 0.8rem;
    min-width: 3.5rem;
    flex-shrink: 0;
}

.cq-entry-blanks {
    color: #6b7280;
    letter-spacing: 0.15em;
    flex: 1;
}

.cq-entry-answer {
    font-weight: 700;
    letter-spacing: 0.08em;
    flex: 1;
    color: #d1d5db;
}

.cq-entry-failed .cq-entry-answer {
    color: #fca5a5;
}

.cq-entry-arrow {
    color: #6b7280;
    font-size: 1.2rem;
}

.cq-entry-check {
    color: #4ade80;
    font-size: 1.1rem;
}

.cq-entry-x {
    color: #f87171;
    font-size: 1.1rem;
}

/* ===== Word challenge page ===== */
.cq-word-header {
    position: relative;
    text-align: center;
    margin-bottom: 1.5rem;
}

.cq-word-meta {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    align-items: center;
}

.cq-back {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    text-decoration: none;
    font-size: 0.9rem;
    /* border: 1px solid var(--cq-green); */
    border: 1px solid black;
    border-radius: 5px;
    padding: 8px;
    padding-top: 6px;
    /* box-shadow: 0 0 3px var(--cq-green); */
    box-shadow: 0 0 3px white;
}

.cq-back:hover {
    color: #e5e7eb;
}

.cq-word-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #e5e7eb;
    margin: 0;
}

.cq-guesses-left {
    font-size: 0.85rem;
    color: #9ca3af;
}

/* ===== Board (guess rows) ===== */
.cq-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 1.25rem;
}

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

/* ===== Tiles ===== */
.cq-tile {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 800;
    border-radius: 4px;
    text-transform: uppercase;
    transition: border-color 0.1s;
    user-select: none;
}

.cq-empty-tile {
    background: #1f2937;
    border: 2px solid #374151;
    color: #e5e7eb;
}

.cq-tile-filled {
    border-color: #9ca3af !important;
}

@keyframes cq-cursor-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(229,231,235,0); }
    50%       { box-shadow: 0 0 0 2px rgba(229,231,235,0.55); }
}

.cq-tile-cursor {
    animation: cq-cursor-pulse 1.2s ease-in-out infinite;
}

.cq-htp-btn-pulse {
    animation: cq-cursor-pulse 1.2s ease-in-out 3;
}

.cq-revealed {
    background: #1e3a5f;
    background: linear-gradient(135deg, #111827, #1e3a5f);
    border: 2px solid #3b82f6;
    color: #93c5fd;
}

/* Revealed tiles in the active input row are editable — make them look interactive */
#current-row .cq-tile.cq-revealed {
    border-color: #60a5fa;
    border-style: dashed;
    box-shadow: 0 0 6px rgba(96, 165, 250, 0.35);
}

.cq-gold {
    /* background: linear-gradient(135deg, rgb(194,147,22), rgb(254,247,180));
    border: 2px solid #D4AF37; */
    background: linear-gradient(135deg, #111827, rgba(133, 120, 11, 0.404));
    border: 1px solid #D4AF37;
    color: white;
}

.cq-silver {
    /* background: linear-gradient(135deg, #737477, white);
    border: 2px solid #d1d5db;
    color: #ffffff; */
    background: linear-gradient(135deg, #111827, rgba(160, 160, 157, 0.404));
    border: 1px solid #d1d5db;
    color: white;
}

.cq-dark {
    background: #1f2937;
    border: 2px solid #374151;
    color: #6b7280;
}

/* Light-on animation */
@keyframes cq-light-on {
    0%   { filter: brightness(0.2); }
    60%  { filter: brightness(1.6); }
    100% { filter: brightness(1); }
}

.cq-light-on {
    animation: cq-light-on 0.35s ease-out forwards;
}

/* ===== Error message ===== */
.cq-error {
    text-align: center;
    color: #fca5a5;
    background: #450a0a;
    border: 1px solid #7f1d1d;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
}

.cq-error.cq-error-visible {
    visibility: visible;
}

/* ===== On-screen keyboard ===== */
.cq-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    padding: 0.6rem;
    padding-bottom: 0.6rem;
    background: #0f172a;
    border: 1px solid var(--cq-green);
    border-radius: 10px;
    box-shadow: 0 0 5px var(--cq-green);
    /* Fixed to bottom of viewport */
    position: fixed;
    bottom: max(env(safe-area-inset-bottom), 12px);
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 480px;
}

/* Push page content above the pinned keyboard */
.cq-page:has(.cq-keyboard) {
    padding-bottom: 220px;
}

.cq-kb-row {
    display: flex;
    gap: 5px;
    width: 100%;
    justify-content: center;
}

.cq-kb-key {
    /* All letter keys: uniform width so row 1 (10 keys, 9 gaps) fills 100% of the row */
    flex: none;
    width: calc((100% - 9 * 5px) / 10);
    height: 54px;
    padding: 0;
    /* background: #374151; */
    background: #111827;
    color: #e5e7eb;
    border: none;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    transition: background 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cq-green);
    box-shadow: 0 0 3px var(--cq-green);
}

.cq-kb-key:hover {
    background: #4b5563;
}

.cq-kb-key:active {
    background: #6b7280;
}

.cq-kb-key:disabled {
    opacity: 0.4;
    cursor: default;
}

.cq-kb-action {
    width: calc((100% - 9 * 5px) / 10 * 1.5);
    font-size: 0.8rem;
}

#backspace-btn {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.452);
}

#backspace-btn svg {
    width: 1.3em;
    height: 1.3em;
    pointer-events: none;
}

.cq-kb-enter {
    background: #1e3a5f;
    color: #93c5fd;
    padding-right: 4px;
    border: none;
    box-shadow: none;
}

.cq-kb-enter:not(:disabled):hover {
    background: #1e40af;
}

.cq-kb-used-gray {
    background: #1f2937;
    color: #4b5563;
    border: none;
    box-shadow: none;
}

.cq-kb-used-silver {
    /* background: linear-gradient(135deg, #494a4d, white); */
    background: linear-gradient(135deg, #111827, rgba(160, 160, 157, 0.404));
    border: 1px solid #d1d5db;
    color: white;
    box-shadow: none;
    /* text-shadow: 0 0 2px rgba(255,255,255,0.5); */
    /* -webkit-text-stroke: 1px black; */
}

.cq-kb-used-gold {
    /* background: linear-gradient(135deg, rgb(194,147,22), rgb(254,247,180)); */
    background: linear-gradient(135deg, #111827, rgba(133, 120, 11, 0.404));
    border: 1px solid #D4AF37;
    color: white;
    box-shadow: none;
}

/* Scale tiles to fill 90% of page width, square */
:root {
    --cq-tile-gap: 5px;
    --cq-page-pad: 1rem;
    --cq-avail-w: min(calc(100vw - 2 * var(--cq-page-pad)), calc(480px - 2 * var(--cq-page-pad)));
}

.cq-board[data-word-len="5"] .cq-tile {
    --cq-tile-sz: calc((var(--cq-avail-w) * 0.9 - 4 * var(--cq-tile-gap)) / 5);
    width: var(--cq-tile-sz);
    height: var(--cq-tile-sz);
    font-size: calc(var(--cq-tile-sz) * 0.42);
}

.cq-board[data-word-len="6"] .cq-tile {
    --cq-tile-sz: calc((var(--cq-avail-w) * 0.9 - 5 * var(--cq-tile-gap)) / 6);
    width: var(--cq-tile-sz);
    height: var(--cq-tile-sz);
    font-size: calc(var(--cq-tile-sz) * 0.42);
}

.cq-board[data-word-len="7"] .cq-tile {
    --cq-tile-sz: calc((var(--cq-avail-w) * 0.9 - 6 * var(--cq-tile-gap)) / 7);
    width: var(--cq-tile-sz);
    height: var(--cq-tile-sz);
    font-size: calc(var(--cq-tile-sz) * 0.42);
}

/* ===== Tile speech bubble ===== */
.cq-speech-bubble {
    position: fixed;
    background: #1f2937;
    border: 1px solid #4b5563;
    border-radius: 8px;
    padding: 0.45rem 0.85rem;
    font-size: 0.82rem;
    color: #e5e7eb;
    z-index: 500;
    max-width: 210px;
    text-align: center;
    line-height: 1.4;
    pointer-events: none;
    display: none;
}

.cq-speech-bubble.cq-speech-visible {
    display: block;
}

/* Outer triangle (border colour) */
.cq-speech-bubble::before {
    content: '';
    position: absolute;
    left: var(--cq-tail-x, 50%);
    top: 100%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #4b5563;
}

/* Inner triangle (background fill) */
.cq-speech-bubble::after {
    content: '';
    position: absolute;
    left: var(--cq-tail-x, 50%);
    top: calc(100% - 1px);
    transform: translateX(-50%);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 7px solid #1f2937;
}

.cq-username-line {
    font-size: 0.78rem;
    color: #6b7280;
    margin: 0.1rem 0 0 0;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.cq-username-val {
    color: #D4AF37;
    font-weight: 600;
}

.cq-username-edit-btn {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0 0 0 0.3rem;
    line-height: 1;
    vertical-align: middle;
    /* padding-right: 10px; */
}

.cq-username-edit-btn:hover {
    color: #D4AF37;
}

.cq-join-lb-btn {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.cq-join-lb-btn:hover {
    color: #9ca3af;
}

.cq-lb-opt-out-btn {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.6rem 0 0 0;
    display: block;
    width: 100%;
    text-align: center;
    text-decoration: underline;
}

.cq-lb-opt-out-btn:hover {
    color: #9ca3af;
}

/* ===== Leaderboard open button ===== */
.cq-lb-open-btn {
    background: none;
    border: 1px solid black;
    border-radius: 5px;
    box-shadow: 0 0 3px gray;
    padding: 6px;
    color: #D4AF37;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    /* padding: 0; */
    margin-left: auto;
}

.cq-lb-open-btn:hover {
    color: #f0cc55;
}

/* ===== Leaderboard (inside modal) ===== */
.cq-lb-title {
    font-size: 1rem;
    font-weight: 700;
    color: #D4AF37;
    margin: 0 0 0.75rem 0;
    text-align: center;
}

.cq-lb-submit-row {
    display: flex;
    gap: 0.5rem;
}

.cq-lb-known-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.cq-lb-known-name {
    color: #D4AF37;
    font-weight: 600;
    font-size: 0.95rem;
}

.cq-lb-input {
    flex: 1;
    background: #1f2937;
    border: 1px solid #4b5563;
    border-radius: 6px;
    color: #e5e7eb;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    outline: none;
}

.cq-lb-input:focus {
    border-color: #D4AF37;
}

.cq-lb-btn {
    background: #D4AF37;
    color: #111827;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.cq-lb-btn:hover {
    background: #f0cc55;
}

.cq-lb-error {
    color: #fca5a5;
    font-size: 0.85rem;
    margin: 0.4rem 0 0 0;
}

.cq-lb-rank-msg {
    text-align: center;
    color: #D4AF37;
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
}

.cq-lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.cq-lb-th {
    color: #9ca3af;
    text-align: left;
    padding: 0.3rem 0.4rem;
    border-bottom: 1px solid #374151;
    font-weight: 600;
}

.cq-lb-td {
    color: #d1d5db;
    padding: 0.35rem 0.4rem;
    border-bottom: 1px solid #1f2937;
}

.cq-lb-th-name,
.cq-lb-td-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cq-lb-my-row .cq-lb-td {
    background: rgba(59,130,246,0.15);
    color: #93c5fd;
    font-weight: 600;
}

.cq-lb-td-rank {
    position: relative;
    width: 2rem;
    text-align: center;
}

.cq-lb-rank-medal {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    line-height: 1;
}

.cq-lb-rank-num {
    display: inline-block;
}

.cq-lb-gold-medal {
    color: #D4AF37;
}

.cq-lb-silver-medal {
    color: #9ca3af;
}

.cq-lb-bronze-medal {
    color: #cd7f32;
}

/* Small screen adjustments */
@media (max-width: 380px) {
    .cq-cell {
        width: 32px;
        height: 32px;
        min-width: 32px;
        font-size: 0.85rem;
    }

    .cq-kb-key {
        height: 46px;
        font-size: 0.8rem;
    }
}
