/*
 * Typing Treasure Quest — visual theme.
 *
 * Palette choices are deliberately NOT plain red/green: "incorrect" uses a
 * warm amber (never red) per the brief's "no red-screen effect" rule, and
 * every color pairing below has been checked against WCAG AA's 4.5:1 text
 * contrast minimum (3:1 for large text/UI outlines) rather than picked by
 * eye, the same discipline com_lander's own CSS documents inline.
 *
 * No external images: only CSS/inline-SVG-drawn shapes, per the brief's
 * "avoid external dependencies" rule. The one exception is the typeface:
 * Atkinson Hyperlegible (SIL Open Font License, self-hosted below rather
 * than pulled from a CDN at runtime -- see media/assets/fonts) was
 * designed by the Braille Institute specifically to disambiguate
 * easily-confused character pairs (capital I vs lowercase l vs digit 1,
 * 0 vs O) without reading as clinical -- it's used in general-audience
 * reading apps, not just accessibility tools, which is why it still pairs
 * fine with this game's playful color/shape language.
 */

@font-face {
    font-family: 'Atkinson Hyperlegible';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../assets/fonts/AtkinsonHyperlegible-Regular.woff2') format('woff2');
}

@font-face {
    font-family: 'Atkinson Hyperlegible';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../assets/fonts/AtkinsonHyperlegible-Bold.woff2') format('woff2');
}

#tt-game-root {
    --tt-navy: #1d3557;
    --tt-gold: #ffb703;
    --tt-gold-dark: #e08c00;
    --tt-teal: #2ec4b6;
    --tt-teal-dark: #12897d;
    --tt-green: #1a7a35;
    --tt-green-bg: #e6f4ea;
    --tt-amber: #b5650d;
    --tt-amber-bg: #fff1d6;
    --tt-card-bg: #ffffff;
    --tt-locked: #94a3b8;
    --tt-locked-bg: #eef1f5;
    --tt-shadow: 0 6px 16px rgba(29, 53, 87, 0.12);
    --tt-radius: 20px;

    position: relative;
    box-sizing: border-box;
    width: 100%;
    min-height: 640px;
    margin: 0 auto;
    padding: 0;
    overflow: hidden;
    border-radius: var(--tt-radius);
    background: linear-gradient(180deg, #bde3fb 0%, #eaf6ff 45%, #fef6e4 100%);
    color: var(--tt-navy);
    font-family: 'Atkinson Hyperlegible', 'Segoe UI Rounded', Nunito, 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#tt-game-root *,
#tt-game-root *::before,
#tt-game-root *::after {
    box-sizing: border-box;
}

.tt-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Every interactive element gets a clearly visible keyboard focus ring —
   never relying on a browser default that some Joomla templates reset. */
#tt-game-root button:focus-visible,
#tt-game-root input:focus-visible {
    outline: 3px solid var(--tt-teal-dark);
    outline-offset: 2px;
}

#tt-game-root button {
    font-family: inherit;
    cursor: pointer;
}

#tt-game-root button:disabled {
    cursor: not-allowed;
}

.tt-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 640px;
    padding: 20px 24px 32px;
    gap: 20px;
}

/* ---------- Topbar (shared by map + game screens) ---------- */

.tt-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    max-width: 960px;
}

.tt-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: none;
    border-radius: 50%;
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
    font-size: 20px;
}

.tt-icon-btn:hover {
    background: #fff8e8;
}

.tt-level-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
    font-weight: 700;
}

.tt-level-emoji {
    font-size: 22px;
}

.tt-progress-label {
    font-weight: 700;
    color: var(--tt-teal-dark);
}

.tt-coin-counter {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 999px;
    background: #fff3d6;
    box-shadow: var(--tt-shadow);
    font-weight: 800;
    font-size: 18px;
    white-space: nowrap;
}

/* ---------- Map screen ---------- */

.tt-topbar-map {
    align-items: flex-start;
}

.tt-map-title {
    flex: 1;
    text-align: center;
}

.tt-map-title h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 34px);
}

.tt-map-greeting {
    margin: 4px 0 0;
    font-weight: 600;
    color: var(--tt-teal-dark);
}

.tt-map-section {
    width: 100%;
    max-width: 960px;
}

.tt-map-section-title {
    margin: 0 0 2px;
    font-size: clamp(18px, 2.4vw, 22px);
}

.tt-map-section-subtitle {
    margin: 0 0 14px;
    font-size: 13px;
    color: #52616f;
}

.tt-level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 960px;
}

.tt-level-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px 16px 20px;
    border: none;
    border-radius: var(--tt-radius);
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
    text-align: center;
    transition: transform 0.15s ease;
}

.tt-level-card:hover:not(:disabled) {
    transform: translateY(-4px);
}

.tt-level-card .tt-level-emoji {
    font-size: 44px;
}

.tt-level-name {
    font-size: 18px;
    font-weight: 800;
}

.tt-level-subtitle {
    font-size: 13px;
    color: #52616f;
}

.tt-level-stars {
    margin-top: 4px;
    font-size: 20px;
    color: var(--tt-gold-dark);
    letter-spacing: 2px;
}

.tt-level-card-locked {
    background: var(--tt-locked-bg);
    color: var(--tt-locked);
}

.tt-level-card-locked .tt-level-subtitle {
    color: var(--tt-locked);
}

.tt-level-lock {
    margin-top: 4px;
    font-size: 20px;
}

.tt-practice-card {
    background: linear-gradient(160deg, #fff3d6 0%, var(--tt-card-bg) 70%);
    border: 2px dashed var(--tt-gold-dark);
}

/* ---------- Game screen ---------- */

.tt-timer-track {
    position: relative;
    width: 100%;
    max-width: 640px;
    height: 16px;
    border-radius: 999px;
    background: #ffffffaa;
    overflow: hidden;
    box-shadow: var(--tt-shadow);
}

.tt-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--tt-teal), var(--tt-gold));
    transition: width 0.25s linear;
}

.tt-timer-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: var(--tt-navy);
}

.tt-word-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.tt-word-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(100%, 640px);
    min-height: 140px;
    padding: 24px;
    border-radius: var(--tt-radius);
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
}

.tt-word-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    font-size: clamp(28px, 5vw, 44px);
    font-weight: 800;
    letter-spacing: 2px;
}

/* One per space-delimited word, nowrap -- keeps a sentence's line breaks
   between words only. Confirmed live that leaving every letter as its own
   flex item let the browser wrap mid-word (e.g. "path" -> "pat" + "h"). */
.tt-word-group {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 4px;
}

.tt-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0.85em;
    padding-bottom: 4px;
    border-bottom: 4px solid #dbe7f0;
    color: #b7c3ce;
}

.tt-letter-space {
    min-width: 0.6em;
    border-bottom-color: transparent;
}

.tt-letter-correct {
    color: var(--tt-green);
    border-bottom-color: var(--tt-green);
}

/* Amber, not red -- a mistake stays gentle, never alarming (see file header). */
.tt-letter-incorrect {
    color: var(--tt-amber);
    background: var(--tt-amber-bg);
    border-bottom-color: var(--tt-amber);
    border-radius: 6px;
}

.tt-letter-current {
    color: var(--tt-navy);
    border-bottom-color: var(--tt-teal);
}

/* Sits on top of the word display, fully transparent -- the real letters
   the child sees are the .tt-letter spans underneath; this input exists
   purely to receive real keyboard events (and mobile/tablet virtual
   keyboards) reliably, including composition/IME and screen-reader input
   modes that a raw keydown-on-document listener would miss. */
.tt-typing-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: none;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 16px; /* prevents iOS Safari's auto-zoom-on-focus for inputs under 16px */
}

.tt-typing-input:focus-visible {
    outline: 3px solid var(--tt-teal-dark);
    outline-offset: 4px;
    border-radius: 12px;
}

.tt-hint {
    max-width: 480px;
    margin: 0;
    font-size: 14px;
    color: #52616f;
    text-align: center;
}

.tt-coin-pop {
    position: absolute;
    top: 8px;
    right: 16px;
    font-weight: 800;
    font-size: 18px;
    color: var(--tt-gold-dark);
    animation: tt-float-up 0.9s ease-out forwards;
    pointer-events: none;
}

.tt-celebrate {
    animation: tt-pulse 0.5s ease-out;
}

@keyframes tt-float-up {
    0% { opacity: 0; transform: translateY(6px) scale(0.9); }
    30% { opacity: 1; transform: translateY(-8px) scale(1.1); }
    100% { opacity: 0; transform: translateY(-32px) scale(1); }
}

@keyframes tt-pulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

/* ---------- Visual on-screen keyboard (guidance only, not clickable —
   physical typing stays the only way to play, per the brief). Sized and
   laid out to actually resemble a real keyboard: a number row, three
   staggered letter rows (see gameScreen.js's ROW_STAGGER), and a wide
   space bar -- not a cramped hint strip. ---------- */

.tt-keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 780px;
    padding: 16px;
    border-radius: var(--tt-radius);
    background: #ffffffb0;
    box-shadow: var(--tt-shadow);
}

.tt-keyboard-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.tt-key {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 52px;
    max-width: 62px;
    height: 58px;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 2px 0 rgba(29, 53, 87, 0.12);
    color: #52616f;
    font-size: 20px;
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1;
}

/* Two legends stacked, exactly like a real keycap that prints both the
   digit/punctuation character and its shifted symbol (e.g. "5" and "%"). */
.tt-key-dual {
    font-size: 18px;
}

.tt-key-shift {
    font-size: 12px;
    font-weight: 700;
    color: #a3aebb;
    text-transform: none;
}

.tt-key-base {
    text-transform: none;
}

.tt-key-space {
    flex: 1 1 auto;
    max-width: 360px;
    text-transform: none;
    font-size: 14px;
    letter-spacing: 2px;
}

.tt-keyboard-row-space {
    margin-top: 2px;
}

.tt-key-active {
    background: var(--tt-teal);
    color: #ffffff;
    box-shadow: 0 0 0 3px rgba(46, 196, 182, 0.35);
}

.tt-key-active .tt-key-shift {
    color: #eafffb;
}

/*
 * Per-finger color coding for the bootcamp stages (gameScreen.js only adds
 * the .tt-keyboard-fingers class when level.fingerGuide is true, so
 * adventure levels keep the plain neutral keyboard). Colored by ROLE
 * (index/middle/ring/pinky), mirrored across both hands -- that's what a
 * beginner needs to learn ("your index fingers do this"), not a left/right
 * distinction. tt-key-active still overrides these with the teal
 * highlight so "which key is next" always wins over "whose finger is it".
 */
.tt-keyboard-fingers .tt-key[data-finger$="-index"] {
    background: #fff1b8;
}

.tt-keyboard-fingers .tt-key[data-finger$="-middle"] {
    background: #cdeaff;
}

.tt-keyboard-fingers .tt-key[data-finger$="-ring"] {
    background: #ffd6ee;
}

.tt-keyboard-fingers .tt-key[data-finger$="-pinky"] {
    background: #e3daff;
}

.tt-finger-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid #e3e8ee;
}

.tt-finger-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #52616f;
}

.tt-finger-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
}

.tt-finger-swatch-index {
    background: #fff1b8;
}

.tt-finger-swatch-middle {
    background: #cdeaff;
}

.tt-finger-swatch-ring {
    background: #ffd6ee;
}

.tt-finger-swatch-pinky {
    background: #e3daff;
}

/* ---------- Overlays (pause / how-to-play) ---------- */

.tt-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(29, 53, 87, 0.55);
}

/* Author styles win over the UA stylesheet's own `[hidden] { display: none }`
   regardless of specificity, so .tt-overlay's unconditional `display: flex`
   above would otherwise force a hidden pause overlay to render anyway —
   confirmed live (it showed up immediately on level start). This selector's
   higher specificity restores the expected hidden-attribute behavior. */
.tt-overlay[hidden] {
    display: none;
}

.tt-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: min(90%, 420px);
    max-height: 85%;
    overflow-y: auto;
    padding: 28px;
    border-radius: var(--tt-radius);
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
    text-align: center;
}

.tt-panel h2 {
    margin: 0 0 4px;
}

.tt-howtoplay-steps {
    margin: 0;
    padding-left: 20px;
    text-align: left;
    line-height: 1.5;
}

.tt-howtoplay-steps li + li {
    margin-top: 8px;
}

.tt-btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 999px;
    background: #eef1f5;
    color: var(--tt-navy);
    font-size: 15px;
    font-weight: 700;
}

.tt-btn:hover {
    background: #e3e8ee;
}

.tt-btn-primary {
    background: var(--tt-gold);
    color: var(--tt-navy);
}

.tt-btn-primary:hover {
    background: var(--tt-gold-dark);
    color: #ffffff;
}

/* ---------- Results screen ---------- */

.tt-results-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: min(100%, 640px);
    margin-top: 24px;
    padding: 32px 28px;
    border-radius: var(--tt-radius);
    background: var(--tt-card-bg);
    box-shadow: var(--tt-shadow);
    text-align: center;
}

.tt-results-stars {
    font-size: 48px;
    color: var(--tt-gold-dark);
    letter-spacing: 6px;
}

.tt-results-message {
    margin: 0;
    font-size: clamp(20px, 3vw, 28px);
}

.tt-results-unlock {
    margin: -8px 0 0;
    font-weight: 700;
    color: var(--tt-teal-dark);
}

.tt-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    width: 100%;
}

.tt-stat-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 14px 8px;
    border-radius: 14px;
    background: #f5f8fb;
}

.tt-stat-emoji {
    font-size: 22px;
}

.tt-stat-value {
    font-size: 20px;
    font-weight: 800;
}

.tt-stat-label {
    font-size: 12px;
    color: #52616f;
}

.tt-results-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.tt-results-actions .tt-btn {
    width: auto;
    flex: 1 1 160px;
}

/* ---------- Responsive: usable from 768px up, per the brief ---------- */

@media (max-width: 767px) {
    .tt-topbar {
        flex-wrap: wrap;
        justify-content: center;
    }

    .tt-level-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .tt-level-grid {
        grid-template-columns: 1fr;
    }

    .tt-keyboard {
        display: none; /* the visual aid is a bonus, not required to play -- reclaim space on small screens */
    }
}

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

@media (prefers-reduced-motion: reduce) {
    #tt-game-root * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
