/* =====================================================================
 * The Revenue Puzzle — daily path-drawing game for hoteliers
 * ---------------------------------------------------------------------
 * Two surfaces are styled here:
 *   1. .rpg-ai-puzzle-invite      — the once-per-day promo popup that
 *                                   floats above the FAB inviting visitors
 *                                   to play.
 *   2. .rpg-ai-puzzle-widget      — the in-chat game widget shown inside
 *                                   the existing chat panel when the
 *                                   player opens the puzzle on the
 *                                   revenue-intelligence landing page.
 * ===================================================================== */

/* ── Invite popup ──────────────────────────────────────────────────── */

/* Reset everything inside the popup so the host theme can't bleed in
   borders, outlines, focus rings, underlines, etc. Themes commonly apply
   global `button { border: 1px solid; }` rules or accessibility outlines
   that show up as red boxes around every nested element. */
.rpg-ai-puzzle-invite,
.rpg-ai-puzzle-invite *,
.rpg-ai-puzzle-invite *::before,
.rpg-ai-puzzle-invite *::after {
    box-sizing: border-box !important;
    border: 0 !important;
    outline: 0 !important;
    text-decoration: none !important;
    text-shadow: none !important;
    background-image: none !important;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}

.rpg-ai-puzzle-invite {
    position: fixed !important;
    right: 20px !important;
    bottom: 90px !important;
    width: 320px !important;
    max-width: calc(100% - 40px) !important;
    background: linear-gradient(135deg, #5B48EE 0%, #7A6BFF 100%) !important;
    color: #ffffff !important;
    border-radius: 16px !important;
    box-shadow: 0 16px 36px rgba(91, 72, 238, 0.35) !important;
    padding: 16px 16px 14px !important;
    z-index: 2147483646 !important;
    transform: translateY(10px);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
    pointer-events: none;
}
.rpg-ai-puzzle-invite.is-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.rpg-ai-puzzle-invite__close {
    position: absolute !important;
    top: 6px !important;
    right: 8px !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.18) !important;
    color: #ffffff !important;
    cursor: pointer !important;
    font-size: 18px !important;
    line-height: 1 !important;
    padding: 0 !important;
    margin: 0 !important;
    text-align: center !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    /* Defensive: some themes ship `button { pointer-events: none; }` for
       "disabled" looks; force the close button to always be clickable, and
       give it a higher stacking context than the popup content below. */
    pointer-events: auto !important;
    z-index: 2 !important;
}
.rpg-ai-puzzle-invite__close:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}
.rpg-ai-puzzle-invite__eyebrow {
    font-size: 11px !important;
    font-weight: 700 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    opacity: 0.85 !important;
    margin: 0 0 6px 0 !important;
    padding: 0 !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-invite__title {
    font-size: 17px !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
    margin: 0 28px 6px 0 !important;
    padding: 0 !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-invite__body {
    font-size: 12.5px !important;
    line-height: 1.45 !important;
    margin: 0 0 12px 0 !important;
    padding: 0 !important;
    opacity: 0.94 !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-invite__actions {
    display: flex !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}
.rpg-ai-puzzle-invite__btn {
    appearance: none !important;
    -webkit-appearance: none !important;
    border-radius: 999px !important;
    padding: 8px 14px !important;
    margin: 0 !important;
    font-size: 12.5px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    line-height: 1.2 !important;
    box-shadow: none !important;
}
.rpg-ai-puzzle-invite__btn--primary {
    background: #ffffff !important;
    color: #5B48EE !important;
}
.rpg-ai-puzzle-invite__btn--primary:hover {
    background: #f3f1ff !important;
}
.rpg-ai-puzzle-invite__btn--ghost {
    background: rgba(255, 255, 255, 0.18) !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-invite__btn--ghost:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}
.rpg-ai-puzzle-invite__never {
    appearance: none !important;
    -webkit-appearance: none !important;
    margin: 0 0 0 auto !important;
    background: transparent !important;
    color: rgba(255, 255, 255, 0.85) !important;
    font-size: 11px !important;
    cursor: pointer !important;
    padding: 4px 6px !important;
    text-decoration: underline !important;
    line-height: 1.2 !important;
    box-shadow: none !important;
}
.rpg-ai-puzzle-invite__never:hover {
    color: #ffffff !important;
}

/* ── Chat-panel adjustments while the puzzle is mounted ─────────────
 * The default chat panel is 320px / 480px max — too cramped for a 5x5
 * grid with controls and a leaderboard. The .rpg-ai-panel--puzzle
 * modifier is added by JS while the puzzle is mounted and reset on exit.
 */
#rpg-ai-chat-panel.rpg-ai-panel--puzzle {
    width: 360px;
    max-height: min(640px, 85vh);
    display: flex !important;
    flex-direction: column;
}
#rpg-ai-chat-panel.rpg-ai-panel--puzzle #rpg-ai-puzzle-widget {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}
@media (max-width: 480px) {
    #rpg-ai-chat-panel.rpg-ai-panel--puzzle {
        width: calc(100vw - 24px);
        max-height: min(78vh, 640px);
    }
}

/* ── Game widget (lives inside the existing chat panel) ────────────── */

/* Reset everything inside the widget so the host theme can't bleed in
   borders, outlines, weird backgrounds, or list bullets. */
.rpg-ai-puzzle-widget,
.rpg-ai-puzzle-widget *,
.rpg-ai-puzzle-widget *::before,
.rpg-ai-puzzle-widget *::after {
    box-sizing: border-box !important;
    outline: 0 !important;
    text-shadow: none !important;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}
.rpg-ai-puzzle-widget button {
    appearance: none !important;
    -webkit-appearance: none !important;
    border: 0 !important;
    box-shadow: none !important;
    text-decoration: none !important;
    margin: 0 !important;
    font-family: inherit !important;
}
.rpg-ai-puzzle-widget ul,
.rpg-ai-puzzle-widget li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}
.rpg-ai-puzzle-widget p {
    margin: 0 !important;
    padding: 0 !important;
}

.rpg-ai-puzzle-widget {
    background: #ffffff !important;
    color: #111827 !important;
}

.rpg-ai-puzzle-widget__top {
    padding: 12px 14px 8px;
    border-bottom: 1px solid #ececf3;
    background: #faf9ff;
}
.rpg-ai-puzzle-widget__row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.rpg-ai-puzzle-widget__title {
    font-size: 13px;
    font-weight: 700;
    color: #5B48EE;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.rpg-ai-puzzle-widget__date {
    font-size: 11px;
    color: #6b7280;
    margin-left: auto;
}
.rpg-ai-puzzle-widget__badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.rpg-ai-puzzle-widget__badge--easy   { background: #DDF6E5; color: #176B36; }
.rpg-ai-puzzle-widget__badge--medium { background: #FFF1D6; color: #8A5A00; }
.rpg-ai-puzzle-widget__badge--hard   { background: #FEE2E2; color: #B91C1C; }
.rpg-ai-puzzle-widget__flavour {
    font-size: 12.5px;
    color: #374151;
    margin: 6px 0 0;
    line-height: 1.4;
    font-style: italic;
}
.rpg-ai-puzzle-widget__stats {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 11px;
    color: #4b5563;
    flex-wrap: wrap;
}
.rpg-ai-puzzle-widget__stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.rpg-ai-puzzle-widget__stat-label {
    color: #6b7280;
}
.rpg-ai-puzzle-widget__stat-value {
    font-weight: 700;
    color: #111827;
}

/* The grid lives inside a stage so we can layer an SVG path overlay on top
   of the cells. The stage is squared via padding-bottom:100% so it stays
   responsive across the chat panel widths. */
.rpg-ai-puzzle-widget__stage-wrap {
    padding: 12px;
}

/* ── Calendar chrome above the grid ────────────────────────────────
 * Two small bits of skinning to make the grid read like a mini calendar:
 *   1. A coloured banner showing the month/year (purely cosmetic — the
 *      puzzle is not tied to a real month).
 *   2. A weekday header strip (Mon..Fri) aligned with the grid columns. */
.rpg-ai-puzzle-widget__cal-banner {
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ffffff;
    background: #5B48EE;
    padding: 6px 10px;
    border-radius: 8px 8px 0 0;
    border: 1px solid #5B48EE;
    border-bottom: 0;
}
.rpg-ai-puzzle-widget__weekdays {
    display: grid;
    gap: 0;
    background: #faf9ff;
    border: 1px solid #ececf3;
    border-bottom: 0;
    padding: 5px 0;
}
.rpg-ai-puzzle-widget__weekdays span {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7280;
    line-height: 1.2;
}
/* When the calendar chrome sits above the stage, square off the top of
   the stage so the borders flow cleanly into the grid. */
.rpg-ai-puzzle-widget__cal-banner + .rpg-ai-puzzle-widget__weekdays + .rpg-ai-puzzle-widget__stage {
    border-radius: 0 0 10px 10px;
}
.rpg-ai-puzzle-widget__stage {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    /* Outline drawn via box-shadow so it doesn't shift the interior
       coordinate system that walls + path overlay rely on. */
    border-radius: 10px;
    box-shadow: 0 0 0 2px #5B48EE inset;
    overflow: hidden;
}
.rpg-ai-puzzle-widget__grid {
    position: absolute;
    inset: 0;
    display: grid;
    gap: 0;
    background: #cfcfe1;
}
.rpg-ai-puzzle-cell {
    position: relative;
    background: #fff;
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #ececf3;
    border-bottom: 1px solid #ececf3;
}
.rpg-ai-puzzle-cell:hover {
    background: #f7f6ff;
}
.rpg-ai-puzzle-cell.is-on-path {
    background: #ece9ff;
}
.rpg-ai-puzzle-cell.is-on-path.is-tail {
    background: #d9d3ff;
}
.rpg-ai-puzzle-cell.is-error {
    animation: rpgPuzzleShake 0.28s ease;
}

/* Calendar date in the top-left corner of every cell (1..N counting
   row-major). Sized to read clearly without competing with the centred
   checkpoint badges. */
.rpg-ai-puzzle-cell__date {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 10px;
    line-height: 1;
    color: #94939f;
    font-weight: 600;
    pointer-events: none;
    z-index: 1;
}
.rpg-ai-puzzle-cell.is-on-path .rpg-ai-puzzle-cell__date {
    color: #5B48EE;
}

.rpg-ai-puzzle-cell__checkpoint {
    width: 60%;
    height: 60%;
    max-width: 38px;
    max-height: 38px;
    min-width: 22px;
    min-height: 22px;
    border-radius: 50%;
    background: #5B48EE;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
    pointer-events: none;
}
.rpg-ai-puzzle-cell.is-checkpoint-active .rpg-ai-puzzle-cell__checkpoint {
    background: #2BC479;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.16), 0 0 0 3px rgba(43, 196, 121, 0.18);
}

/* Walls — we render them as overlay divs absolutely positioned along the
   shared edge between two cells. CSS variables let JS compute placement
   relative to the stage size. */
.rpg-ai-puzzle-wall {
    position: absolute;
    background: #1f1d3b;
    border-radius: 2px;
    pointer-events: none;
    z-index: 2;
}
.rpg-ai-puzzle-wall--h {
    height: 4px;
    transform: translateY(-2px);
}
.rpg-ai-puzzle-wall--v {
    width: 4px;
    transform: translateX(-2px);
}

/* Path overlay — an SVG layered on top of the grid renders the polyline
   connecting visited cells (with rounded joints and a soft glow). */
.rpg-ai-puzzle-widget__overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}
.rpg-ai-puzzle-widget__overlay path {
    fill: none;
    stroke: #5B48EE;
    stroke-width: 10;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.55;
    filter: drop-shadow(0 2px 4px rgba(91, 72, 238, 0.25));
}

/* Control row beneath the grid */
.rpg-ai-puzzle-widget__controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px 14px;
    flex-wrap: wrap;
}
.rpg-ai-puzzle-widget__progress {
    flex: 1;
    min-width: 120px;
    font-size: 11px;
    color: #4b5563;
}
.rpg-ai-puzzle-widget__progress strong {
    color: #111827;
}
.rpg-ai-puzzle-widget__btn {
    border-radius: 999px !important;
    padding: 7px 12px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    line-height: 1.2 !important;
    transition: background 0.15s ease;
}
.rpg-ai-puzzle-widget__btn--ghost {
    background: #f3f2ff !important;
    color: #5B48EE !important;
}
.rpg-ai-puzzle-widget__btn--ghost:hover {
    background: #e5e2ff !important;
}
.rpg-ai-puzzle-widget__btn--primary {
    background: #5B48EE !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-widget__btn--primary:hover {
    background: #4a38d4 !important;
}
.rpg-ai-puzzle-widget__btn:disabled {
    opacity: 0.55 !important;
    cursor: not-allowed !important;
}

.rpg-ai-puzzle-widget__hint {
    padding: 0 14px 12px;
    font-size: 11px;
    color: #6b7280;
    line-height: 1.45;
}
.rpg-ai-puzzle-widget__hint code {
    background: #f3f2ff;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 11px;
}

/* Win panel */
.rpg-ai-puzzle-widget__win {
    border-top: 1px solid #ececf3;
    background: linear-gradient(180deg, #f6f5ff 0%, #ffffff 100%);
    padding: 14px;
}
.rpg-ai-puzzle-widget__win-title {
    font-size: 15px;
    font-weight: 800;
    color: #111827;
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.rpg-ai-puzzle-widget__win-sub {
    font-size: 12px;
    color: #4b5563;
    margin: 0 0 10px;
}
.rpg-ai-puzzle-widget__score-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 10px;
}
.rpg-ai-puzzle-widget__score-cell {
    background: #fff;
    border: 1px solid #ececf3;
    border-radius: 10px;
    padding: 8px;
    text-align: center;
}
.rpg-ai-puzzle-widget__score-cell-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 2px;
}
.rpg-ai-puzzle-widget__score-cell-value {
    font-size: 16px;
    font-weight: 800;
    color: #111827;
}
.rpg-ai-puzzle-widget__total {
    background: #5B48EE;
    color: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.rpg-ai-puzzle-widget__total-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.85;
}
.rpg-ai-puzzle-widget__total-value {
    font-size: 22px;
    font-weight: 800;
}
.rpg-ai-puzzle-widget__streak {
    font-size: 12px;
    color: #4b5563;
    margin-bottom: 10px;
}
.rpg-ai-puzzle-widget__streak strong {
    color: #d97706;
}
.rpg-ai-puzzle-widget__tip {
    background: #fff;
    border: 1px solid #ececf3;
    border-left: 3px solid #5B48EE;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12.5px;
    color: #374151;
    line-height: 1.5;
    margin-bottom: 10px;
}
.rpg-ai-puzzle-widget__tip-label {
    display: block;
    font-size: 10px;
    color: #5B48EE;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    margin-bottom: 4px;
}
.rpg-ai-puzzle-widget__win-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.rpg-ai-puzzle-widget__leaderboard {
    background: #fff;
    border: 1px solid #ececf3;
    border-radius: 10px;
    overflow: hidden;
}
.rpg-ai-puzzle-widget__leaderboard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #faf9ff;
    border-bottom: 1px solid #ececf3;
}
.rpg-ai-puzzle-widget__leaderboard-title {
    font-size: 12px;
    font-weight: 700;
    color: #111827;
}
.rpg-ai-puzzle-widget__lb-tabs {
    display: inline-flex;
    background: #ececf3;
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}
.rpg-ai-puzzle-widget__lb-tab {
    background: transparent !important;
    color: #4b5563 !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    padding: 3px 10px !important;
    border-radius: 999px !important;
    cursor: pointer !important;
    line-height: 1.2 !important;
}
.rpg-ai-puzzle-widget__lb-tab.is-active {
    background: #5B48EE !important;
    color: #ffffff !important;
}
.rpg-ai-puzzle-widget__lb-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 180px;
    overflow-y: auto;
}
.rpg-ai-puzzle-widget__lb-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    font-size: 12px;
}
.rpg-ai-puzzle-widget__lb-row.is-me {
    background: #f3f2ff;
    font-weight: 700;
}
.rpg-ai-puzzle-widget__lb-rank {
    width: 22px;
    color: #6b7280;
    font-weight: 700;
}
.rpg-ai-puzzle-widget__lb-name {
    flex: 1;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rpg-ai-puzzle-widget__lb-score {
    color: #111827;
    font-weight: 700;
}
.rpg-ai-puzzle-widget__lb-empty {
    padding: 10px 12px;
    font-size: 12px;
    color: #6b7280;
    text-align: center;
}
.rpg-ai-puzzle-widget__user-rank {
    text-align: center;
    padding: 6px 12px;
    font-size: 11px;
    color: #4b5563;
    border-top: 1px solid #ececf3;
    background: #faf9ff;
}

.rpg-ai-puzzle-widget__loading,
.rpg-ai-puzzle-widget__error {
    padding: 28px 14px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}
.rpg-ai-puzzle-widget__error button {
    margin-top: 10px;
}

@keyframes rpgPuzzleShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-3px); }
    50%      { transform: translateX(3px); }
    75%      { transform: translateX(-2px); }
}

/* Smaller screens — keep things readable when the chat panel narrows. */
@media (max-width: 380px) {
    .rpg-ai-puzzle-widget__title { font-size: 12px; }
    .rpg-ai-puzzle-widget__date  { font-size: 10px; }
    .rpg-ai-puzzle-widget__total-value { font-size: 19px; }
    .rpg-ai-puzzle-widget__score-cell-value { font-size: 14px; }
    .rpg-ai-puzzle-widget__cal-banner    { font-size: 11px; padding: 5px 8px; }
    .rpg-ai-puzzle-widget__weekdays span { font-size: 9px; letter-spacing: 0.04em; }
    .rpg-ai-puzzle-cell__date            { font-size: 9px; top: 3px; left: 4px; }
}
