.tk-page {
    width: min(1480px, calc(100% - 2rem));
    margin: 0 auto;
    padding-top: 2.5rem;
}

.tk-game {
    --tk-bg: #141211;
    --tk-panel: rgba(22, 20, 18, 0.86);
    --tk-panel-strong: rgba(38, 32, 27, 0.94);
    --tk-line: rgba(244, 214, 141, 0.26);
    --tk-text: #f8f0df;
    --tk-muted: #c8b892;
    --tk-gold: #efc45b;
    --tk-red: #c94e3f;
    --tk-jade: #3da66b;
    --tk-blue: #4e83c5;
    --tk-ink: #201916;
    color: var(--tk-text);
    min-height: 780px;
}

.tk-game * {
    box-sizing: border-box;
}

.tk-commandbar {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto minmax(320px, 1fr);
    align-items: center;
    gap: 1rem;
    padding: 0.95rem 1rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(36, 24, 20, 0.95), rgba(32, 45, 38, 0.94));
    border: 1px solid var(--tk-line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(37, 28, 18, 0.24);
}

.tk-brand-block h2,
.tk-section-title h3 {
    color: var(--tk-text);
}

.tk-brand-block h2 {
    margin: 0;
    font-size: clamp(1.35rem, 2.2vw, 2.2rem);
    line-height: 1.05;
    letter-spacing: 0;
}

.tk-kicker {
    margin: 0 0 0.25rem;
    color: var(--tk-gold);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
}

.tk-run-stats {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tk-run-stats span,
.tk-cloud-pill {
    min-height: 2.1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.7rem;
    border: 1px solid rgba(239, 196, 91, 0.25);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    color: #f2dfb2;
    white-space: nowrap;
}

.tk-run-stats strong {
    color: #ffffff;
}

.tk-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    min-width: 0;
}

.tk-name-label {
    color: var(--tk-muted);
    font-size: 0.8rem;
    margin: 0;
}

#tk-player-name {
    width: 8rem;
    height: 2.35rem;
    padding: 0 0.75rem;
    color: #1d1712;
    background: #fff8e8;
    border: 1px solid rgba(239, 196, 91, 0.55);
    border-radius: 6px;
}

.tk-speed-row,
.tk-rank-tabs {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: rgba(0, 0, 0, 0.24);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
}

.tk-icon-button,
.tk-speed,
.tk-rank-tabs button {
    min-height: 2rem;
    min-width: 2.4rem;
    padding: 0 0.65rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--tk-muted);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: none;
}

.tk-icon-button {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.tk-icon-button.is-active,
.tk-speed.is-active,
.tk-rank-tabs button.is-active {
    color: #1e1711;
    background: var(--tk-gold);
}

.tk-sound-toggle.is-muted {
    color: var(--tk-muted);
    background: transparent;
    opacity: 0.7;
}

.tk-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px 300px;
    gap: 1rem;
    align-items: start;
}

.tk-arena-wrap,
.tk-draft-panel,
.tk-rank-panel {
    min-width: 0;
}

.tk-arena {
    --tk-formation-scale: 1;
    --tk-camera-x: 0px;
    --tk-shake-x: 0px;
    --tk-shake-y: 0px;
    position: relative;
    min-height: 430px;
    overflow: hidden;
    border: 1px solid var(--tk-line);
    border-radius: 8px;
    transform: translate(var(--tk-shake-x), var(--tk-shake-y));
    background:
        radial-gradient(120% 82% at 50% 6%, rgba(255, 226, 158, 0.22), transparent 46%),
        radial-gradient(72% 52% at 16% 22%, rgba(239, 196, 91, 0.16), transparent 60%),
        radial-gradient(72% 52% at 84% 24%, rgba(61, 166, 107, 0.14), transparent 60%),
        linear-gradient(180deg, #2a2622 0%, #1d1714 40%, #120d0b 66%, #2c2017 100%);
    box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.5), 0 18px 44px rgba(0, 0, 0, 0.16);
}

.tk-formation {
    position: absolute;
    left: calc(50% + var(--tk-camera-x));
    top: 52%;
    z-index: 2;
    width: 720px;
    height: 260px;
    transform: translate(-50%, -50%) scale(var(--tk-formation-scale));
    transform-origin: center center;
    transition: transform 420ms ease, left 420ms ease;
}

#tk-fx-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

.tk-skyline {
    position: absolute;
    inset: auto 0 0;
    height: 38%;
    z-index: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    opacity: 0.42;
    pointer-events: none;
}

.tk-skyline span {
    display: block;
    width: 14%;
    height: 40%;
    background: linear-gradient(180deg, rgba(239, 196, 91, 0.12), rgba(10, 10, 10, 0.58));
    clip-path: polygon(0 100%, 0 35%, 18% 35%, 18% 18%, 34% 18%, 34% 42%, 52% 42%, 52% 7%, 70% 7%, 70% 30%, 100% 30%, 100% 100%);
}

.tk-vs-mark {
    position: absolute;
    left: 50%;
    top: 52%;
    z-index: 2;
    transform: translate(-50%, -50%);
    width: 5rem;
    height: 5rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(239, 196, 91, 0.6);
    background: rgba(23, 16, 12, 0.76);
    color: #f6d66f;
    font-weight: 900;
    box-shadow: 0 0 28px rgba(239, 196, 91, 0.25);
    transition: opacity 180ms ease, transform 180ms ease;
}

.tk-is-battle .tk-vs-mark {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.64);
    pointer-events: none;
}

.tk-is-battle .tk-formation::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 53%;
    z-index: 1;
    width: 9rem;
    height: 10.5rem;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, rgba(255, 232, 158, 0.32), transparent 38%),
        linear-gradient(90deg, transparent, rgba(255, 232, 158, 0.22) 45%, rgba(255, 96, 70, 0.2) 50%, rgba(255, 232, 158, 0.22) 55%, transparent);
    filter: blur(0.5px);
    mix-blend-mode: screen;
    pointer-events: none;
    animation: tkClashGlow 1.05s ease-in-out infinite;
}

.tk-side {
    position: absolute;
    z-index: 2;
    width: calc(50% - 3.25rem);
    top: 52%;
    bottom: auto;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
}

.tk-side-player {
    left: 1rem;
}

.tk-side-npc {
    right: 1rem;
}

.tk-general-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3.4rem;
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(16, 12, 10, 0.64);
    backdrop-filter: blur(10px);
}

.tk-general-banner strong {
    color: var(--tk-text);
    text-align: right;
    min-width: 0;
}

.tk-faction-chip {
    flex: 0 0 auto;
    padding: 0.16rem 0.5rem;
    border-radius: 999px;
    background: rgba(239, 196, 91, 0.18);
    color: #ffeab1;
    font-size: 0.75rem;
    font-weight: 800;
}

.tk-army-line {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0.5rem;
    align-items: flex-end;
}

.tk-unit {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 216px;
    padding: 0.65rem 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(24, 18, 15, 0.72);
    box-shadow: inset 0 0 0 1px rgba(239, 196, 91, 0.08);
    transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
}

.tk-unit-general {
    border-color: rgba(239, 196, 91, 0.34);
    background:
        linear-gradient(180deg, rgba(239, 196, 91, 0.12), rgba(24, 18, 15, 0.78)),
        rgba(24, 18, 15, 0.72);
}

.tk-unit-general .tk-sprite {
    height: 126px;
}

.tk-unit.is-active {
    border-color: rgba(239, 196, 91, 0.85);
    box-shadow: 0 0 28px rgba(239, 196, 91, 0.24), inset 0 0 0 1px rgba(239, 196, 91, 0.32);
}

.tk-unit.is-attacking {
    filter: brightness(1.12);
}

.tk-unit.is-hit {
    animation: tkHitFlash 260ms ease;
}

.tk-unit.is-defeated {
    opacity: 0.5;
    filter: grayscale(0.55);
}

/* A fallen fighter that has finished its drop holds its end pose instead of
   re-triggering the fall animation each time the formation is re-rendered. */
.tk-unit.is-settled .tk-fighter {
    animation: none !important;
    transform: translateY(16px) scaleX(var(--face)) rotate(calc(var(--face) * 72deg));
    opacity: 0.4;
}

/* Once a destroyed fighter has dropped it is removed from the formation flow
   so survivors close ranks and the camera can zoom in on the rest. */
.tk-unit.is-dropped {
    display: none !important;
}

@keyframes tkHitFlash {
    0%, 100% { box-shadow: inset 0 0 0 1px rgba(239, 196, 91, 0.08); }
    30% { box-shadow: inset 0 0 0 2px rgba(229, 93, 79, 0.8), 0 0 18px rgba(229, 93, 79, 0.4); }
}

.tk-sprite {
    position: relative;
    width: 100%;
    height: 116px;
    margin: 0 auto 0.6rem;
    display: grid;
    place-items: end center;
    transition: transform 180ms ease;
}

/* ground disc the fighter stands on */
.tk-sprite::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 4px;
    width: 64px;
    height: 13px;
    transform: translateX(-50%);
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 40%, rgba(239, 196, 91, 0.22), transparent 70%);
}

/* soft cast shadow under the feet */
.tk-sprite::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 6px;
    width: 50px;
    height: 9px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.38);
    filter: blur(1px);
    z-index: 0;
}

.tk-fighter {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 92px;
    height: auto;
    aspect-ratio: 16 / 19;
    transform-origin: 50% 100%;
    --face: 1;
    transform: scaleX(var(--face));
}

/* player faces right (as drawn); the enemy line faces back across the field */
.tk-side-player .tk-fighter { --face: 1; }
.tk-side-npc .tk-fighter { --face: -1; }

/* the currently engaged pair breathes; the rest hold formation */
.tk-unit.is-active .tk-fighter {
    animation: tkBreath 1.5s ease-in-out infinite;
}

@keyframes tkBreath {
    0%, 100% { transform: scaleX(var(--face)) translateY(0); }
    50% { transform: scaleX(var(--face)) translateY(-3px); }
}

/* lunge toward the enemy on attack (direction follows --face) */
.tk-unit.is-attacking .tk-fighter {
    animation: tkLunge 260ms ease;
}

@keyframes tkLunge {
    0% { transform: translateX(0) scaleX(var(--face)); }
    42% { transform: translateX(calc(var(--face) * 18px)) translateY(-4px) scaleX(var(--face)); }
    100% { transform: translateX(0) scaleX(var(--face)); }
}

/* recoil away from the blow + a steel flash */
.tk-unit.is-hit .tk-fighter {
    animation: tkRecoil 260ms ease;
}

@keyframes tkRecoil {
    0%, 100% { transform: translateX(0) scaleX(var(--face)); filter: none; }
    30% { transform: translateX(calc(var(--face) * -8px)) scaleX(var(--face)); filter: brightness(1.7) saturate(0.35); }
}

@keyframes tkClashGlow {
    0%, 100% { opacity: 0.34; transform: translate(-50%, -50%) scale(0.92); }
    50% { opacity: 0.72; transform: translate(-50%, -50%) scale(1.08); }
}

.tk-is-battle .tk-side-player .tk-unit.is-active .tk-sprite {
    transform: translateX(10px);
}

.tk-is-battle .tk-side-npc .tk-unit.is-active .tk-sprite {
    transform: translateX(-10px);
}

/* topple over when routed */
.tk-unit.is-defeated .tk-fighter {
    animation: tkFall 520ms ease forwards;
}

@keyframes tkFall {
    to {
        transform: translateY(16px) scaleX(var(--face)) rotate(calc(var(--face) * 72deg));
        opacity: 0.4;
    }
}

.tk-unit-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-bottom: 0.45rem;
    color: #fff7e4;
    font-size: 0.92rem;
    font-weight: 800;
}

.tk-slot-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.55rem;
    height: 1.55rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #f8e1a2;
    font-size: 0.74rem;
}

.tk-hp {
    height: 0.55rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.tk-hp span {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #4ed26f, #f2c94c, #e45d4f);
    transition: width 240ms ease;
}

.tk-unit-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
    margin-top: 0.55rem;
    color: var(--tk-muted);
    font-size: 0.7rem;
}

.tk-unit-stats span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tk-battle-console,
.tk-draft-panel,
.tk-rank-panel {
    border: 1px solid var(--tk-line);
    border-radius: 8px;
    background: var(--tk-panel);
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.14);
}

.tk-battle-console {
    margin-top: 1rem;
    padding: 0.85rem;
}

.tk-speed-row {
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.tk-speed-row > span {
    padding: 0 0.45rem;
    color: var(--tk-muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.tk-battle-log {
    height: 7.3rem;
    overflow: auto;
    padding-right: 0.4rem;
    color: #eadfc7;
    font-size: 0.86rem;
    line-height: 1.5;
}

.tk-quote-card {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    z-index: 5;
    width: min(88%, 580px);
    padding: 0.8rem 1rem;
    transform: translateX(-50%);
    border: 1px solid rgba(239, 196, 91, 0.46);
    border-radius: 8px;
    background: rgba(18, 13, 10, 0.82);
    color: #fff7df;
    text-align: center;
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    pointer-events: none;
    animation: tkQuotePop 220ms ease-out;
}

.tk-quote-card span {
    display: block;
    color: #f6d66f;
    font-size: 0.76rem;
    font-weight: 900;
}

.tk-quote-card strong {
    display: block;
    margin-top: 0.22rem;
    font-size: 1.04rem;
    line-height: 1.35;
}

.tk-quote-card.is-win {
    border-color: rgba(141, 240, 160, 0.58);
    box-shadow: 0 16px 36px rgba(21, 101, 50, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tk-quote-card.is-loss {
    border-color: rgba(255, 154, 141, 0.6);
    box-shadow: 0 16px 36px rgba(151, 44, 36, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tk-quote-card.is-awaiting::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -0.72rem;
    width: 0;
    height: 0;
    transform: translateX(-50%);
    border-left: 0.42rem solid transparent;
    border-right: 0.42rem solid transparent;
    border-top: 0.62rem solid #f6d66f;
    filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.45));
    animation: tkResumeTriangle 820ms ease-in-out infinite;
}

@keyframes tkQuotePop {
    from {
        opacity: 0;
        transform: translate(-50%, 0.65rem);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes tkResumeTriangle {
    0%,
    100% {
        opacity: 0.58;
        transform: translate(-50%, -0.1rem);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, 0.22rem);
    }
}

.tk-log-line {
    padding: 0.16rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tk-log-win {
    color: #8df0a0;
}

.tk-log-loss {
    color: #ff9a8d;
}

.tk-log-special {
    color: #f6d66f;
}

.tk-draft-panel,
.tk-rank-panel {
    padding: 0.85rem;
}

.tk-panel-section + .tk-panel-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tk-section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.tk-section-title h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.15;
}

.tk-section-title span {
    color: var(--tk-muted);
    font-size: 0.76rem;
    white-space: nowrap;
}

.tk-general-grid {
    display: grid;
    gap: 0.55rem;
}

.tk-general-card,
.tk-troop-card,
.tk-ranking-list li,
.tk-share-card {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
}

.tk-general-card {
    width: 100%;
    min-height: 6.7rem;
    padding: 0.75rem;
    color: var(--tk-text);
    text-align: left;
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
    box-shadow: none;
}

.tk-general-card:hover,
.tk-general-card.is-selected {
    transform: translateY(-2px);
    border-color: rgba(239, 196, 91, 0.75);
    background: rgba(239, 196, 91, 0.13);
}

.tk-general-card strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #fff7df;
    font-size: 1.02rem;
}

.tk-general-card small,
.tk-general-card span {
    color: var(--tk-muted);
}

.tk-general-card p {
    margin: 0.45rem 0 0;
    color: #eadcc3;
    font-size: 0.78rem;
    line-height: 1.35;
}

.tk-faction-wei {
    --faction-color: #5a86cb;
}

.tk-faction-shu {
    --faction-color: #42b56b;
}

.tk-faction-wu {
    --faction-color: #d7594f;
}

.tk-general-card::before {
    content: "";
    display: block;
    width: 100%;
    height: 0.22rem;
    margin-bottom: 0.55rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--faction-color, #efc45b), transparent);
}

.tk-troop-list {
    display: grid;
    gap: 0.5rem;
}

.tk-troop-card {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    min-height: 4.2rem;
    padding: 0.55rem;
    color: var(--tk-text);
    cursor: grab;
}

.tk-troop-card:active {
    cursor: grabbing;
}

.tk-troop-card.is-dragging {
    opacity: 0.5;
}

.tk-troop-token {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 6px;
    background: var(--unit-color, var(--tk-gold));
    color: #fff;
    font-weight: 900;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.tk-troop-copy {
    min-width: 0;
}

.tk-troop-copy strong {
    display: block;
    color: #fff7df;
    line-height: 1.15;
}

.tk-troop-copy span {
    display: block;
    color: var(--tk-muted);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tk-order-buttons {
    display: inline-flex;
    gap: 0.25rem;
}

.tk-order-buttons button {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff1ce;
    box-shadow: none;
    cursor: pointer;
}

.tk-order-buttons button:disabled {
    opacity: 0.35;
    cursor: default;
}

.tk-start-button,
.tk-copy-button {
    width: 100%;
    min-height: 2.8rem;
    margin-top: 0.8rem;
    border: 0;
    border-radius: 8px;
    color: #23170d;
    background: linear-gradient(135deg, #f1c857, #e98546);
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(224, 132, 63, 0.22);
}

.tk-start-button:disabled {
    opacity: 0.45;
    cursor: default;
    box-shadow: none;
}

.tk-matchups {
    display: grid;
    gap: 0.4rem;
}

.tk-matchup-row {
    display: grid;
    grid-template-columns: 4rem minmax(0, 1fr);
    gap: 0.45rem;
    align-items: center;
    color: #eadcc3;
    font-size: 0.76rem;
}

.tk-matchup-row strong {
    color: #fff7df;
}

.tk-rank-tabs {
    width: 100%;
    margin-bottom: 0.75rem;
}

.tk-rank-tabs button {
    flex: 1 1 0;
}

.tk-ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
}

.tk-ranking-list li {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: center;
    min-height: 4.1rem;
    padding: 0.55rem;
}

.tk-rank-num {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(239, 196, 91, 0.18);
    color: #f7da8b;
    font-weight: 900;
}

.tk-rank-main {
    min-width: 0;
}

.tk-rank-main strong {
    display: block;
    color: #fff7df;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tk-rank-main span {
    display: block;
    color: var(--tk-muted);
    font-size: 0.73rem;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tk-rank-main .tk-rank-icons {
    display: flex;
    align-items: flex-end;
    gap: 0.2rem;
    min-width: 0;
    margin-top: 0.32rem;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}

.tk-rank-main .tk-rank-chip {
    display: grid;
    place-items: end center;
    flex: 0 0 auto;
    width: 1.25rem;
    height: 1.5rem;
    overflow: visible;
    font-size: 0;
    line-height: 1;
    --face: 1;
}

.tk-rank-main .tk-rank-chip-general {
    width: 1.45rem;
    height: 1.7rem;
}

.tk-ranking-list .tk-rank-chip .tk-fighter {
    width: 100%;
    max-width: 100%;
    animation: none;
    transform: scaleX(var(--face));
    filter:
        drop-shadow(0.8px 0 0 rgba(16, 12, 10, 0.9))
        drop-shadow(-0.8px 0 0 rgba(16, 12, 10, 0.9))
        drop-shadow(0 0.8px 0 rgba(16, 12, 10, 0.9));
}

.tk-rank-wins {
    color: #8df0a0;
    font-weight: 900;
    white-space: nowrap;
}

.tk-empty-rank {
    color: var(--tk-muted);
    text-align: center;
    padding: 1rem 0.5rem;
}

.tk-share-card {
    margin-top: 0.85rem;
    padding: 0.75rem;
}

.tk-share-card strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #fff7df;
}

.tk-share-card p {
    margin: 0;
    color: #eadcc3;
    font-size: 0.8rem;
    line-height: 1.35;
}

.tk-art-prompt {
    margin-top: 0.75rem;
    padding: 0.7rem 0.65rem;
    border: 1px solid rgba(239, 196, 91, 0.24);
    border-radius: 8px;
    background: rgba(12, 9, 8, 0.32);
    text-align: center;
}

.tk-art-prompt-text {
    margin: 0 0 0.55rem;
    color: #f6d66f;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.35;
}

.tk-art-prompt-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.tk-art-prompt-btn {
    flex: 1 1 0;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    border: 1px solid rgba(239, 196, 91, 0.4);
    background: rgba(239, 196, 91, 0.1);
    color: #f6d66f;
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.tk-art-prompt-btn:hover {
    background: rgba(239, 196, 91, 0.2);
    border-color: rgba(239, 196, 91, 0.6);
}

.tk-art-prompt-btn:active {
    transform: translateY(1px);
}

.tk-art-prompt-yes {
    color: #8df0a0;
    border-color: rgba(141, 240, 160, 0.4);
    background: rgba(141, 240, 160, 0.1);
}

.tk-art-prompt-yes:hover {
    background: rgba(141, 240, 160, 0.2);
    border-color: rgba(141, 240, 160, 0.6);
}

/* 아니요 is the default action, so give it focus emphasis. */
.tk-art-prompt-no.is-default:focus,
.tk-art-prompt-no.is-default:focus-visible {
    outline: 2px solid rgba(246, 214, 111, 0.7);
    outline-offset: 2px;
}

.tk-defeat-art {
    margin-top: 0.75rem;
    overflow: hidden;
    border: 1px solid rgba(239, 196, 91, 0.24);
    border-radius: 8px;
    background: rgba(12, 9, 8, 0.32);
}

.tk-art-status {
    padding: 0.55rem 0.6rem;
    color: #f6d66f;
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1.35;
}

.tk-defeat-art.is-error .tk-art-status {
    color: #ff9a8d;
}

.tk-defeat-art.is-ready .tk-art-status {
    color: #8df0a0;
}

.tk-art-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #15100d;
}

/* Reserve the square only while generating or once the art is ready;
   on error (or idle) there is no image, so collapse the frame. */
.tk-defeat-art:not(.is-loading):not(.is-ready) .tk-art-frame {
    display: none;
}

.tk-art-loader {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: none;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 42%, rgba(239, 196, 91, 0.14), rgba(12, 9, 8, 0) 62%),
        #15100d;
}

.tk-defeat-art.is-loading .tk-art-loader {
    display: flex;
}

/* sweeping shimmer to sell the "generating" feel */
.tk-art-loader::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 32%, rgba(239, 196, 91, 0.16) 50%, transparent 68%);
    transform: translateX(-100%);
    animation: tkArtShimmer 1.6s ease-in-out infinite;
}

.tk-art-spinner {
    position: relative;
    z-index: 1;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid rgba(239, 196, 91, 0.22);
    border-top-color: #f6d66f;
    animation: tkArtSpin 0.85s linear infinite;
}

@keyframes tkArtSpin {
    to { transform: rotate(360deg); }
}

@keyframes tkArtShimmer {
    0% { transform: translateX(-100%); }
    60%, 100% { transform: translateX(100%); }
}

/* gently pulse the status text while we wait */
.tk-defeat-art.is-loading .tk-art-status {
    animation: tkArtStatusPulse 1.4s ease-in-out infinite;
}

@keyframes tkArtStatusPulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

.tk-defeat-art img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #15100d;
}

/* Honor the hidden attribute — the rule above would otherwise force the
   empty <img> to render as a broken-image box during generation. */
.tk-defeat-art img[hidden] {
    display: none;
}

.tk-copy-button {
    min-height: 2.35rem;
    font-size: 0.82rem;
}

.tk-type-infantry { --unit-color: #4f9d67; --unit-dark: #2f6b43; --unit-light: #79c08f; }
.tk-type-spear { --unit-color: #b88a35; --unit-dark: #7d5c1f; --unit-light: #e0b463; }
.tk-type-cavalry { --unit-color: #c9584a; --unit-dark: #8a3329; --unit-light: #e88577; }
.tk-type-archer { --unit-color: #4f83c7; --unit-dark: #2f568f; --unit-light: #84acdf; }
.tk-type-shield { --unit-color: #8a6dbd; --unit-dark: #5a4185; --unit-light: #b49adf; }
.tk-type-general { --unit-color: #efc45b; --unit-dark: #8f6030; --unit-light: #ffe38a; }
.tk-unit.tk-faction-wei { --unit-color: #5a86cb; --unit-dark: #2f568f; --unit-light: #99bae9; }
.tk-unit.tk-faction-shu { --unit-color: #42b56b; --unit-dark: #2f6b43; --unit-light: #85d99f; }
.tk-unit.tk-faction-wu { --unit-color: #d7594f; --unit-dark: #8a3329; --unit-light: #ee9488; }

/* ---- MAX: character-first cinematic battlefield, no cards ---- */
.tk-mode-max .tk-arena::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 50%, transparent 0 25%, rgba(0, 0, 0, 0.18) 58%, rgba(0, 0, 0, 0.5) 100%),
        linear-gradient(90deg, rgba(201, 78, 63, 0.2), transparent 34% 66%, rgba(61, 166, 107, 0.17));
    mix-blend-mode: screen;
}

.tk-mode-max .tk-skyline {
    display: none;
}

.tk-mode-max .tk-fighter {
    max-width: 104px;
    filter:
        drop-shadow(1.2px 0 0 rgba(16, 12, 10, 0.95))
        drop-shadow(-1.2px 0 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 1.2px 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 -1.2px 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 6px 6px rgba(0, 0, 0, 0.55));
}

.tk-mode-max .tk-unit.is-active .tk-fighter {
    filter:
        drop-shadow(1.2px 0 0 rgba(16, 12, 10, 0.95))
        drop-shadow(-1.2px 0 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 1.2px 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 -1.2px 0 rgba(16, 12, 10, 0.95))
        drop-shadow(0 6px 7px rgba(0, 0, 0, 0.6))
        drop-shadow(0 0 14px rgba(239, 196, 91, 0.5));
}

.tk-mode-max .tk-unit.is-active .tk-sprite::before {
    background: radial-gradient(circle at 50% 45%, rgba(239, 196, 91, 0.5), transparent 70%);
}

.tk-mode-max .tk-arena {
    min-height: 540px;
    border-color: rgba(239, 196, 91, 0.34);
    background:
        radial-gradient(95% 80% at 50% 4%, rgba(255, 223, 151, 0.18), transparent 44%),
        linear-gradient(180deg, rgba(12, 9, 8, 0.08) 0%, rgba(12, 9, 8, 0.04) 42%, rgba(14, 8, 5, 0.48) 100%),
        var(--tk-battle-bg, url("/images/three_kingdoms/battlefield-pass.webp")),
        linear-gradient(180deg, #33302d 0%, #1b1919 34%, #14100e 58%, #3b2819 100%);
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    box-shadow:
        inset 0 0 110px rgba(0, 0, 0, 0.6),
        inset 0 -36px 70px rgba(99, 54, 24, 0.38),
        0 18px 44px rgba(0, 0, 0, 0.18);
}

.tk-mode-max .tk-arena::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    height: 42%;
    pointer-events: none;
    background:
        radial-gradient(70% 44% at 50% 82%, rgba(239, 196, 91, 0.16), transparent 62%),
        linear-gradient(180deg, transparent, rgba(18, 12, 9, 0.72));
}

.tk-mode-max .tk-formation {
    width: 860px;
    height: 340px;
    top: 58%;
}

.tk-mode-max .tk-side {
    width: calc(50% - 3.65rem);
}

.tk-mode-max .tk-army-line {
    gap: 0.2rem;
}

.tk-mode-max .tk-unit,
.tk-mode-max .tk-unit-general,
.tk-mode-max .tk-unit.is-active {
    min-height: 300px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}

.tk-mode-max .tk-unit::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 32px;
    width: 82px;
    height: 28px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: radial-gradient(circle at 50% 45%, rgba(239, 196, 91, 0.24), rgba(239, 196, 91, 0.04) 48%, transparent 70%);
    opacity: 0.75;
    filter: blur(1px);
}

.tk-mode-max .tk-unit.is-active::before {
    width: 108px;
    opacity: 1;
    background: radial-gradient(circle at 50% 45%, rgba(239, 196, 91, 0.48), rgba(239, 196, 91, 0.1) 54%, transparent 74%);
    animation: tkGroundPulse 1.1s ease-in-out infinite;
}

.tk-mode-max .tk-unit.is-defeated::before {
    opacity: 0.2;
}

.tk-mode-max .tk-sprite,
.tk-mode-max .tk-unit-general .tk-sprite {
    height: 230px;
    margin: 0 auto 0;
}

.tk-mode-max .tk-fighter {
    max-width: 152px;
    filter:
        drop-shadow(1.6px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(-1.6px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 1.6px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 -1.6px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 12px 10px rgba(0, 0, 0, 0.62))
        drop-shadow(0 0 14px rgba(239, 196, 91, 0.12));
    animation: tkCombatIdle 1.9s ease-in-out infinite;
}

.tk-mode-max .tk-unit-general .tk-fighter {
    max-width: 178px;
    filter:
        drop-shadow(1.8px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(-1.8px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 1.8px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 -1.8px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 14px 12px rgba(0, 0, 0, 0.7))
        drop-shadow(0 0 18px rgba(239, 196, 91, 0.28));
}

.tk-mode-max .tk-unit.is-active .tk-fighter {
    filter:
        drop-shadow(1.8px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(-1.8px 0 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 1.8px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 -1.8px 0 rgba(10, 8, 7, 0.98))
        drop-shadow(0 14px 12px rgba(0, 0, 0, 0.72))
        drop-shadow(0 0 24px rgba(239, 196, 91, 0.58));
    animation: tkCombatReady 0.86s ease-in-out infinite;
}

.tk-mode-max .tk-unit.is-attacking .tk-fighter {
    animation: tkMaxStrike 310ms cubic-bezier(.2, .8, .16, 1);
}

/* No card-style red hit box in cinematic MAX mode — the sprite recoil and the
   on-canvas FX already convey the blow. */
.tk-mode-max .tk-unit.is-hit {
    animation: none;
}

.tk-mode-max .tk-unit.is-hit .tk-fighter {
    animation: tkMaxRecoil 320ms ease;
}

.tk-mode-max .tk-unit.is-defeated .tk-fighter {
    animation: tkMaxFall 680ms ease forwards;
}

.tk-mode-max .tk-unit.is-settled .tk-fighter {
    transform: translateY(44px) scaleX(var(--face)) rotate(calc(var(--face) * 82deg));
    opacity: 0.24;
    filter: grayscale(0.75) brightness(0.72);
}

.tk-mode-max .tk-unit-title {
    position: absolute;
    left: 50%;
    bottom: 16px;
    z-index: 3;
    transform: translateX(-50%);
    justify-content: center;
    width: max-content;
    max-width: 96px;
    min-height: 1.45rem;
    margin: 0;
    padding: 0.08rem 0.45rem;
    border: 1px solid rgba(239, 196, 91, 0.2);
    border-radius: 999px;
    background: rgba(12, 9, 8, 0.58);
    color: #fff3d6;
    font-size: 0.78rem;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    backdrop-filter: blur(5px);
}

.tk-mode-max .tk-slot-badge {
    display: none;
}

.tk-mode-max .tk-hp {
    position: absolute;
    left: 50%;
    bottom: 5px;
    z-index: 3;
    width: 72%;
    max-width: 82px;
    height: 0.42rem;
    transform: translateX(-50%);
    border: 1px solid rgba(0, 0, 0, 0.28);
    background: rgba(8, 6, 5, 0.68);
    box-shadow: 0 0 9px rgba(0, 0, 0, 0.36);
}

.tk-mode-max .tk-unit-stats {
    display: none;
}

@keyframes tkGroundPulse {
    0%, 100% { transform: translateX(-50%) scaleX(0.92); opacity: 0.72; }
    50% { transform: translateX(-50%) scaleX(1.14); opacity: 1; }
}

@keyframes tkCombatIdle {
    0%, 100% { transform: scaleX(var(--face)) translateY(0) rotate(calc(var(--face) * -1deg)); }
    50% { transform: scaleX(var(--face)) translateY(-5px) rotate(calc(var(--face) * 1deg)); }
}

@keyframes tkCombatReady {
    0%, 100% { transform: scaleX(var(--face)) translateY(-3px) rotate(calc(var(--face) * -3deg)); }
    50% { transform: scaleX(var(--face)) translateY(-10px) rotate(calc(var(--face) * 3deg)); }
}

@keyframes tkMaxStrike {
    0% { transform: scaleX(var(--face)) translateX(0) translateY(-4px) rotate(calc(var(--face) * -4deg)); }
    34% { transform: scaleX(var(--face)) translateX(calc(var(--face) * 34px)) translateY(-24px) rotate(calc(var(--face) * 12deg)) scale(1.08); }
    70% { transform: scaleX(var(--face)) translateX(calc(var(--face) * 14px)) translateY(2px) rotate(calc(var(--face) * -8deg)) scale(1.02); }
    100% { transform: scaleX(var(--face)) translateX(0) translateY(0) rotate(0); }
}

@keyframes tkMaxRecoil {
    0%, 100% { transform: scaleX(var(--face)) translateX(0); filter: none; }
    22% { transform: scaleX(var(--face)) translateX(calc(var(--face) * -18px)) translateY(-8px) rotate(calc(var(--face) * -9deg)); filter: brightness(2) saturate(0.25); }
    58% { transform: scaleX(var(--face)) translateX(calc(var(--face) * 6px)) rotate(calc(var(--face) * 4deg)); }
}

@keyframes tkMaxFall {
    to {
        transform: translateY(44px) scaleX(var(--face)) rotate(calc(var(--face) * 82deg));
        opacity: 0.24;
        filter: grayscale(0.75) brightness(0.72);
    }
}

@media screen and (max-width: 1280px) {
    .tk-layout {
        grid-template-columns: minmax(0, 1fr) 320px;
    }

    .tk-rank-panel {
        grid-column: 1 / -1;
    }
}

@media screen and (max-width: 980px) {
    .tk-page {
        width: min(100% - 1rem, 760px);
        padding-top: 1.25rem;
    }

    .tk-commandbar {
        grid-template-columns: 1fr;
    }

    .tk-run-stats,
    .tk-controls {
        justify-content: flex-start;
    }

    .tk-layout {
        grid-template-columns: 1fr;
    }

    .tk-arena {
        min-height: 420px;
    }

    .tk-side {
        width: calc(50% - 2.75rem);
    }

    .tk-army-line {
        gap: 0.4rem;
    }

    .tk-unit {
        min-height: 176px;
        padding: 0.5rem 0.4rem;
    }

    .tk-sprite,
    .tk-unit-general .tk-sprite {
        height: 92px;
    }

    .tk-unit-stats {
        display: none;
    }
}

@media screen and (max-width: 640px) {
    .tk-page {
        width: calc(100% - 0.6rem);
    }

    .tk-commandbar,
    .tk-battle-console,
    .tk-draft-panel,
    .tk-rank-panel {
        padding: 0.7rem;
    }

    .tk-controls {
        align-items: stretch;
    }

    #tk-player-name {
        width: 100%;
    }

    .tk-icon-button {
        flex: 1 1 0;
        justify-content: center;
    }

    .tk-arena {
        min-height: 340px;
        overflow: hidden;
    }

    .tk-vs-mark {
        top: 50%;
        width: 3.5rem;
        height: 3.5rem;
        font-size: 0.9rem;
    }

    .tk-quote-card {
        bottom: 0.65rem;
        width: calc(100% - 1.2rem);
        padding: 0.65rem 0.75rem;
    }

    .tk-quote-card strong {
        font-size: 0.92rem;
    }

    .tk-side {
        width: calc(50% - 2.75rem);
        height: auto;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
    }

    .tk-side-player {
        left: 1rem;
    }

    .tk-side-npc {
        right: 1rem;
    }

    .tk-army-line {
        gap: 0.4rem;
    }

    .tk-unit {
        min-height: 162px;
        padding: 0.45rem;
    }

    .tk-sprite,
    .tk-unit-general .tk-sprite {
        height: 78px;
        margin-bottom: 0.45rem;
    }

    .tk-fighter,
    .tk-mode-max .tk-fighter {
        max-width: 60px;
    }

    .tk-unit-title {
        font-size: 0.75rem;
        align-items: flex-start;
    }

    .tk-slot-badge {
        width: 1.25rem;
        height: 1.25rem;
        font-size: 0.65rem;
    }

    .tk-troop-card {
        grid-template-columns: 2rem minmax(0, 1fr);
    }

    .tk-order-buttons {
        grid-column: 1 / -1;
        width: 100%;
    }

    .tk-order-buttons button {
        flex: 1 1 0;
    }
}

@media screen and (max-width: 640px) {
    .tk-mode-max .tk-arena {
        min-height: 390px;
    }

    .tk-mode-max .tk-formation {
        width: 860px;
        height: 340px;
    }

    .tk-mode-max .tk-unit,
    .tk-mode-max .tk-unit-general {
        min-height: 292px;
        padding: 0;
    }

    .tk-mode-max .tk-sprite,
    .tk-mode-max .tk-unit-general .tk-sprite {
        height: 220px;
        margin-bottom: 0;
    }

    .tk-mode-max .tk-fighter {
        max-width: 138px;
    }

    .tk-mode-max .tk-unit-general .tk-fighter {
        max-width: 158px;
    }

    .tk-mode-max .tk-unit-title {
        bottom: 17px;
        align-items: center;
        max-width: 92px;
        font-size: 0.76rem;
    }

    .tk-mode-max .tk-hp {
        bottom: 5px;
        max-width: 76px;
    }
}
