/* Whiskers & Witches Retro Theme Styles */

.witch-game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #111115;
    padding: 20px;
    border-radius: 12px;
    border: 3px solid #2d2d3a;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
    font-family: 'Press Start 2P', monospace, sans-serif;
    color: #eee;
    max-width: 900px;
    margin: 0 auto;
}

#witch-ui-overlay {
    width: 100%;
}

/* Panel Containers */
.witch-panel {
    background-color: #1a1a24;
    border: 4px double #4a4a5a;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    margin: 20px auto;
    max-width: 750px;
}

.witch-panel h2 {
    font-size: 1.5rem;
    color: #ff99cc;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0px #000;
}

.witch-panel p {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #a0a0b0;
    margin-bottom: 25px;
}

/* Character Selection Screen */
.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.char-card {
    background-color: #232330;
    border: 3px solid #3c3c4e;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s, border-color 0.2s;
    cursor: pointer;
}

.char-card:hover {
    transform: translateY(-5px);
    border-color: #ff99cc;
}

.char-avatar {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: #1a1a24;
    border: 2px solid #555;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.char-avatar.bubby { border-color: #ff99cc; background: radial-gradient(circle, #ffccd5 0%, #1a1a24 70%); }
.char-avatar.smart { border-color: #33ccff; background: radial-gradient(circle, #ccf2ff 0%, #1a1a24 70%); }
.char-avatar.chaos { border-color: #9933ff; background: radial-gradient(circle, #ebd6ff 0%, #1a1a24 70%); }
.char-avatar.regal { border-color: #ffff33; background: radial-gradient(circle, #ffffe0 0%, #1a1a24 70%); }

.char-card h3 {
    font-size: 1rem;
    color: #fff;
    margin: 5px 0;
}

.role-desc {
    font-size: 0.6rem;
    color: #ffcc00 !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.spell-desc {
    font-size: 0.6rem;
    color: #a0a0b0;
    min-height: 50px;
    line-height: 1.4;
}

.btn-select {
    width: 100%;
    font-size: 0.65rem;
    padding: 8px;
    margin-top: 10px;
    border-radius: 4px;
}

/* Placement Screen */
.placement-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.placement-canvas-container {
    background-color: #0c0c0f;
    padding: 10px;
    border-radius: 8px;
    border: 3px solid #2d2d3a;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
    margin-bottom: 20px;
}

#placement-canvas {
    display: block;
    image-rendering: pixelated;
}

.placement-controls {
    display: flex;
    gap: 15px;
}

/* HUD & Status Header */
.witch-game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background-color: #1a1a24;
    border: 3px solid #3c3c4e;
    border-radius: 8px;
    padding: 12px 20px;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.player-hud {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hud-portrait {
    font-size: 2rem;
    background-color: #111115;
    border: 2px solid #555;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hud-info h3 {
    font-size: 0.75rem;
    margin: 0 0 5px 0;
    color: #fff;
}

.power-status {
    font-size: 0.62rem;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: bold;
}

.power-status.unlocked {
    animation: ready-glow 1.2s infinite alternate;
}

@keyframes ready-glow {
    from { box-shadow: 0 0 3px rgba(102, 255, 102, 0.4); }
    to   { box-shadow: 0 0 10px rgba(102, 255, 102, 0.9); }
}

.power-status.locked {
    background-color: #3a1a1a;
    color: #ff6666;
}

.power-status.unlocked {
    background-color: #1a3a1a;
    color: #66ff66;
}

.turn-indicator {
    font-size: 0.9rem;
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 6px;
    text-shadow: 1px 1px 0 #000;
}

.turn-indicator.my-turn {
    background-color: #00ffcc;
    color: #111115;
    box-shadow: 0 0 10px rgba(0,255,204,0.5);
    animation: pulse 1.5s infinite;
}

.turn-indicator.opp-turn {
    background-color: #ff3366;
    color: #fff;
    box-shadow: 0 0 10px rgba(255,51,102,0.3);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Canvas Styling */
#witch-canvas-container {
    width: 100%;
}

#witchbattleship-canvas {
    width: 100%;
    max-width: 800px;
    height: auto;
    background-color: #0c0c0f;
    border: 4px solid #3c3c4e;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    display: block;
    margin: 0 auto;
    image-rendering: pixelated;
    /* Allow the page to scroll (pan) when dragging on the tall portrait canvas,
       while a tap still registers as a click. Also removes the 300ms tap delay. */
    touch-action: manipulation;
}

/* Game Over Screen */
.game-over-panel h1 {
    font-size: 2.2rem;
    margin-bottom: 20px;
    text-shadow: 3px 3px 0 #000;
}

.text-win {
    color: #00ffcc;
}

.text-lose {
    color: #ff3366;
}

/* Loader Animation */
.pixel-loader {
    width: 40px;
    height: 40px;
    margin: 20px auto;
    border: 4px solid #ff99cc;
    border-top: 4px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ──────────────────────────────────────────
   Dialogue Bark Box (Visual Novel style)
────────────────────────────────────────── */
.witch-dialogue-box {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    background-color: #12121a;
    border: 2px solid #4a4a5a;
    border-radius: 6px;
    padding: 10px 16px;
    margin-top: 6px;
    min-height: 44px;
    overflow: hidden;
}

.dialogue-arrow {
    font-size: 1rem;
    flex-shrink: 0;
    animation: arrow-blink 0.8s step-start infinite;
}

@keyframes arrow-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

.dialogue-text {
    font-family: 'Press Start 2P', monospace, sans-serif;
    font-size: 0.65rem;
    line-height: 1.5;
    letter-spacing: 0.02em;
}

/* Slide-in animation triggered by JS */
.bark-slide-in {
    animation: bark-enter 0.25s ease-out forwards;
}

@keyframes bark-enter {
    from { transform: translateX(-12px); opacity: 0; }
    to   { transform: translateX(0);     opacity: 1; }
}

/* Three-tier spell status colours */
.power-status.used {
    background-color: #2a1a2a;
    color: #cc66ff;
}

.btn-cast-spell {
    font-family: 'Press Start 2P', monospace, sans-serif;
    font-size: 0.72rem;
    padding: 9px 15px;
    background-color: #4a1a4a;
    color: #ffccf0;
    border: 2px solid #ff99cc;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, transform 0.1s;
    box-shadow: 0 0 10px rgba(255, 153, 204, 0.45);
}

.btn-cast-spell:hover {
    background-color: #6a2a6a;
    border-color: #fff;
    transform: scale(1.05);
}

.btn-cast-spell.cast-armed {
    background-color: #ff99cc;
    color: #111115;
    border-color: #fff;
    box-shadow: 0 0 8px rgba(255, 153, 204, 0.6);
    animation: spell-pulse 1s infinite alternate;
}

@keyframes spell-pulse {
    from { box-shadow: 0 0 4px rgba(255, 153, 204, 0.4); }
    to { box-shadow: 0 0 12px rgba(255, 153, 204, 0.8); }
}

/* Armed but no area picked yet — calmer look than the ready-to-fire button */
.btn-cast-spell.cast-waiting {
    background-color: #3a2340;
    color: #e6c6f0;
    border-color: #a066b0;
    box-shadow: none;
    animation: none;
}

/* Cancel (disarm) button shown next to the confirm button while casting */
.btn-cast-cancel {
    font-family: 'Press Start 2P', monospace, sans-serif;
    font-size: 0.72rem;
    padding: 9px 12px;
    background-color: #3a1a1a;
    color: #ffb3b3;
    border: 2px solid #ff6666;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, transform 0.1s;
}

.btn-cast-cancel:hover {
    background-color: #5a2a2a;
    border-color: #fff;
    transform: scale(1.05);
}

#witch-saved-banner {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(26, 26, 36, 0.95);
    border: 4px solid #ffcc00;
    border-radius: 8px;
    padding: 20px 40px;
    font-family: 'Press Start 2P', monospace, sans-serif;
    font-size: 1.1rem;
    color: #ffcc00;
    text-shadow: 2px 2px 0px #000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), inset 0 0 15px rgba(255, 204, 0, 0.2);
    z-index: 1000;
    pointer-events: none;
    white-space: nowrap;
}

.witch-saved-banner-anim {
    animation: banner-fade-in-out 2.5s ease-in-out forwards;
}

@keyframes banner-fade-in-out {
    0% {
        opacity: 0;
        transform: translate(-50%, -60%) scale(0.9);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
    15% {
        transform: translate(-50%, -50%) scale(1);
    }
    85% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -40%) scale(0.95);
    }
}

/* Portrait image styling */
.witch-portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: pixelated;
}

.char-avatar .witch-portrait-img {
    border-radius: 50%;
}

/* ──────────────────────────────────────────
   Reaction cards — two stacked rectangles rising from the bottom.
   Yours hugs the left edge (on top); the opponent's hugs the right
   edge beneath it, so each side is unmistakably attributed.
────────────────────────────────────────── */
.witch-vs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 10px 12px;
    z-index: 1200;
    /* Only the cards catch taps; everything else falls through to the board. */
    pointer-events: none;
}

.vs-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 90%;
    max-width: 470px;
    box-sizing: border-box;
    padding: 12px 16px;
    background: #14141d;
    border: 3px solid #4a4a5a;
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.85);
    pointer-events: auto;
    cursor: pointer;
    /* Show/hide state (transform + opacity) is driven inline by JS; this just
       defines how it eases between them. */
    transition: transform 0.45s cubic-bezier(0.22, 0.9, 0.3, 1.15), opacity 0.3s ease;
}

/* You: flush left, thick signature edge on the left */
.vs-card-left {
    align-self: flex-start;
    border-left-width: 7px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0));
}

/* Opponent: flush right, portrait on the right, thick edge on the right */
.vs-card-right {
    align-self: flex-end;
    flex-direction: row-reverse;
    text-align: right;
    border-right-width: 7px;
    background: linear-gradient(270deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0));
}

.vs-portrait {
    flex: 0 0 auto;
    width: 76px;
    height: 76px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #6a6a8a;
    background: #111115;
}

.vs-portrait .witch-portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
}

.vs-speech {
    font-family: 'Press Start 2P', monospace, sans-serif;
    font-size: 0.72rem;
    line-height: 1.6;
    min-width: 0;
    word-break: break-word;
}

@media (max-width: 680px) {
    .witch-vs { gap: 8px; padding: 0 8px 10px; }
    .vs-card { width: 93%; padding: 10px 12px; gap: 11px; }
    .vs-portrait { width: 64px; height: 64px; }
    .vs-speech { font-size: 0.62rem; line-height: 1.55; }
}

/* Aura Glow */
.aura-glow {
    box-shadow: 0 0 15px 5px var(--glow-color, rgba(255, 255, 255, 0.7));
    animation: aura-pulse 2s infinite alternate;
}

@keyframes aura-pulse {
    0% { box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.5); }
    100% { box-shadow: 0 0 20px 8px rgba(255, 255, 255, 0.9); }
}

/* Large reaction portrait popping over the board. Portrait-aspect box with a
   16-bit double frame (matching the VN quote box) so the face sits cleanly. */
#witch-reaction-portrait {
    position: absolute;
    bottom: 28px;
    right: 28px;
    width: 168px;
    height: 208px;
    border: 3px solid #6a6a8a;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px #12121a, inset 0 0 0 4px #3c3c4e,
                0 8px 30px rgba(0, 0, 0, 0.85);
    z-index: 900;
    pointer-events: none;
    background: #111115;
}

/* Frame the face: bias the crop toward the top of the portrait art. */
#witch-reaction-portrait .witch-portrait-img {
    object-fit: cover;
    object-position: top center;
}

.witch-reaction-anim {
    animation: reaction-pop 2.6s ease-in-out forwards;
}

@keyframes reaction-pop {
    0%   { opacity: 0; transform: translateY(30px) scale(0.85); }
    12%  { opacity: 1; transform: translateY(0) scale(1.06); }
    18%  { transform: translateY(0) scale(1); }
    85%  { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(18px) scale(0.95); }
}

/* ──────────────────────────────────────────
   Character-select hero preview
────────────────────────────────────────── */
.character-select-panel {
    max-width: 820px;
}

.witch-hero {
    display: flex;
    gap: 20px;
    align-items: stretch;
    text-align: left;
    margin: 10px 0 18px;
}

.witch-hero-art {
    flex: 0 0 240px;
    border: 3px solid #ff99cc;
    border-radius: 10px;
    overflow: hidden;
    background: #0c0c0f;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    align-self: flex-start;
}

.witch-hero-img {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    image-rendering: pixelated;
}

.witch-hero-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.witch-hero-heading {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.witch-hero-name {
    font-size: 1.2rem;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
}

.witch-hero-role {
    font-size: 0.6rem;
    color: #ffcc00;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* 16-bit visual-novel style quote frame */
.vn-quote-box {
    position: relative;
    background: #12121a;
    border: 3px solid #6a6a8a;
    border-radius: 4px;
    box-shadow: inset 0 0 0 2px #12121a, inset 0 0 0 4px #3c3c4e;
    padding: 12px 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vn-quote-name {
    font-size: 0.62rem;
    color: #ffcc00;
    text-shadow: 1px 1px 0 #000;
}

.vn-quote-text {
    font-size: 0.6rem;
    line-height: 1.7;
    color: #e6e6f0;
}

.witch-spell {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #1a1a24;
    border: 2px solid #3c3c4e;
    border-radius: 6px;
    padding: 12px 14px;
}

.witch-spell-text {
    flex: 1;
    min-width: 0;
}

.witch-spell-name {
    font-size: 0.72rem;
    color: #66ffcc;
    margin-bottom: 6px;
}

.witch-spell-desc {
    font-size: 0.58rem;
    color: #cfcfe0;
    line-height: 1.5;
}

.witch-spell-hint {
    font-size: 0.5rem;
    color: #8a8a9e;
    margin-top: 6px;
}

/* 5×5 spell-pattern mini-grid */
.spell-grid {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: repeat(5, 14px);
    grid-template-rows: repeat(5, 14px);
    gap: 2px;
    padding: 6px;
    background: #0c0c0f;
    border: 2px solid #2d2d3a;
    border-radius: 4px;
}

.spell-cell {
    width: 14px;
    height: 14px;
    background: #23232e;
    border-radius: 2px;
}

.spell-cell.on { box-shadow: 0 0 5px currentColor; }
.spell-cell.on.block  { background: #ff99cc; color: #ff99cc; }
.spell-cell.on.line   { background: #00ffcc; color: #00ffcc; }
.spell-cell.on.cross  { background: #ffcc00; color: #ffcc00; }
.spell-cell.on.random { background: #cc66ff; color: #cc66ff; }

.btn-choose-witch {
    margin-top: auto;
    font-size: 0.85rem;
    padding: 12px 20px;
}

/* Thumbnail switcher row */
.witch-thumb-row {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.witch-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    background: #232330;
    border: 2px solid #3c3c4e;
    border-radius: 8px;
    padding: 8px 6px;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
    flex: 1;
    max-width: 96px;
}

.witch-thumb:hover { transform: translateY(-3px); border-color: #ff99cc; }

.witch-thumb.active {
    border-color: #ff99cc;
    box-shadow: 0 0 10px rgba(255, 153, 204, 0.6);
    background: #2e2340;
}

.witch-thumb-portrait {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #555;
    background: #111115;
}

.witch-thumb.active .witch-thumb-portrait { border-color: #ff99cc; }

.witch-thumb-name {
    font-size: 0.55rem;
    color: #fff;
}

/* ──────────────────────────────────────────
   Intro / How-to-play screen
────────────────────────────────────────── */
.intro-screen {
    max-width: 780px;
}

.intro-story {
    color: #ffd9ec !important;
    font-size: 0.72rem !important;
    line-height: 1.7 !important;
    margin-bottom: 20px !important;
}

.intro-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
    margin: 0 auto 24px;
    max-width: 560px;
}

.intro-step {
    background-color: #232330;
    border: 2px solid #3c3c4e;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.62rem;
    line-height: 1.6;
    color: #cfcfe0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.intro-step span {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.intro-step b {
    color: #ff99cc;
}

.intro-subhead {
    font-size: 0.7rem;
    color: #ffcc00;
    margin: 10px 0 16px;
    text-shadow: 1px 1px 0 #000;
}

.intro-witch-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 460px;
    margin: 0 auto 26px;
}

.intro-witch {
    background-color: #232330;
    border: 2px solid #3c3c4e;
    border-radius: 8px;
    padding: 10px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.intro-witch-portrait {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #ff99cc;
    background: #111115;
    margin-bottom: 4px;
}

.intro-witch-name {
    font-size: 0.62rem;
    color: #fff;
}

.intro-witch-spell {
    font-size: 0.52rem;
    color: #66ffcc;
    line-height: 1.3;
}

.intro-witch-desc {
    font-size: 0.48rem;
    color: #a0a0b0;
    line-height: 1.3;
}

.btn-intro-start {
    font-size: 0.9rem;
    padding: 12px 28px;
}

/* Ending-screen generated art */
.ending-art {
    display: block;
    max-width: 320px;
    width: 70%;
    margin: 16px auto;
    border: 4px solid #ffcc00;
    border-radius: 10px;
    image-rendering: pixelated;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
}

/* ──────────────────────────────────────────
   Responsive / narrow-viewport layout
────────────────────────────────────────── */
@media (max-width: 680px) {
    .witch-game-container {
        padding: 8px;
        border-width: 2px;
    }

    .witch-game-header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 8px 10px;
    }

    /* Turn indicator gets its own full-width row above the two player HUDs */
    .turn-indicator {
        order: -1;
        width: 100%;
        text-align: center;
        font-size: 0.8rem;
    }

    .player-hud {
        flex: 1 1 45%;
        min-width: 0;
        gap: 8px;
    }

    .hud-info h3 {
        font-size: 0.58rem;
    }

    .hud-portrait {
        width: 40px;
        height: 40px;
    }

    .btn-cast-spell {
        font-size: 0.62rem;
        padding: 7px 10px;
    }

    /* The play container is very tall in portrait, so bottom-anchoring puts the
       reaction pop way below the fold. Tuck it against the RIGHT edge, below the
       HUD header + dialogue text, so it hovers over the top-right of the board
       (off to the side) instead of covering the dialogue text. */
    #witch-reaction-portrait {
        width: 92px;
        height: 116px;
        top: 160px;
        right: 6px;
        left: auto;
        bottom: auto;
    }

    #witch-saved-banner {
        font-size: 0.8rem;
        padding: 12px 18px;
        white-space: normal;
        text-align: center;
        max-width: 80%;
    }

    .intro-witch-row {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Character-select hero stacks vertically on narrow screens */
    .witch-hero {
        flex-direction: column;
        align-items: center;
    }

    .witch-hero-art {
        flex: 0 0 auto;
        width: 190px;
    }

    .witch-hero-info {
        width: 100%;
    }

    .witch-thumb-row {
        flex-wrap: wrap;
    }
}
