/* ============================================================
   Rate this tool
   ============================================================

   The shared rating and private feedback component. Loaded only
   on pages that render it, which is every genuine tool page.

   NO NEW PALETTE. Every colour resolves to an A-to-Z token with
   the same fallback value after it, so load order cannot break
   it and nothing here introduces a second design system.

   STATE IS NEVER COLOUR ALONE. A selected star is filled AND
   larger AND named in the text beneath; an error is coral AND
   says what is wrong; success is mint AND says thank you.
   ============================================================ */

:root {
    --tr-bg:      var(--az-bg, #fbf9f7);
    --tr-surface: var(--az-surface, #ffffff);
    --tr-ink:     var(--az-ink, #10162b);
    --tr-ink-2:   var(--az-ink-2, #454d63);
    --tr-ink-3:   var(--az-ink-3, #5f677d);
    --tr-line:    var(--az-line, #e8e6e3);
    --tr-line-2:  var(--az-line-2, #f0eeeb);

    --tr-a-1:     var(--az-a-1, #5b8def);
    --tr-a-2:     var(--az-a-2, #7b5bf0);
    --tr-mid:     var(--az-mid, #c05ad9);
    --tr-star:    var(--az-z-2, #f89a4d);
    --tr-coral:   var(--az-z-1, #f0655f);
    --tr-mint:    var(--az-mint, #22b06b);

    /* Deeper than the coral above, which is a decorative accent:
       an error message has to clear 4.5:1 on white. */
    --tr-error:   #c62f2f;

    --tr-r:       var(--az-r, 14px);
    --tr-r-lg:    var(--az-r-lg, 18px);
    --tr-shadow:  var(--az-shadow, 0 4px 16px rgba(16, 22, 43, .06));
}

.tr {
    background: var(--tr-bg);
    padding: 26px 0 30px;
}

.tr *, .tr *::before, .tr *::after { box-sizing: border-box; }

.tr-card {
    max-width: 760px;
    margin: 0 auto;
    padding: 26px 26px 22px;
    background: var(--tr-surface);
    border: 1px solid var(--tr-line);
    border-radius: var(--tr-r-lg);
    box-shadow: var(--tr-shadow);
}

.tr-head { text-align: center; margin-bottom: 16px; }

.tr-title {
    margin: 0 0 6px;
    font-size: 1.3rem;
    color: var(--tr-ink);
    line-height: 1.25;
}

.tr-lede { margin: 0; color: var(--tr-ink-2); font-size: .96rem; }

.tr-visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ------------------------------------------------------------
   The aggregate
   ------------------------------------------------------------ */

.tr-aggregate {
    display: flex;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 12px 14px;
    margin-bottom: 18px;
    background: var(--tr-line-2);
    border-radius: var(--tr-r);
    text-align: center;
}

.tr-avg { font-size: 1.7rem; font-weight: 700; color: var(--tr-ink); line-height: 1; }
.tr-outof { font-size: .9rem; color: var(--tr-ink-3); }
.tr-count { font-size: .9rem; color: var(--tr-ink-2); font-weight: 600; }
.tr-none { font-size: .95rem; color: var(--tr-ink-2); }

/* ------------------------------------------------------------
   Stars

   The inputs are real radios, moved off-screen rather than
   hidden: display:none removes them from the focus order and
   from the accessibility tree, which is exactly what a keyboard
   user needs them to stay in.
   ------------------------------------------------------------ */

.tr-stars-set { border: 0; padding: 0; margin: 0 0 18px; text-align: center; }

.tr-legend {
    padding: 0;
    margin: 0 auto 8px;
    font-size: .82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--tr-ink-3);
}

.tr-stars {
    display: inline-flex;
    gap: 2px;
    /* Right-to-left so the CSS sibling selector can light every
       star to the LEFT of the hovered or checked one - the
       general sibling combinator only reaches forward. */
    flex-direction: row-reverse;
    justify-content: center;
}

.tr-radio {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    margin: 0;
    pointer-events: none;
}

.tr-star {
    /* 44x44 minimum, and it is the label that carries it - the
       input itself is a pixel off-screen. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--tr-line);
    transition: color .15s ease, transform .15s ease, background .15s ease;
}

.tr-star svg { fill: currentColor; display: block; }

/* Checked star and every star before it. */
.tr-radio:checked ~ .tr-star,
.tr-radio:checked + .tr-star {
    color: var(--tr-star);
}

/* Hover preview - the same fill, deliberately a different weight
   so a preview never looks like a committed choice. */
.tr-stars:hover .tr-star { color: var(--tr-line); }

.tr-star:hover,
.tr-star:hover ~ .tr-star {
    color: var(--tr-star);
    opacity: .72;
}

/* A committed choice always wins over a hover preview. */
.tr-stars:hover .tr-radio:checked ~ .tr-star,
.tr-stars:hover .tr-radio:checked + .tr-star {
    color: var(--tr-star);
    opacity: 1;
}

.tr-star:active { transform: scale(.94); }

/* VISIBLE FOCUS ON THE LABEL, driven by the off-screen input. */
.tr-radio:focus-visible + .tr-star {
    outline: 3px solid var(--tr-a-2);
    outline-offset: 2px;
    background: rgba(123, 91, 240, .08);
}

.tr-chosen {
    margin: 8px 0 0;
    font-size: .92rem;
    font-weight: 600;
    color: var(--tr-ink-2);
    min-height: 1.3em;
}

.tr-chosen.is-set { color: var(--tr-ink); }

/* ------------------------------------------------------------
   Comment
   ------------------------------------------------------------ */

.tr-field { margin-bottom: 14px; }

.tr-label {
    display: block;
    margin-bottom: 6px;
    font-size: .94rem;
    font-weight: 600;
    color: var(--tr-ink);
}

.tr-optional { font-weight: 400; color: var(--tr-ink-3); }

.tr-textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--tr-line);
    border-radius: var(--tr-r);
    background: var(--tr-surface);
    color: var(--tr-ink);
    font: inherit;
    font-size: .96rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 96px;
}

.tr-textarea:focus-visible {
    outline: 3px solid var(--tr-a-2);
    outline-offset: 1px;
    border-color: var(--tr-a-2);
}

.tr-meta { display: flex; justify-content: flex-end; margin-top: 5px; }

.tr-counter { font-size: .8rem; color: var(--tr-ink-3); font-variant-numeric: tabular-nums; }
.tr-counter.is-near { color: var(--tr-star); font-weight: 600; }
.tr-counter.is-full { color: var(--tr-error); font-weight: 600; }

.tr-sensitive { margin: 8px 0 0; font-size: .84rem; color: var(--tr-ink-3); }

/* The honeypot. Off-screen rather than display:none - some bots
   skip fields that are display:none, and this one is meant to be
   filled by them. Never reachable by tab or by a screen reader. */
.tr-hp {
    position: absolute !important;
    left: -9999px;
    top: auto;
    width: 1px; height: 1px;
    overflow: hidden;
}

/* ------------------------------------------------------------
   Privacy, actions, status
   ------------------------------------------------------------ */

.tr-privacy {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 16px;
    padding: 10px 12px;
    background: rgba(91, 141, 239, .07);
    border-left: 3px solid var(--tr-a-1);
    border-radius: 0 var(--tr-r) var(--tr-r) 0;
    font-size: .88rem;
    color: var(--tr-ink-2);
}

.tr-lock { flex: none; color: var(--tr-a-1); margin-top: 1px; }
.tr-lock svg { fill: currentColor; display: block; }

.tr-actions { display: flex; justify-content: center; }

.tr-submit {
    min-height: 48px;
    min-width: 200px;
    padding: 0 26px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--tr-a-1), var(--tr-a-2));
    color: #fff;
    font: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter .15s ease, transform .15s ease;
}

.tr-submit:hover:not(:disabled) { filter: brightness(1.06); }
.tr-submit:active:not(:disabled) { transform: translateY(1px); }

.tr-submit:focus-visible {
    outline: 3px solid var(--tr-ink);
    outline-offset: 3px;
}

.tr-submit:disabled { opacity: .62; cursor: not-allowed; }

/* Loading - a spinner AND the word, because a spinner alone
   says nothing to a screen reader. */
.tr-submit.is-busy::before {
    content: "";
    display: inline-block;
    width: 15px; height: 15px;
    margin-right: 9px;
    vertical-align: -2px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tr-spin .7s linear infinite;
}

@keyframes tr-spin { to { transform: rotate(360deg); } }

.tr-status {
    margin: 12px 0 0;
    min-height: 1.3em;
    text-align: center;
    font-size: .93rem;
    font-weight: 600;
}

/* Every state names itself in words; the colour is the second
   signal, never the only one. */
.tr-status.is-error { color: var(--tr-error); }
.tr-status.is-success { color: #0d5c37; }
.tr-status.is-info { color: var(--tr-ink-2); font-weight: 500; }

/* ------------------------------------------------------------
   Success
   ------------------------------------------------------------ */

.tr-done {
    text-align: center;
    padding: 22px 18px;
}

.tr-done-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px; height: 52px;
    margin-bottom: 12px;
    border-radius: 50%;
    background: rgba(34, 176, 107, .13);
    color: var(--tr-mint);
}

.tr-done-icon svg { fill: currentColor; display: block; }

.tr-done-title { margin: 0 0 6px; font-size: 1.12rem; color: var(--tr-ink); }
.tr-done-text { margin: 0 0 14px; color: var(--tr-ink-2); font-size: .95rem; }

.tr-again {
    min-height: 44px;
    padding: 0 20px;
    border: 1px solid var(--tr-line);
    border-radius: 999px;
    background: var(--tr-surface);
    color: var(--tr-ink-2);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.tr-again:hover { border-color: var(--tr-a-2); color: var(--tr-ink); }
.tr-again:focus-visible { outline: 3px solid var(--tr-a-2); outline-offset: 2px; }

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */

@media (max-width: 560px) {
    .tr { padding: 20px 0 24px; }
    .tr-card { margin: 0 12px; padding: 20px 16px 18px; border-radius: var(--tr-r); }
    .tr-title { font-size: 1.15rem; }
    .tr-star { width: 44px; height: 44px; }
    .tr-star svg { width: 27px; height: 27px; }
    .tr-submit { width: 100%; min-width: 0; }
}

@media (max-width: 340px) {
    .tr-star { width: 44px; height: 44px; }
    .tr-star svg { width: 23px; height: 23px; }
    .tr-card { padding: 18px 12px 16px; }
}

/* ------------------------------------------------------------
   Reduced motion

   Everything that moves is decoration over a state also carried
   in text, so removing the motion removes nothing. The spinner
   keeps a slow turn rather than stopping dead, so "busy" is
   still legible.
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    .tr-star,
    .tr-submit { transition-duration: .001ms !important; }

    .tr-star:active,
    .tr-submit:active:not(:disabled) { transform: none; }

    .tr-submit.is-busy::before { animation-duration: 2.4s; }
}
