/* ======================================================================
   نبرد تصاحب زمین - Territory Battle
   استایل کامل بازی - مقیاس‌پذیر، مناسب موبایل، بدون افکت‌های سنگین
   ====================================================================== */

@font-face {
    font-family: KalamehWebFaNum;
    font-display: block;
    font-style: normal;
    src: url('../../fonts/Abi-FaNum-MediumDot3.woff2') format('woff2');
}

#twb-root, #twb-root * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

#twb-root {
    --twb-bg: #08080d;
    --twb-blue-1: #12b7ea;
    --twb-blue-2: #0b3f8f;
    --twb-blue-glow: rgba(18, 183, 234, .55);
    --twb-red-1: #ff4d63;
    --twb-red-2: #7a1026;
    --twb-red-glow: rgba(255, 77, 99, .55);
    --twb-gold: #ffd166;
    --twb-gold-glow: rgba(255, 209, 102, .75);
    --twb-line: #ffffff;
    --twb-safe-t: env(safe-area-inset-top, 0px);
    --twb-safe-b: env(safe-area-inset-bottom, 0px);
    --twb-safe-l: env(safe-area-inset-left, 0px);
    --twb-safe-r: env(safe-area-inset-right, 0px);

    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    height: calc(var(--twb-vh, 1vh) * 100);
    overflow: hidden;
    background: var(--twb-bg);
    font-family: KalamehWebFaNum, Tahoma, sans-serif;
    direction: rtl;
    color: #fff;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    z-index: 20000;
}

#twb-root, #twb-root button {
    font-family: KalamehWebFaNum, Tahoma, sans-serif;
}

/* ---------------------------------------------------------------------
   صفحات کلی
   --------------------------------------------------------------------- */
.twb-screen {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    height: 100%;
}

.twb-screen.twb-active {
    display: block;
}

/* ---------------------------------------------------------------------
   صفحه شروع
   --------------------------------------------------------------------- */
.twb-start {
    background:
        radial-gradient(circle at 20% 15%, rgba(18, 183, 234, .30), transparent 32%),
        radial-gradient(circle at 82% 85%, rgba(255, 77, 99, .28), transparent 34%),
        linear-gradient(160deg, #0a0a12 0%, #14101a 45%, #0a1614 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(20px, var(--twb-safe-t)) max(18px, var(--twb-safe-r)) max(20px, var(--twb-safe-b)) max(18px, var(--twb-safe-l));
    overflow-y: auto;
}

.twb-start__inner {
    width: 100%;
    max-width: 420px;
    margin:0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
}

.twb-start__title {
    font-size: clamp(1.9rem, 8vw, 2.6rem);
    font-weight: 900;
    margin: 0;
    background: linear-gradient(90deg, var(--twb-blue-1), #fff 45%, var(--twb-red-1));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: .5px;
}

.twb-start__desc {
    font-size: .95rem;
    line-height: 1.9;
    color: rgba(255, 255, 255, .78);
    margin: 0 0 4px;
}

.twb-start__block {
    width: 100%;
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 16px;
    padding: 14px;
}

.twb-start__label {
    display: block;
    font-size: .82rem;
    font-weight: 700;
    color: rgba(255, 255, 255, .65);
    margin-bottom: 10px;
}

.twb-duration-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.twb-duration-btn {
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .05);
    color: #fff;
    font-weight: 800;
    font-size: .92rem;
    border-radius: 10px;
    padding: 10px 6px;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease, transform .12s ease;
}

.twb-duration-btn.twb-active {
    background: linear-gradient(135deg, var(--twb-blue-1), var(--twb-red-1));
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}

.twb-sound-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .05);
    color: #fff;
    font-size: .9rem;
    font-weight: 700;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
}

.twb-sound-toggle[aria-pressed="false"] {
    opacity: .55;
}

.twb-start-btn {
    width: 100%;
    border: none;
    border-radius: 16px;
    padding: 16px;
    font-size: 1.25rem;
    font-weight: 900;
    color: #0a0a12;
    background: linear-gradient(120deg, var(--twb-gold), #fff2c2);
    box-shadow: 0 14px 30px rgba(255, 209, 102, .35);
    cursor: pointer;
    margin-top: 4px;
    transition: transform .12s ease;
}

.twb-start-btn:active {
    transform: scale(.97);
}

/* ---------------------------------------------------------------------
   راهنمای کامل بازی (آکاردئون در صفحه شروع)
   --------------------------------------------------------------------- */
.twb-howto-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    border: 1px dashed rgba(255, 255, 255, .28);
    background: transparent;
    color: rgba(255, 255, 255, .85);
    font-size: .88rem;
    font-weight: 800;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    margin-top: 2px;
}

.twb-howto-caret {
    display: inline-block;
    transition: transform .2s ease;
}

.twb-howto-toggle[aria-expanded="true"] .twb-howto-caret {
    transform: rotate(180deg);
}

.twb-howto-panel {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height .35s ease, opacity .25s ease;
}

.twb-howto-panel.twb-open {
    max-height: 2000px;
    opacity: 1;
}

.twb-howto-inner {
    width: 100%;
    text-align: right;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 14px;
    padding: 14px 16px;
    margin-top: 10px;
}

.twb-howto-section {
    margin-bottom: 14px;
}

.twb-howto-section:last-child {
    margin-bottom: 0;
}

.twb-howto-section h3 {
    font-size: .95rem;
    font-weight: 900;
    color: var(--twb-gold);
    margin: 0 0 6px;
}

.twb-howto-section p {
    font-size: .82rem;
    line-height: 1.9;
    color: rgba(255, 255, 255, .82);
    margin: 0;
}

.twb-howto-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.twb-howto-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.twb-howto-list li span:last-child {
    font-size: .82rem;
    line-height: 1.9;
    color: rgba(255, 255, 255, .82);
}

.twb-howto-list b {
    color: #fff;
}

.twb-howto-icon {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    margin-top: 2px;
}

.twb-howto-icon--normal {
    background: radial-gradient(circle at 35% 30%, #eafcff, var(--twb-blue-1) 55%, #0a5f86 100%);
    box-shadow: 0 0 8px 2px var(--twb-blue-glow);
}

.twb-howto-icon--golden {
    background: radial-gradient(circle at 35% 30%, #fffbe8, var(--twb-gold) 55%, #a86c00 100%);
    box-shadow: 0 0 8px 2px var(--twb-gold-glow);
}

.twb-howto-icon--bomb {
    background: radial-gradient(circle at 35% 30%, #6b6b70, #201f24 60%, #050506 100%);
    border: 2px solid rgba(255, 80, 80, .55);
}

/* ---------------------------------------------------------------------
   صفحه بازی - دو نیمه
   --------------------------------------------------------------------- */
.twb-game {
    background: #050507;
}

.twb-half {
    position: absolute;
    left: 0;
    right: 0;
    width: 100%;
    overflow: hidden;
    transition: none;
}

.twb-half--top {
    top: 0;
    height: 50%;
}

.twb-half--bottom {
    bottom: 0;
    height: 50%;
}

.twb-half--blue {
    background:
        radial-gradient(circle at 50% 100%, var(--twb-blue-glow), transparent 60%),
        linear-gradient(180deg, #061321, #0a2b4a 70%, #0d3d63);
}

.twb-half--red {
    background:
        radial-gradient(circle at 50% 0%, var(--twb-red-glow), transparent 60%),
        linear-gradient(180deg, #3a0d18, #591322 60%, #2a0a12);
}

.twb-half-content {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.twb-flip {
    transform: rotate(180deg);
}

.twb-targets-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* ---------------------------------------------------------------------
   HUD هر بازیکن (امتیاز، دقت، کمبو، درصد زمین)
   --------------------------------------------------------------------- */
.twb-hud {
    position: absolute;
    left: max(10px, var(--twb-safe-l));
    right: max(10px, var(--twb-safe-r));
    bottom: max(8px, var(--twb-safe-b));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    z-index: 5;
}

.twb-hud-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.twb-hud-item {
    font-size: .72rem;
    font-weight: 700;
    background: rgba(0, 0, 0, .32);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 999px;
    padding: 3px 10px;
    color: rgba(255, 255, 255, .9);
    white-space: nowrap;
}

.twb-hud-item b {
    color: #fff;
    font-size: .82rem;
    margin-inline-start: 3px;
}

.twb-territory-pct {
    font-size: 1.5rem;
    font-weight: 900;
    text-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}

.twb-player-name {
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .5px;
    opacity: .7;
    text-transform: uppercase;
}

/* ---------------------------------------------------------------------
   اهداف (هدف معمولی، طلایی، بمب)
   --------------------------------------------------------------------- */
.twb-target {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    touch-action: none;
    transform: translate(-50%, -50%) scale(.4);
    opacity: 0;
    animation: twb-target-in .16s ease-out forwards;
    will-change: transform, opacity;
    z-index: 4;
}

@keyframes twb-target-in {
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.twb-target.twb-target-out {
    animation: twb-target-out .16s ease-in forwards;
}

@keyframes twb-target-out {
    to { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
}

.twb-target--normal {
    background: radial-gradient(circle at 35% 30%, #eafcff, var(--twb-blue-1) 55%, #0a5f86 100%);
    box-shadow: 0 0 16px 4px var(--twb-blue-glow), inset 0 0 10px rgba(255, 255, 255, .5);
    animation: twb-target-in .16s ease-out forwards, twb-pulse 1s ease-in-out infinite .16s;
}

.twb-half--red .twb-target--normal {
    background: radial-gradient(circle at 35% 30%, #fff0f2, var(--twb-red-1) 55%, #7a1026 100%);
    box-shadow: 0 0 16px 4px var(--twb-red-glow), inset 0 0 10px rgba(255, 255, 255, .5);
}

@keyframes twb-pulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.28); }
}

.twb-target--golden {
    background: radial-gradient(circle at 35% 30%, #fffbe8, var(--twb-gold) 55%, #a86c00 100%);
    box-shadow: 0 0 22px 8px var(--twb-gold-glow), inset 0 0 12px rgba(255, 255, 255, .7);
    animation: twb-target-in .12s ease-out forwards, twb-golden-spin 1.1s linear infinite .12s;
}

@keyframes twb-golden-spin {
    0% { filter: brightness(1) saturate(1); }
    50% { filter: brightness(1.5) saturate(1.4); }
    100% { filter: brightness(1) saturate(1); }
}

.twb-target--golden::after {
    content: "★";
    font-size: 1.1rem;
    color: #7a4d00;
    text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
}

.twb-target--bomb {
    background: radial-gradient(circle at 35% 30%, #6b6b70, #201f24 60%, #050506 100%);
    box-shadow: 0 0 14px 4px rgba(0, 0, 0, .65), inset 0 0 8px rgba(255, 60, 60, .35);
    border: 2px solid rgba(255, 80, 80, .55);
}

.twb-target--bomb::after {
    content: "✕";
    font-size: 1.05rem;
    font-weight: 900;
    color: #ff5c5c;
}

.twb-target--bomb.twb-target-fuse {
    animation: twb-target-in .16s ease-out forwards, twb-fuse .45s ease-in-out infinite .16s;
}

@keyframes twb-fuse {
    0%, 100% { box-shadow: 0 0 14px 4px rgba(0, 0, 0, .65), inset 0 0 8px rgba(255, 60, 60, .35); }
    50% { box-shadow: 0 0 20px 8px rgba(255, 60, 60, .5), inset 0 0 10px rgba(255, 90, 90, .55); }
}

/* موج لمس صحیح */
.twb-ripple {
    position: absolute;
    top: 0;
    left: 0;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .85);
    transform: translate(-50%, -50%) scale(1);
    pointer-events: none;
    z-index: 6;
    animation: twb-ripple-anim .5s ease-out forwards;
}

.twb-ripple--gold { border-color: var(--twb-gold); }

@keyframes twb-ripple-anim {
    to { transform: translate(-50%, -50%) scale(9); opacity: 0; }
}

/* افکت انفجار بمب */
.twb-boom {
    position: absolute;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff3d6, #ff8a3d 45%, #ff2e2e 70%, transparent 78%);
    pointer-events: none;
    z-index: 6;
    animation: twb-boom-anim .42s ease-out forwards;
}

@keyframes twb-boom-anim {
    0% { transform: scale(.2); opacity: 1; }
    100% { transform: scale(6.5); opacity: 0; }
}

/* افکت خطای لمس فضای خالی */
.twb-miss-fx {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border-radius: 50%;
    border: 2px solid rgba(255, 70, 70, .85);
    pointer-events: none;
    z-index: 6;
    animation: twb-miss-anim .38s ease-out forwards;
}

@keyframes twb-miss-anim {
    0% { transform: scale(.4); opacity: 1; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ---------------------------------------------------------------------
   خط مرکزی و تایمر
   --------------------------------------------------------------------- */
.twb-center-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 5px;
    margin-top: -2.5px;
    background: linear-gradient(90deg, transparent, var(--twb-line) 12%, var(--twb-line) 88%, transparent);
    box-shadow: 0 0 14px 3px rgba(255, 255, 255, .75);
    z-index: 30;
    pointer-events: none;
}

.twb-center-line::before {
    content: "";
    position: absolute;
    inset: -6px 0;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, .18), transparent);
}

.twb-timer {
    position: absolute;
    left: 50%;
    background: rgba(0, 0, 0, .45);
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 999px;
    padding: 4px 14px;
    font-size: .95rem;
    font-weight: 900;
    color: #fff;
    min-width: 46px;
    text-align: center;
}

.twb-timer--bottom {
    top: 14px;
    transform: translate(-50%, 0);
}

.twb-timer--top {
    bottom: 14px;
    transform: translate(-50%, 0) rotate(180deg);
}

.twb-timer.twb-hidden {
    display: none;
}

.twb-sudden-badge {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    font-size: .8rem;
    font-weight: 900;
    background: linear-gradient(120deg, var(--twb-gold), #ff8a3d);
    color: #1a1200;
    padding: 4px 12px;
    border-radius: 999px;
    display: none;
}

.twb-sudden-badge.twb-active-badge {
    display: block;
}

/* ---------------------------------------------------------------------
   شمارش معکوس
   --------------------------------------------------------------------- */
.twb-countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    font-weight: 900;
    text-shadow: 0 0 30px rgba(255, 255, 255, .7);
    z-index: 10;
    display: none;
    pointer-events: none;
}

.twb-countdown.twb-show {
    display: block;
    animation: twb-count-pop .82s ease-out;
}

@keyframes twb-count-pop {
    0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ---------------------------------------------------------------------
   پیام کمبو و پیام بمب
   --------------------------------------------------------------------- */
.twb-combo-popup, .twb-bomb-msg {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 900;
    z-index: 9;
    pointer-events: none;
    opacity: 0;
    white-space: nowrap;
}

.twb-combo-popup.twb-show {
    animation: twb-combo-pop .78s ease-out;
    color: var(--twb-gold);
    text-shadow: 0 0 18px rgba(255, 209, 102, .8);
}

.twb-bomb-msg.twb-show {
    animation: twb-combo-pop .7s ease-out;
    color: #ff5c5c;
    text-shadow: 0 0 16px rgba(255, 60, 60, .8);
}

@keyframes twb-combo-pop {
    0% { transform: translate(-50%, -50%) scale(.5) translateY(10px); opacity: 0; }
    25% { transform: translate(-50%, -50%) scale(1.15) translateY(0); opacity: 1; }
    75% { transform: translate(-50%, -50%) scale(1) translateY(-6px); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(.9) translateY(-22px); opacity: 0; }
}

/* لرزش نیمه هنگام لمس بمب */
.twb-shake {
    animation: twb-shake-anim .38s ease-in-out;
}

@keyframes twb-shake-anim {
    0%, 100% { transform: translate3d(0, 0, 0); }
    20% { transform: translate3d(-8px, 0, 0); }
    40% { transform: translate3d(7px, 0, 0); }
    60% { transform: translate3d(-5px, 0, 0); }
    80% { transform: translate3d(4px, 0, 0); }
}

/* ---------------------------------------------------------------------
   صفحه نتیجه
   --------------------------------------------------------------------- */
.twb-result {
    background: #050507;
    display: none;
}

.twb-result.twb-active {
    display: flex;
    flex-direction: column;
}

.twb-result-panel {
    position: relative;
    flex: 1 1 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px max(14px, var(--twb-safe-r)) 14px max(14px, var(--twb-safe-l));
    overflow-y: auto;
}

.twb-result-panel--top {
    transform: rotate(180deg);
    background: radial-gradient(circle at 50% 0%, var(--twb-red-glow), transparent 65%), #0d0810;
}

.twb-result-panel--bottom {
    background: radial-gradient(circle at 50% 100%, var(--twb-blue-glow), transparent 65%), #08090d;
}

.twb-result-card {
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.twb-result-winner {
    font-size: 1.5rem;
    font-weight: 900;
    margin: 0 0 4px;
}

.twb-result-winner.twb-win-blue { color: var(--twb-blue-1); }
.twb-result-winner.twb-win-red { color: var(--twb-red-1); }

.twb-result-sub {
    font-size: .8rem;
    color: rgba(255, 255, 255, .65);
    margin: 0 0 14px;
}

.twb-result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.twb-result-grid--simple {
    gap: 12px;
    margin-bottom: 20px;
}

.twb-result-grid--simple .twb-result-stat {
    padding: 14px 8px;
}

.twb-result-grid--simple .twb-result-stat b {
    font-size: 1.7rem;
}

.twb-result-stat {
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px;
    padding: 8px 6px;
}

.twb-result-stat span {
    display: block;
    font-size: .68rem;
    color: rgba(255, 255, 255, .6);
    margin-bottom: 2px;
}

.twb-result-stat b {
    font-size: 1rem;
}

.twb-result-actions {
    display: flex;
    gap: 8px;
}

.twb-btn {
    flex: 1;
    border: none;
    border-radius: 12px;
    padding: 12px 8px;
    font-size: .92rem;
    font-weight: 800;
    cursor: pointer;
}

.twb-btn--primary {
    background: linear-gradient(120deg, var(--twb-gold), #fff2c2);
    color: #1a1200;
}

.twb-btn--secondary {
    background: rgba(255, 255, 255, .08);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .22);
}

/* ---------------------------------------------------------------------
   واکنش‌گرایی
   --------------------------------------------------------------------- */
@media (max-width: 340px) {
    .twb-start__title { font-size: 1.7rem; }
    .twb-territory-pct { font-size: 1.2rem; }
}

@media (min-width: 700px) {
    .twb-start__inner, .twb-result-card { max-width: 460px; }
}
