.tp-root {
    --tp-color: #1CCD9D;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 1fr;
    width: 100%;
    height: 100%;
    max-height: 100%;
    box-sizing: border-box;
    gap: 12px;
    padding: 16px 16px 0 16px;
    overflow: hidden;
}

/* ---------- Loading / error panels ---------- */

.tp-loading,
.tp-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
    text-align: center;
}

.tp-loading__title,
.tp-panel__title {
    font-family: var(--third-family);
    font-weight: 600;
    font-size: 18px;
    color: var(--text-dark-color);
    margin: 0;
}

/* ---------- Header (grid row 1) ---------- */

.tp-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    grid-row: 1;
}

.tp-header__topline {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
}

.tp-icon-button {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: none;
    background: var(--gray-200);
    color: var(--text-gray-dark-color);
    cursor: pointer;
    padding: 0;
    transition: background-color .15s ease;
}

    .tp-icon-button:hover { background: var(--gray-300); }

.tp-icon-button--placeholder {
    background: transparent;
    cursor: default;
    pointer-events: none;
}

.tp-header__stats {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex-wrap: wrap;
    align-items: baseline;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    color: var(--gray-600);
    min-width: 0;
}

.tp-header__counter {
    color: var(--text-dark-color);
    font-weight: 600;
}

.tp-header__timer {
    margin-left: auto;
    color: var(--text-dark-color);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tp-progress-segments {
    display: flex;
    flex-direction: row;
    gap: 4px;
    width: 100%;
}

.tp-progress-seg {
    flex: 1 1 0;
    height: 6px;
    border-radius: 999px;
    background: var(--gray-200);
    transition: background-color .15s ease;
}

.tp-progress-seg--current {
    background: color-mix(in srgb, var(--tp-color) 45%, var(--gray-200));
}

.tp-progress-seg--ok { background: #1CCD9D; }
.tp-progress-seg--wrong { background: #FF6951; }
.tp-progress-seg--time { background: #FCAF2A; }

/* ---------- Middle scroll row ---------- */

.tp-question-card {
    grid-row: 2;
    background: #FFFFFF;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 2px 12px rgba(22, 30, 57, .06);
    position: relative; /* anchor for the absolutely-positioned .tp-points-badge floating overlay */
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    min-height: 0;
}

    .tp-question-card::-webkit-scrollbar { width: 6px; }
    .tp-question-card::-webkit-scrollbar-thumb {
        background-color: rgba(135, 148, 168, .35);
        border-radius: 6px;
    }

.tp-question__image-wrap {
    width: 100%;
    max-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    border-radius: 14px;
    overflow: hidden;
}

.tp-question__image {
    max-width: 100%;
    max-height: 240px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.tp-question__title {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 20px;
    line-height: 1.35;
    color: var(--text-dark-color);
    margin: 0;
    word-break: break-word;
}

.tp-question__timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    align-self: flex-start;
    border-radius: 10px;
    background: var(--gray-200);
    color: var(--text-gray-dark-color);
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.tp-answers {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tp-answer--blue   { --ans-bg: #4B9FFF; }
.tp-answer--green  { --ans-bg: #1CCD9D; }
.tp-answer--yellow { --ans-bg: #FCAF2A; }
.tp-answer--red    { --ans-bg: #FF6951; }

.sortable-chosen { cursor: grabbing; }

.sortable-ghost {
    opacity: .35;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, .25) 0,
        rgba(255, 255, 255, .25) 8px,
        transparent 8px,
        transparent 16px
    );
    outline: 2px dashed rgba(22, 30, 57, .3);
    outline-offset: -2px;
    border-radius: inherit;
}

    .sortable-ghost > * { visibility: hidden; }

.sortable-drag {
    box-shadow: 0 18px 36px -8px rgba(22, 30, 57, .35) !important;
    cursor: grabbing !important;
    opacity: 1 !important;
    filter: brightness(1.04);
    transition: none !important;
    pointer-events: none !important;
}

.qc-seq-ghost { visibility: hidden; }

.tp-sortable-dragging {
    box-shadow: 0 14px 28px rgba(22, 30, 57, .25);
    z-index: 10;
    position: relative;
    filter: brightness(1.05);
    transition: none !important;
    will-change: transform;
}

.tp-sortable-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    touch-action: none;
}

    .tp-sortable-container * {
        touch-action: none;

        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }

    .tp-sortable-container > *:not(.tp-sortable-dragging) {
        transition: transform .18s ease;
    }

/* ---------- Choice answer tile ---------- */

.tp-answer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    color: #FFFFFF;
    background: var(--ans-bg, var(--gray-200));
    box-shadow: 0 2px 8px rgba(22, 30, 57, .08);
    text-align: left;
    width: 100%;
    transition: transform .1s ease, box-shadow .15s ease, filter .15s ease;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 15px;
    box-sizing: border-box;
}

    .tp-answer:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.05); }
    .tp-answer:active:not(:disabled) { transform: scale(.99); }
    .tp-answer:disabled { cursor: default; opacity: .9; }

.tp-answer__text {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
    color: #FFFFFF;
}

.tp-answer__marker {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .2);
    border: 2px solid rgba(255, 255, 255, .7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
}

.tp-answer--checked .tp-answer__marker {
    background: #FFFFFF;
    color: var(--ans-bg);
    border-color: #FFFFFF;
}

.tp-answer--checked {
    box-shadow: 0 4px 16px rgba(22, 30, 57, .18);
    outline: 3px solid rgba(255, 255, 255, .85);
    outline-offset: -3px;
}

/* ---------- Reorder tile ---------- */

.tp-answer--orderable {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    cursor: grab;
    touch-action: none;
}

    .tp-answer--orderable:active { cursor: grabbing; }

.tp-answer__drag-handle {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, .7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
}

.tp-answer__order {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    color: #FFFFFF;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 13px;
}

/* ---------- Text answer ---------- */

.tp-answer-input {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    border-radius: 12px;
    border: 2px solid var(--gray-300);
    background: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 15px;
    color: var(--text-dark-color);
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s ease, box-shadow .15s ease;
}

    .tp-answer-input:focus {
        border-color: var(--tp-color);
        box-shadow: 0 0 0 3px rgba(28, 205, 157, .15);
    }

/* ---------- Match (2-column drag layout) ---------- */

.tp-match-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tp-match-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    touch-action: none;
}

.tp-match-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--ans-bg, var(--gray-200));
    color: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(22, 30, 57, .08);
    user-select: none;
}

.tp-match-cell--left {
    /* Left column is the fixed target — not draggable. */
    cursor: default;
}

.tp-match-cell--right {
    cursor: grab;
    touch-action: none;
}

    .tp-match-cell--right:active { cursor: grabbing; }

.tp-match-cell__drag {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, .7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
}

.tp-match-cell__text { flex: 1 1 auto; min-width: 0; }

/* ---------- Sequence blocks ---------- */

.tp-seq-answer {
    min-height: 72px;
    padding: 14px;
    border-radius: 16px;
    background: #FFFFFF;
    border: 2px dashed var(--gray-300);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    touch-action: none;
}

.tp-seq-answer__placeholder {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    color: var(--gray-500);
    margin: 0 auto;
}

.tp-seq-pool {
    padding: 14px;
    border-radius: 16px;
    background: var(--gray-200);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tp-seq-pool__label {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-600);
    margin: 0;
}

.tp-seq-pool__items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
    /* The pool is also a drop target when the user returns blocks. */
    touch-action: none;
}

.tp-seq-block {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 12px;
    border: none;
    background: var(--ans-bg, var(--tp-color));
    color: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 2px 6px rgba(22, 30, 57, .12);
    transition: transform .1s ease, filter .15s ease;
    /* See .tp-answer--orderable for why this is required on draggables. */
    touch-action: none;
}

    .tp-seq-block:hover:not(:disabled) { filter: brightness(1.08); }
    .tp-seq-block:active:not(:disabled) { cursor: grabbing; transform: scale(.98); }

.tp-seq-block--answer {
    background: var(--ans-bg, var(--tp-color));
}

.tp-seq-block--pool {
    background: var(--ans-bg, var(--tp-color));
}

.tp-seq-block__order {
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .25);
    font-size: 12px;
    font-weight: 700;
}

.tp-seq-block__text { word-break: break-word; }

.tp-answers__unsupported {
    padding: 16px;
    background: var(--gray-200);
    color: var(--gray-600);
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 14px;
    margin: 0;
}

/* ---------- Question result overlay ---------- */

.tp-question-result {
    margin-top: 4px;
    padding: 14px 16px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #FFFFFF;
}

.tp-question-result--ok { background: #1CCD9D; }
.tp-question-result--wrong { background: #FF6951; }

.tp-question-result__title {
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 16px;
    margin: 0;
}

.tp-question-result__sub {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    margin: 0;
    opacity: .95;
}

/* ---------- "+N points" floating badge ----------
   Inserted into the DOM with a per-trigger @key so the CSS animation re-runs each
   time the user answers correctly. Pointer-events disabled so it never blocks the
   submit button. */

.tp-points-badge {
    position: absolute;
    left: 50%;
    bottom: 24%;
    transform: translateX(-50%) translateY(0) scale(0.6);
    background: rgba(255, 255, 255, 0.94);
    color: #1CCD9D;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 24px;
    padding: 6px 14px;
    border-radius: 16px;
    box-shadow: 0 8px 18px rgba(28, 205, 157, 0.18);
    pointer-events: none;
    opacity: 0;
    animation: tp-points-badge 720ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    z-index: 2;
}

@keyframes tp-points-badge {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(0) scale(0.6);
    }
    25% {
        opacity: 1;
        transform: translateX(-50%) translateY(-6px) scale(1.1);
    }
    35% {
        transform: translateX(-50%) translateY(-6px) scale(1.0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-42px) scale(1.0);
    }
}

/* ---------- Footer row (grid row 3) ---------- */

.tp-sticky-cta {
    grid-row: 3;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)) 0;
    display: flex;
    justify-content: center;
    background: transparent;
}

.tp-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    min-height: 48px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 15px;
    transition: filter .15s ease, background-color .15s ease, transform .1s ease;
}

    .tp-button:hover:not(:disabled) { filter: brightness(1.05); }
    .tp-button:active:not(:disabled) { transform: scale(.98); }
    .tp-button:disabled { cursor: default; opacity: .45; }

.tp-button--primary {
    background: var(--tp-color, #1CCD9D);
    color: #FFFFFF;
}

    .tp-button--primary:disabled {
        background: var(--tp-color, #1CCD9D);
        opacity: .45;
    }

.tp-button--wide { width: 100%; max-width: 420px; }

.tp-button--ghost {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--text-dark-color);
}

.tp-button--danger {
    background: var(--red-color);
    color: #FFFFFF;
}

.tp-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 30, 57, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-in-out;
    z-index: 50;
}

.tp-drawer-backdrop--open {
    opacity: 1;
    pointer-events: auto;
}

.tp-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    background: #FFFFFF;
    box-shadow: -8px 0 24px rgba(22, 30, 57, .15);
    transform: translateX(100%);
    transition: transform .25s ease-in-out;
    z-index: 60;
    display: flex;
    flex-direction: column;
}

.tp-drawer--open { transform: translateX(0); }

.tp-drawer__header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.tp-drawer__title {
    font-family: var(--third-family);
    font-weight: 600;
    font-size: 20px;
    color: var(--text-dark-color);
    margin: 0;
}

.tp-drawer__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
}

.tp-selector-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tp-selector-item {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-radius: 12px;
    background: var(--gray-200);
    color: var(--text-dark-color);
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    text-align: left;
    transition: background-color .15s ease;
    max-width: 365px;
}

    .tp-selector-item:hover:not(:disabled) { background: var(--gray-300); }
    .tp-selector-item:disabled { cursor: default; opacity: .75; }

.tp-selector-item--current {
    background: rgba(28, 205, 157, .15);
    outline: 2px solid var(--tp-color);
}

.tp-selector-item--ok { background: #DFFCEF; color: #0E8660; }
.tp-selector-item--wrong { background: #FCE0DB; color: #B7402E; }
.tp-selector-item--time { background: #FDEFCC; color: #9A6B10; }

.tp-selector-item__order {
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 8px;
    background: #FFFFFF;
    color: var(--text-dark-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.tp-selector-item__title {
    min-width: 0;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.tp-result-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 30, 57, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 70;
}

.tp-result,
.tp-confirm {
    background: #FFFFFF;
    border-radius: 20px;
    padding: 28px 24px;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
    box-shadow: 0 20px 48px rgba(22, 30, 57, .25);
    overflow-y: auto;

    box-sizing: border-box;
}

/* Score ring inside the end-of-pass modal — sits above the title and pulls
   the eye to the points/threshold visualisation before the textual result. */
.tp-result__ring {
    width: 140px;
    height: 140px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.tp-result__title,
.tp-confirm__title {
    font-family: var(--third-family);
    font-weight: 700;
    font-size: 20px;
    color: var(--text-dark-color);
    margin: 0;
}

.tp-result__reason,
.tp-confirm__sub {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    color: var(--gray-600);
    margin: 0;
}

.tp-result__stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.tp-result__stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    border-radius: 16px;
    color: #FFFFFF;
    text-align: left;
}

.tp-result__stat--ok { background: var(--blue-color); }
.tp-result__stat--wrong { background: var(--red-color); }

.tp-result__stat-value {
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 28px;
}

.tp-result__stat-label {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    opacity: .9;
}

.tp-result__cta {
    width: 100%;

    flex: 0 0 auto;
}

.tp-result__actions {
    width: 100%;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 0 0 auto;
}

.tp-confirm__actions {
    display: flex;
    flex-direction: row;
    gap: 12px;
    width: 100%;
    justify-content: stretch;
}

    .tp-confirm__actions .tp-button { flex: 1 1 0; }

.ti-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 30, 57, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-in-out;
    z-index: 50;
}

.ti-drawer-backdrop--open { opacity: 1; pointer-events: auto; }

.ti-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    background: #FFFFFF;
    box-shadow: 8px 0 24px rgba(22, 30, 57, .15);
    transform: translateX(-100%);
    transition: transform .25s ease-in-out;
    z-index: 60;
    display: flex;
    flex-direction: column;
}

.ti-drawer--open { transform: translateX(0); }

.ti-drawer__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.ti-drawer__title {
    font-family: var(--third-family);
    font-weight: 600;
    font-size: 20px;
    color: var(--text-dark-color);
    margin: 0;
}

.ti-drawer__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
}

.ti-questions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ti-question-item {
    background: var(--gray-200);
    border-radius: 16px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ti-question-item__head {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ti-question-item__order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 24px;
    padding: 0 8px;
    border-radius: 8px;
    background: var(--green-color);
    color: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 13px;
}

.ti-question-item__time {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--gray-500);
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.ti-question-item__title {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    color: var(--text-dark-color);
    margin: 0;
    word-break: break-word;
}

/* ============================================================
   Tablet and up
   ============================================================ */

@media (min-width: 768px) {

    .tp-root {
        padding: 20px 24px 0 24px;
        max-width: 900px;
        margin: 0 auto;
    }

    .tp-question-card {
        padding: 28px;
    }

    .tp-question__title {
        font-size: 22px;
    }

    .tp-drawer {
        width: 420px;
        max-width: 90vw;
        border-radius: 20px 0 0 20px;
    }
}
