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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 24px 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}

.btn:disabled {
    cursor: not-allowed;
}

.btn-submit {
    background: #22c55e;
    color: #0f1117;
}

.btn-submit:hover {
    background: #4ade80;
}

.btn-submit:disabled {
    background: #1a3a2a;
    color: #4b7a5a;
}

.btn-hint {
    background: #a78bfa;
    color: #0f1117;
}

.btn-hint:hover {
    background: #c4b5fd;
}

.btn-hint:disabled {
    background: #2d2640;
    color: #5b4a7a;
}

.btn-solve {
    background: #f0b860;
    color: #0f1117;
}

.btn-solve:hover {
    background: #f5cc80;
}

.btn-primary {
    background: #7cacf8;
    color: #0f1117;
}

.btn-primary:hover {
    background: #9dbffa;
}

/* Loading / error */
.loading-msg {
    color: #9ca3af;
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

.error-msg {
    color: #f87171;
    font-size: 14px;
    margin-top: 8px;
    text-align: center;
}

/* Phone frame */
.phone-frame {
    max-width: 420px;
    width: 100%;
    position: relative;
}

/* Cancel button (used in modals and reveal actions) */
.btn-cancel {
    background: #2a3547;
    color: #e0e0e0;
}

.btn-cancel:hover {
    background: #344158;
}

/* ---- List screen ---- */
.list-screen {
    padding: 0 0 24px;
}

.list-header {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.list-header-spacer {
    display: block;
    width: 40px;
    height: 40px;
}

.puzzle-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.puzzle-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    background: #1a1d27;
    border: 1px solid #2a2d37;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    color: inherit;
}

.puzzle-card:hover {
    border-color: #3a4a5f;
    background: #1e2130;
}

.puzzle-card:active {
    background: #222738;
}

.puzzle-card-row1 {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.puzzle-card-date {
    font-size: 15px;
    font-weight: 600;
    color: #e0e0e0;
}

.puzzle-card-difficulty {
    font-size: 12px;
    color: #6b7280;
}

.puzzle-card-row2 {
    font-size: 13px;
    color: #9ca3af;
}

.puzzle-card-status {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 12px;
    flex-shrink: 0;
}

.puzzle-card-status.solved {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.puzzle-card-status.failed {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.puzzle-card-status.new {
    background: rgba(124, 172, 248, 0.15);
    color: #7cacf8;
}

.btn-play-again {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    background: #2a3547;
    border: 1px solid #3a4a5f;
    color: #7cacf8;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-play-again:hover {
    background: #344158;
    border-color: #7cacf8;
}

/* ---- Header ---- */
.play-header {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.header-title {
    font-size: 28px;
    text-align: center;
    color: #e0e0e0;
    margin: 0;
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-title-img {
    height: 40px;
    width: auto;
    display: block;
}

.header-back,
.header-help {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    border-radius: 8px;
    padding: 0;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
}

.header-back:hover,
.header-help:hover {
    color: #e0e0e0;
    background: #1a1d27;
}

.header-help {
    justify-self: end;
}

.btn-back {
    background: none;
    border: 1px solid #2a2d37;
    border-radius: 8px;
    color: #9ca3af;
    font-size: 18px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-back:hover {
    border-color: #7cacf8;
    color: #e0e0e0;
}

.play-header-right {
    flex: 1;
    min-width: 0;
}

.play-date {
    font-size: 15px;
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

.play-info {
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 13px;
    color: #9ca3af;
}

.play-info .attempts {
    font-weight: 600;
}

/* Grid */
.grid-area {
    position: relative;
    width: 100%;
    margin: 0 auto 16px auto;
    min-height: 100px;
}

.grid-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.tri-line {
    stroke: #3a4a5f;
    stroke-width: 1.5;
    fill: none;
}

.tri-hover-zone {
    cursor: pointer;
    transition: fill-opacity 0.15s;
}

.tri-hover-zone:hover {
    fill-opacity: 0.18;
}

/* Slots */
.node-slot {
    position: absolute;
    height: 56px;
    background: #1e2130;
    border: 2px dashed #4a5068;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    z-index: 2;
}

.node-slot:hover {
    border-color: #7cacf8;
}

.node-slot.filled {
    border-style: solid;
    border-color: #5a6a8f;
    background: #262a3a;
}

.node-slot.selected-target {
    border-color: #7cacf8;
    border-style: solid;
    box-shadow: 0 0 8px rgba(124, 172, 248, 0.3);
}

.node-slot.hint {
    background: #1a1d2e;
    border: 2px solid #4a5068;
    cursor: default;
}

.node-slot.hint .hint-label {
    position: absolute;
    top: -8px;
    right: 6px;
    font-size: 9px;
    color: #8890a4;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #1a1d27;
    padding: 0 4px;
}

.node-slot.correct {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.12);
}

.node-slot.incorrect-flash {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    animation: flash-red 3s;
}

.node-slot.trio-highlight {
    box-shadow: 0 0 0 2px var(--tri-color, #7cacf8);
}

@keyframes flash-red {
    0% {
        background: rgba(239, 68, 68, 0.3);
    }

    70% {
        background: rgba(239, 68, 68, 0.15);
    }

    100% {
        background: rgba(239, 68, 68, 0);
    }
}

/* How-to-play content (shown inside help modal) */
.solve-modal .info-lead {
    font-size: 17px;
    font-weight: 600;
    color: #e0e0e0;
    line-height: 1.45;
    margin: 0 0 18px 0;
    text-align: center;
}

.solve-modal .info-subhead {
    margin: 0 0 10px 0;
    font-size: 15px;
    font-weight: 600;
    color: #e0e0e0;
    text-align: center;
    letter-spacing: 0.02em;
}

.solve-modal .info-tips {
    list-style: none;
    padding: 0;
    margin: 0 0 22px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: center;
}

.solve-modal .info-tips li {
    font-size: 16px;
    color: #cbd5e1;
    line-height: 1.45;
}

/* Help modal sizing — larger than the shared solve-modal defaults */
#help-modal .solve-modal {
    max-width: 380px;
    padding: 24px 22px;
}

#help-modal .solve-modal h3 {
    font-size: 20px;
    margin-bottom: 14px;
}

.node-slot.trio-highlight {
    box-shadow: 0 0 0 2px var(--tri-color, #7cacf8);
}

/* Word bank */
.word-bank-section {
    margin-top: 8px;
}

.word-bank-section h3 {
    font-size: 14px;
    color: #9ca3af;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.word-bank {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    min-height: 44px;
    padding: 10px;
    background: #13151d;
    border: 1px solid #2a2d37;
    border-radius: 8px;
    margin: 0 auto;
}

.word-bank.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.word-bank.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.word-bank.cols-5 {
    grid-template-columns: repeat(5, 1fr);
}

.word-chip {
    padding: 12px 14px;
    background: #2a3547;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    text-align: center;
}

.word-chip:hover {
    background: #344158;
}

.word-chip.selected {
    border-color: #7cacf8;
    background: #2a3a5a;
}

.word-chip.placed {
    opacity: 0.3;
    pointer-events: none;
}

.word-chip.dragging {
    opacity: 0.4;
}

.word-chip[draggable="true"] {
    cursor: grab;
}

.word-chip[draggable="true"]:active {
    cursor: grabbing;
}

.node-slot.drag-over {
    border-color: #7cacf8;
    border-style: solid;
    background: #2a3a5a;
    box-shadow: 0 0 12px rgba(124, 172, 248, 0.5);
}

.word-chip.correct-locked {
    background: rgba(34, 197, 94, 0.15);
    border-color: #22c55e;
    color: #22c55e;
    cursor: default;
}

.word-chip,
.node-slot,
.trio-words {
    text-transform: uppercase;
}

/* Actions */
.actions-bar {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* Icon-only action buttons (Hint / Submit / Solve Now) */
.actions-bar .btn {
    width: 56px;
    height: 56px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    position: relative;
}

.btn .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn .btn-icon svg {
    display: block;
}

.btn .icon-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #0f1117;
    color: #e0e0e0;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid currentColor;
    line-height: 1;
    pointer-events: none;
}

/* Modal backdrops — fixed to the viewport, lightly dimmed so the board
   stays visible, and anchored ~25% from the top. */
.solve-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 20, 0.25);
    backdrop-filter: none;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 25vh;
    z-index: 10;
}

.solve-modal {
    background: #1a1d27;
    border: 1px solid #2a2d37;
    border-radius: 10px;
    padding: 20px;
    width: calc(100% - 40px);
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.solve-modal h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #e0e0e0;
}

.solve-modal p {
    margin: 0 0 18px 0;
    font-size: 13px;
    color: #9ca3af;
    line-height: 1.4;
}

.solve-modal .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.solve-modal .modal-actions .btn {
    flex: 1;
    width: auto;
    height: auto;
    padding: 10px 16px;
    border-radius: 6px;
}

/* Correct-count overlay shown after an incorrect submit */
.correct-count-overlay {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(15, 17, 23, 0.92);
    border: 1px solid #3a4a5f;
    border-radius: 10px;
    padding: 14px 22px;
    color: #e0e0e0;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
}

.correct-count-overlay.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.correct-count-overlay .count-big {
    font-size: 22px;
    font-weight: 700;
    color: #f0b860;
    display: block;
    margin-bottom: 2px;
}

.correct-count-overlay .count-sub {
    font-size: 12px;
    color: #9ca3af;
}

/* Reveal */
.reveal-section {
    margin-top: 20px;
}

.reveal-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    text-align: center;
}

.reveal-section .reveal-result {
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
}

.reveal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
}

.reveal-actions .btn {
    flex: 1;
    max-width: 160px;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
}

.trio-card {
    background: #1a1d27;
    border: 1px solid #2a2d37;
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 10px;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.trio-card.trio-card-highlight {
    background: #1e2230;
    border-color: var(--tri-card-color, #4a5068);
}

.trio-card .trio-words {
    font-size: 14px;
    color: #e0e0e0;
    display: block;
}

.trio-card .trio-tag {
    font-size: 13px;
    color: #7cacf8;
    font-weight: 500;
    display: block;
    margin-top: 4px;
}

/* Install prompt banner — pinned to the bottom of the phone frame.
   Slides up into view so it catches the eye after the reveal screen settles. */
.install-banner {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #1e293b 0%, #2a3a57 100%);
    border: 1px solid #f0b860;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(240, 184, 96, 0.15);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 50;
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 260ms ease-out, transform 260ms ease-out;
}

.install-banner.visible {
    opacity: 1;
    transform: translateY(0);
}

.install-banner-text {
    font-size: 14px;
    color: #f1f5f9;
    line-height: 1.35;
    font-weight: 500;
}

.install-banner-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.install-banner-actions .btn {
    padding: 8px 14px;
    font-size: 13px;
}

/* Tip jar — fixed to the viewport so it survives list scroll. On wide screens
   it hugs the right edge of the 420px phone frame; on narrow screens it falls
   back to the viewport right edge (the frame fills the width anyway). */
.tip-jar-btn {
    position: fixed;
    bottom: 16px;
    right: max(16px, calc(50vw - 210px + 8px));
    height: 36px;
    padding: 0 14px 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #1a1d27;
    border: 1px solid #2a2d37;
    border-radius: 18px;
    color: #f0b860;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 40;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.tip-jar-btn .tip-jar-label {
    line-height: 1;
    letter-spacing: 0.01em;
}

.tip-jar-btn .tip-jar-icon {
    display: block;
    flex-shrink: 0;
}

.tip-jar-btn:hover {
    background: #222738;
    border-color: #f0b860;
    transform: translateY(-1px);
}

.tip-jar-btn:active {
    transform: translateY(0);
}

/* Hide the tip jar while the install banner is visible so they don't stack. */
.install-banner-open .tip-jar-btn {
    display: none;
}