/*
 * Coding Ireland proprietary interactive activity
 * Copyright (c) 2017-2026 Coding Ireland. All rights reserved.
 *
 * Part of the Coding Ireland online learning platform. Licensed for use only
 * as delivered on the platform. Copying, redistributing, or adapting this
 * file, in whole or in part, for use in any other product or service is not
 * permitted. Ref: CI-maths-shape-measurer
 */
/*
 * shape-measurer — 2D/3D/Pythagoras measuring widget with a grid canvas,
 * live readouts, and mode-tab switching.
 */

.maths-activity .sm-scenario-chip {
    display: inline-block;
    margin-top: 0.4rem;
    padding: 0.3rem 0.75rem;
    background: var(--maths-surface-alt);
    color: var(--maths-primary-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
}

/* Mode tabs */
.maths-activity .sm-mode-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.9rem;
    border-bottom: 2px solid var(--maths-border);
}

.maths-activity .sm-mode-tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0.6rem 1.1rem 0.65rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--maths-ink-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    margin-bottom: -2px;
}

/* The `display: flex` above outranks the UA `[hidden]` rule, so a tab (or shape
 * button) that JS marks hidden — allowedModes / allowedShapeTypes — would still
 * show without this guard. */
.maths-activity .sm-mode-tab[hidden],
.maths-activity .sm-shape-btn[hidden] { display: none; }

.maths-activity .sm-mode-tab i {
    font-size: 1rem;
    color: var(--maths-primary);
}

.maths-activity .sm-mode-tab .sm-mode-hint {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--maths-ink-muted);
    text-transform: none;
}

.maths-activity .sm-mode-tab[aria-selected="true"] {
    color: var(--maths-primary);
    border-bottom-color: var(--maths-primary);
    background: var(--maths-surface);
}

.maths-activity .sm-mode-tab:hover:not([aria-selected="true"]) {
    background: var(--maths-surface-alt);
}

.maths-activity .sm-mode-tab:focus-visible {
    outline: 3px solid var(--maths-focus-ring);
    outline-offset: 2px;
}

/* Prompt card */
.maths-activity .sm-prompt {
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-left: 6px solid var(--maths-accent);
    border-radius: 10px;
    padding: 0.8rem 1.1rem;
    margin-bottom: 0.9rem;
}

.maths-activity .sm-prompt-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--maths-accent-dark);
    margin-bottom: 0.3rem;
}

.maths-activity .sm-prompt-label i {
    margin-right: 0.35rem;
}

.maths-activity .sm-prompt-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--maths-ink);
    line-height: 1.35;
}

/* Shape picker */
.maths-activity .sm-shape-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.maths-activity .sm-shape-btn {
    background: var(--maths-surface);
    border: 2px solid var(--maths-border);
    color: var(--maths-ink);
    border-radius: 8px;
    padding: 0.5rem 0.95rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.maths-activity .sm-shape-btn i {
    color: var(--maths-primary);
}

.maths-activity .sm-shape-btn:hover {
    border-color: var(--maths-primary);
    background: var(--maths-surface-alt);
}

.maths-activity .sm-shape-btn[aria-pressed="true"] {
    background: var(--maths-primary);
    border-color: var(--maths-primary);
    color: #fff;
}

.maths-activity .sm-shape-btn[aria-pressed="true"] i {
    color: #fff;
}

.maths-activity .sm-add-shape {
    margin-left: auto;
    border-style: dashed;
    color: var(--maths-accent);
    border-color: var(--maths-accent);
}

.maths-activity .sm-add-shape i {
    color: var(--maths-accent);
}

.maths-activity .sm-add-shape:hover {
    background: #FFF2EA;
    border-color: var(--maths-accent);
}

/* Workspace: canvas + readout side-by-side */
.maths-activity .sm-workspace {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(260px, 320px);
    gap: 1rem;
    align-items: start;
}

.maths-activity .sm-canvas-wrap {
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: stretch;
}

.maths-activity .sm-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 420px;
    touch-action: none;
    border-radius: 6px;
}

.maths-activity .sm-legend {
    font-size: 0.85rem;
    color: var(--maths-ink-muted);
}

.maths-activity .sm-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.maths-activity .sm-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid var(--maths-grid-line);
}

.maths-activity .sm-swatch-grid {
    background: repeating-linear-gradient(
        90deg,
        var(--maths-surface) 0 3px,
        var(--maths-grid-line) 3px 4px
    ),
    repeating-linear-gradient(
        0deg,
        var(--maths-surface) 0 3px,
        var(--maths-grid-line) 3px 4px
    );
}

/* Readout panel */
.maths-activity .sm-readout {
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-radius: 10px;
    padding: 1rem 1.1rem;
}

.maths-activity .sm-readout-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--maths-ink-muted);
    margin-bottom: 0.6rem;
}

/* Per-shape list (2D) */
.maths-activity .sm-shapes-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}

.maths-activity .sm-shape-row {
    --shape-colour: var(--maths-primary);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    background: var(--maths-surface-alt);
    border-radius: 6px;
    border-left: 4px solid var(--shape-colour);
}

.maths-activity .sm-shape-swatch {
    width: 14px;
    height: 14px;
    background: var(--shape-colour);
    border-radius: 3px;
}

.maths-activity .sm-shape-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--maths-ink);
}

.maths-activity .sm-shape-metrics {
    font-size: 0.85rem;
    color: var(--maths-ink-muted);
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    margin-top: 0.1rem;
}

.maths-activity .sm-shape-metrics strong {
    color: var(--maths-ink);
    font-variant-numeric: tabular-nums;
}

.maths-activity .sm-shape-remove {
    background: transparent;
    border: none;
    color: var(--maths-ink-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.maths-activity .sm-shape-remove:hover {
    background: #FBEAE7;
    color: var(--maths-danger);
}

/* Totals (2D) */
.maths-activity .sm-totals {
    border-top: 1px solid var(--maths-border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.maths-activity .sm-total-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.maths-activity .sm-total-label {
    font-weight: 700;
    color: var(--maths-ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.85rem;
}

.maths-activity .sm-total-value {
    font-weight: 800;
    color: var(--maths-primary);
    font-variant-numeric: tabular-nums;
    font-size: 1.5rem;
}

.maths-activity .sm-total-area .sm-total-value {
    color: var(--maths-accent);
}

/* 3D mode */
.maths-activity .sm-dim-sliders {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.maths-activity .sm-dim-slider {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: center;
}

.maths-activity .sm-dim-slider > span:first-child {
    font-weight: 600;
    color: var(--maths-ink);
    font-size: 0.95rem;
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
}

.maths-activity .sm-dim-slider strong {
    color: var(--maths-primary);
    font-variant-numeric: tabular-nums;
}

.maths-activity .sm-dim-slider input[type="range"] {
    grid-column: 1 / -1;
}

.maths-activity .sm-calc-row {
    display: grid;
    grid-template-columns: 1fr auto;
    row-gap: 0.15rem;
    column-gap: 0.5rem;
    align-items: baseline;
    margin-bottom: 0.7rem;
}

.maths-activity .sm-calc-label {
    font-weight: 700;
    color: var(--maths-ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.8rem;
}

.maths-activity .sm-calc-value {
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--maths-accent);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.maths-activity .sm-calc-formula {
    grid-column: 1 / -1;
    font-size: 0.9rem;
    color: var(--maths-ink);
    font-variant-numeric: tabular-nums;
}

.maths-activity .sm-net-wrap {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--maths-border);
}

.maths-activity .sm-net-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--maths-ink-muted);
    margin-bottom: 0.5rem;
}

.maths-activity .sm-net-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 220px;
    border-radius: 4px;
    background: var(--maths-surface-alt);
}

.maths-activity .sm-net-hint {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--maths-ink-muted);
}

/* Pythagoras mode */
.maths-activity .sm-pyth-equation {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.9rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--maths-ink);
    margin-bottom: 0.7rem;
}

.maths-activity .sm-pyth-leg {
    color: var(--maths-primary);
    font-variant-numeric: tabular-nums;
}

.maths-activity .sm-pyth-formula {
    color: var(--maths-success);
}

.maths-activity .sm-pyth-working {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--maths-ink);
    padding: 0.6rem 0.8rem;
    background: #E6F2EE;
    border-radius: 6px;
    border-left: 4px solid var(--maths-success);
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.7rem;
}

.maths-activity .sm-pyth-working strong {
    color: var(--maths-success);
    font-size: 1.25rem;
}

.maths-activity .sm-pyth-hint {
    font-size: 0.9rem;
    color: var(--maths-ink-muted);
    line-height: 1.4;
}

@media (max-width: 760px) {
    .maths-activity .sm-workspace {
        grid-template-columns: 1fr;
    }
    .maths-activity .sm-mode-tab .sm-mode-hint {
        display: none;
    }
}

/* Display mode — content-step snapshot. Strip all interactive chrome:
 * mode tabs, shape picker, add/remove buttons, dimension sliders, the
 * prompt card. Keep the canvas and totals/readout visible so the
 * labelled shape tells the story. Interaction handlers are already
 * short-circuited in JS. */
body.display-mode .sm-mode-tabs,
body.display-mode .sm-shape-picker,
body.display-mode .sm-shape-btn,
body.display-mode .sm-add-shape,
body.display-mode [data-remove-shape],
body.display-mode .sm-prompt,
body.display-mode .sm-dim-slider,
body.display-mode input[type="range"] {
    display: none !important;
}

body.display-mode canvas {
    cursor: default;
}

/* ---------------------------------------------------------------------------
 * Challenge mode (a `shapeMeasurerChallenges` bank in the config).
 *
 * The widget's whole readout panel is a LIVE answer key — perimeter and area
 * update as the shape is dragged. That is right for explore and for a display
 * snapshot, and fatal for a challenge: the pupil would be asked to find a number
 * printed six inches to the right. So a bank hides the computed values and
 * leaves the drawing, the grid and the unit labels, which are what they measure
 * FROM. The values come back on the end-of-set summary.
 * ------------------------------------------------------------------------- */
body.sm-challenge .sm-shape-metrics,
body.sm-challenge .sm-totals,
body.sm-challenge #volumeFormula,
body.sm-challenge #volumeValue,
body.sm-challenge #surfaceFormula,
body.sm-challenge #surfaceValue,
body.sm-challenge .sm-pyth-working { visibility: hidden; }

/* The rows keep their height so the panel does not jump when Check reveals. */
body.sm-challenge .sm-readout-title::after {
    content: " — work it out yourself";
    font-weight: 600;
    opacity: 0.7;
}

/* Scoped to the panel by id, NOT to the bare class. `sm-challenge` is used for
 * two different jobs — it is the panel's own class AND the state flag the JS
 * puts on <body> while a bank is running. A bare `.sm-challenge { display:none }`
 * therefore matched the BODY and blanked the entire widget the moment a bank
 * started, on all 8 lessons that carry one. */
#challengePanel {
    display: none;
    margin: 10px 0;
    padding: 12px 14px;
    border-radius: 10px;
}
body.sm-challenge #challengePanel { display: block; }
#challengePanel[hidden] { display: none !important; }

.sm-challenge-ask {
    font-weight: 700;
    color: var(--maths-ink, #163a5f);
    margin-bottom: 8px;
}
.sm-challenge-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.sm-challenge-input {
    width: 8.5rem;
    padding: 8px 10px;
    font: inherit;
    font-weight: 700;
    text-align: right;
    border: 2px solid #c7dcf2;
    border-radius: 8px;
}
.sm-challenge-input:focus {
    outline: none;
    border-color: #1565c0;
}
.sm-challenge-unit {
    font-weight: 700;
    color: var(--maths-ink, #163a5f);
}
.sm-challenge-hint-btn {
    margin-top: 8px;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.9em;
    color: #1565c0;
    text-decoration: underline;
    cursor: pointer;
}
.sm-challenge-callout { margin-top: 10px; }
