/* === Prefecture exercise ============================================
   Companion to js/games/prefecture.js + games/prefecture.partial.html.
   Loaded via <link> in index.html; lives in the same #game-stage as
   Swipe / Fall / Rain (opacity-toggled, only one active at a time).

   Tokens come from css/theme.css — never hard-code colors. The map's
   selected-path styling deliberately uses --accent (vermillion in
   light theme, indigo in dark) so the design language stays unified.
   ==================================================================== */

.prefecture-game {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 720px;
    padding: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
    z-index: 2;
}

.prefecture-game.active {
    opacity: 1;
    pointer-events: auto;
}

/* Prefecture content is taller than card-area's natural height, so
   .game-stage collapses around the (absolute) game and SEO content
   below overlaps the answer-line slots. Force .game-stage to be tall
   enough — desktop fits in ~720px (map + info side-by-side); mobile
   stacks vertically and needs more. */
body.prefecture-active .game-stage {
    min-height: 720px;
}

/* Mobile-anchored variant — anchor the game to the TOP of game-stage
   instead of center, so when content overflows it pushes downward
   (into the min-height block) rather than upward where the toolbar /
   carousel sits. Pair this with a taller min-height so the answer
   line never reaches SEO copy below. */
@media (max-width: 640px) {
    body.prefecture-active .game-stage {
        min-height: 880px;
    }
    .prefecture-game {
        top: 0;
        transform: translateX(-50%);
    }
}

/* === Header ========================================================= */
.prefecture-game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
}

.prefecture-score {
    font-size: 0.85rem;
    color: var(--green);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.prefecture-stats {
    font-size: 0.8rem;
    color: var(--accent);
    flex: 1;
    text-align: center;
}

.prefecture-close {
    background: var(--close-bg);
    border: 1px solid var(--close-border);
    color: var(--close-color);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.prefecture-close:hover {
    background: var(--close-hover);
    color: var(--text);
}

/* === Stage (map + prompt strip) ===================================== */
.prefecture-stage {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
}

.prefecture-map-wrap {
    position: relative;
    aspect-ratio: 1000 / 846;
    background: var(--carousel-bg);
    border: 1px solid var(--subtle-border);
    border-radius: 14px;
    overflow: hidden;
}

.prefecture-map-wrap svg {
    width: 100%;
    height: 100%;
    display: block;
}

.prefecture-map-wrap svg path {
    fill: var(--char-fill);
    stroke: var(--container-border);
    stroke-width: 0.6;
    transition: fill 0.25s ease, stroke 0.25s ease;
    cursor: pointer;
}

.prefecture-map-wrap svg path:hover {
    fill: var(--accent-hover);
}

.prefecture-map-wrap svg.has-selection path {
    fill: var(--char-fill);
    opacity: 0.35;
}

.prefecture-map-wrap svg path.is-selected,
.prefecture-map-wrap svg.has-selection path.is-selected {
    fill: var(--accent);
    stroke: var(--accent);
    stroke-width: 0.8;
    opacity: 1;
}

.prefecture-map-reset {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--bg);
    border: 1px solid var(--subtle-border);
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}
.prefecture-map-reset:hover {
    background: var(--accent-hover);
    color: var(--accent);
}
.prefecture-map-reset[hidden] { display: none; }
.prefecture-map-reset-arrow {
    font-size: 0.9rem;
    line-height: 1;
}

/* === Prompt strip =================================================== */
.prefecture-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--subtle-border);
    border-radius: 14px;
    box-shadow: var(--card-shadow);
    text-align: center;
}

.prefecture-prompt-region {
    font-family: 'IBM Plex Mono', monospace, sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.prefecture-prompt-name {
    font-size: 2rem;
    line-height: 1.1;
    font-weight: 500;
    color: var(--heading);
    letter-spacing: -0.01em;
}

.prefecture-hint-btn {
    background: transparent;
    border: 1px solid var(--subtle-border);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.prefecture-hint-btn:hover {
    background: var(--accent-hover);
    color: var(--accent);
    border-color: var(--accent-border);
}
.prefecture-hint-btn[hidden] { display: none; }

.prefecture-prompt-kana {
    font-size: 1.5rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}
.prefecture-prompt-kana[hidden] { display: none; }

/* === Writing surface =================================================
   A single large canvas (sized like the main Recall canvas) holds the
   currently-active kana; the user writes each character of the prefecture
   in sequence into the same canvas. After each commit, the canvas clears
   and loads the next kana — and the corresponding slot in the answer line
   below populates with the canonical kana character.
   ==================================================================== */
.prefecture-write {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* Canvas wrap — adds the 4-quadrant dashed crosshair guide underneath
   the canvas so the user reads the area as a hiragana-practice cell
   (same visual cue as printable kana practice sheets and the Fall
   game). The wrap sits on top of the canvas border-radius so guide
   lines don't bleed past the rounded corners. */
.prefecture-canvas-wrap {
    position: relative;
    width: 260px;
    height: 260px;
    border-radius: 16px;
    overflow: hidden;
}

/* Vertical + horizontal centerline guides. Explicit rgba values
   instead of a theme token — the standard tokens (--guide-line,
   --subtle-border, --container-border) step too coarsely between
   "barely visible" and "loud" for this use case. */
.prefecture-canvas-wrap::before,
.prefecture-canvas-wrap::after {
    content: '';
    position: absolute;
    border: 0;
    border-style: dashed;
    border-color: rgba(0, 0, 0, 0.22);
    pointer-events: none;
    z-index: 1;
}
body.dark .prefecture-canvas-wrap::before,
body.dark .prefecture-canvas-wrap::after {
    border-color: rgba(255, 255, 255, 0.25);
}
.prefecture-canvas-wrap::before {
    left: 50%; top: 0; bottom: 0;
    border-left-width: 1.5px;
}
.prefecture-canvas-wrap::after {
    top: 50%; left: 0; right: 0;
    border-top-width: 1.5px;
}

.prefecture-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: var(--bg);
    border: 2px solid var(--subtle-border);
    border-radius: 16px;
    box-sizing: border-box;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: crosshair;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.prefecture-canvas.miss-flash {
    border-color: var(--red);
    animation: prefecture-shake 0.4s ease;
}

@keyframes prefecture-shake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-4px); }
    40%      { transform: translateX(4px); }
    60%      { transform: translateX(-3px); }
    80%      { transform: translateX(3px); }
}

/* === Answer line ====================================================
   One .prefecture-slot per srs_unit. Pending slots show a subtle dashed
   placeholder; the active slot has an accent underline (the kana the
   user is writing right now); cleared slots show the canonical kana in
   the green confirmation color.
   ==================================================================== */
.prefecture-answer {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
    min-height: 56px;
}

.prefecture-slot {
    width: 44px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid var(--subtle-border);
    font-size: 1.8rem;
    line-height: 1;
    color: transparent;
    transition: color 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
}

.prefecture-slot.active {
    border-bottom-color: var(--accent);
}

.prefecture-slot.cleared {
    color: var(--green);
    border-bottom-color: var(--green);
    animation: prefecture-slot-pop 0.4s ease;
}

@keyframes prefecture-slot-pop {
    0%   { transform: translateY(4px) scale(0.85); opacity: 0; }
    60%  { transform: translateY(-2px) scale(1.08); opacity: 1; }
    100% { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* === Feedback line ================================================== */
.prefecture-feedback {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    opacity: 0;
    transition: opacity 0.3s ease;
    min-height: 1.4em;
}

/* === Empty state ==================================================== */
.prefecture-empty-state {
    width: 100%;
    padding: 30px 20px;
    text-align: center;
    background: var(--subtle-bg);
    border: 1px dashed var(--subtle-border);
    border-radius: 14px;
}
.prefecture-empty-state[hidden] { display: none; }

.prefecture-empty-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 6px;
}

.prefecture-empty-body {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* === Responsive ===================================================== */
@media (max-width: 640px) {
    .prefecture-stage {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .prefecture-map-wrap {
        max-height: 38vh;
    }

    .prefecture-info {
        padding: 12px;
    }

    .prefecture-prompt-name {
        font-size: 1.6rem;
    }

    .prefecture-canvas-wrap {
        width: 220px;
        height: 220px;
    }
    .prefecture-slot {
        width: 36px;
        height: 48px;
        font-size: 1.5rem;
    }
}
