/* ═══════════════════════════════════════════════════
   Format Builder — Visual Tournament Structure Editor
   ═══════════════════════════════════════════════════ */

/* ── Canvas container ── */
.fb-canvas {
    position: relative;
    min-height: 400px;
    overflow: auto;
    padding: 2rem;
    background:
        radial-gradient(circle, var(--dc-slate-300) 1px, transparent 1px);
    background-size: 24px 24px;
    border: 1px solid var(--dc-border);
    border-radius: var(--dc-radius-lg);
}

/* ── Grid layout for phases ── */
.fb-grid {
    display: grid;
    gap: 4rem 6rem;
    position: relative;
    z-index: 1;
}

/* ── SVG arrow overlay ── */
.fb-arrows {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 100%;
    min-height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 2;
}

.fb-arrows path {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
}

.fb-arrows path.fb-arrow-win {
    stroke: var(--dc-success);
}

.fb-arrows path.fb-arrow-lose {
    stroke: var(--dc-danger);
}

.fb-arrows path.fb-arrow-rank {
    stroke: var(--dc-info);
}

.fb-arrows path.fb-arrow-complete {
    stroke: var(--dc-slate-500);
}

.fb-arrows path.fb-arrow-interactive {
    pointer-events: stroke;
    cursor: pointer;
    stroke-width: 3;
}

.fb-arrows path.fb-arrow-interactive:hover {
    stroke-width: 4;
    filter: brightness(1.2);
}

/* Arrow markers */
.fb-marker-win {
    fill: var(--dc-success);
}

.fb-marker-lose {
    fill: var(--dc-danger);
}

.fb-marker-rank {
    fill: var(--dc-info);
}

.fb-marker-complete {
    fill: var(--dc-slate-500);
}

/* Arrow labels */
.fb-arrow-label {
    pointer-events: none;
    font-size: 0.6875rem;
    font-weight: 600;
}

.fb-arrow-label-win {
    fill: var(--dc-success);
}

.fb-arrow-label-lose {
    fill: var(--dc-danger);
}

.fb-arrow-label-rank {
    fill: var(--dc-info);
}

.fb-arrow-label-complete {
    fill: var(--dc-slate-500);
}

/* ── Phase card ── */
.fb-phase {
    background: var(--dc-card-bg);
    border: 2px solid var(--dc-border);
    border-radius: var(--dc-radius-lg);
    min-width: 280px;
    max-width: 420px;
    box-shadow: var(--dc-shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
    position: relative;
}

.fb-phase:hover {
    border-color: var(--dc-orange-mid);
    box-shadow: var(--dc-shadow-md);
}

/* Connection target state — pulsing border when in linking mode */
.fb-phase-target {
    border-color: var(--dc-info);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    cursor: pointer;
    animation: fb-pulse 1.5s ease-in-out infinite;
}

@keyframes fb-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
    50% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.08); }
}

.fb-phase-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--dc-border);
    border-left: 3px solid var(--dc-orange);
    border-radius: var(--dc-radius-lg) var(--dc-radius-lg) 0 0;
    background: var(--dc-slate-50);
}

.fb-phase-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--dc-slate-800);
}

.fb-phase-subtitle {
    font-size: 0.75rem;
    color: var(--dc-text-muted);
    margin-top: 0.125rem;
}

.fb-phase-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.fb-phase-body {
    padding: 0.75rem 1rem;
}

/* ── Groups inside a phase ── */
.fb-groups {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.fb-group {
    flex: 1;
    min-width: 120px;
    border: 1px solid var(--dc-slate-200);
    border-radius: var(--dc-radius);
    background: white;
    overflow: hidden;
}

.fb-group-header {
    padding: 0.375rem 0.625rem;
    background: var(--dc-slate-100);
    border-bottom: 1px solid var(--dc-slate-200);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--dc-slate-700);
}

.fb-group-body {
    padding: 0.375rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* ── Brackets inside a group ── */
.fb-bracket {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--dc-slate-50);
    border-radius: 0.25rem;
    border: 1px solid var(--dc-slate-200);
    font-size: 0.75rem;
}

.fb-bracket-name {
    font-weight: 500;
    color: var(--dc-slate-700);
}

.fb-bracket-length {
    color: var(--dc-text-muted);
    font-size: 0.6875rem;
}

/* ── Add buttons ── */
.fb-add-phase {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 280px;
    min-height: 120px;
    border: 2px dashed var(--dc-slate-300);
    border-radius: var(--dc-radius-lg);
    cursor: pointer;
    color: var(--dc-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    background: transparent;
}

.fb-add-phase:hover {
    border-color: var(--dc-orange);
    color: var(--dc-orange);
    background: var(--dc-orange-light);
}

/* Highlighted state when in connection mode */
.fb-add-phase-active {
    border-color: var(--dc-success);
    color: var(--dc-success);
    background: rgba(34, 197, 94, 0.05);
    animation: fb-pulse-green 1.5s ease-in-out infinite;
}

.fb-add-phase-active:hover {
    border-color: var(--dc-success);
    color: var(--dc-success);
    background: rgba(34, 197, 94, 0.12);
}

@keyframes fb-pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
    50% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.1); }
}

.fb-add-phase .material-icons,
.fb-add-phase .rzi {
    margin-right: 0.375rem;
    font-size: 1.25rem;
}

/* ── Connection anchors ── */
.fb-anchor {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    z-index: 3;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* OUT anchors (right = Winners, bottom = Losers) — clickable, labeled */
.fb-anchor-out {
    background: var(--dc-slate-200);
    border: 2px solid var(--dc-card-bg);
    cursor: crosshair;
}

.fb-anchor-out:hover {
    background: var(--dc-orange);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.fb-anchor-out .fb-anchor-label {
    font-size: 0.5625rem;
    font-weight: 700;
    color: var(--dc-slate-600);
    line-height: 1;
    pointer-events: none;
}

.fb-anchor-out:hover .fb-anchor-label {
    color: white;
}

/* Add-connected-phase anchors — "+" style */
.fb-anchor-add {
    background: var(--dc-success);
    border: 2px solid var(--dc-card-bg);
    cursor: pointer;
    width: 26px;
    height: 26px;
    border-radius: 13px;
}

.fb-anchor-add.fb-anchor-bottom {
    background: var(--dc-danger);
}

.fb-anchor-add:hover {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
    transform: scale(1.2);
}

.fb-anchor-add.fb-anchor-bottom:hover {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
    transform: translateX(-50%) scale(1.2);
}

.fb-anchor-add.fb-anchor-right:hover {
    transform: translateY(-50%) scale(1.2);
}

.fb-anchor-add .fb-anchor-label {
    font-size: 0.5625rem;
    font-weight: 700;
    color: white;
    line-height: 1;
    pointer-events: none;
    letter-spacing: -0.25px;
}

.fb-anchor-add:hover .fb-anchor-label {
    color: white;
}

/* IN anchors (left, top) — passive receive points */
.fb-anchor-in {
    width: 10px;
    height: 10px;
    background: var(--dc-slate-300);
    border: 2px solid var(--dc-card-bg);
}

/* Positional placement */
.fb-anchor-right {
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
}

.fb-anchor-right:hover {
    transform: translateY(-50%) scale(1.15);
}

.fb-anchor-bottom {
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
}

.fb-anchor-bottom:hover {
    transform: translateX(-50%) scale(1.15);
}

.fb-anchor-left {
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
}

.fb-anchor-top {
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
}

.fb-anchor-top:hover {
    transform: translateX(-50%) scale(1.3);
}

/* ── Side panel for detailed editing ── */
.fb-detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    background: var(--dc-card-bg);
    border-left: 1px solid var(--dc-border);
    box-shadow: -4px 0 20px rgba(15, 23, 42, 0.1);
    z-index: 1000;
    overflow-y: auto;
    padding: 1.5rem;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

.fb-detail-panel.open {
    transform: translateX(0);
}

.fb-detail-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--dc-border);
}

.fb-detail-panel-header h4 {
    margin: 0;
    font-size: 1.125rem;
}

.fb-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.3);
    z-index: 999;
}

/* ── Transition dialog ── */
.fb-transition-dialog {
    position: absolute;
    background: var(--dc-card-bg);
    border: 1px solid var(--dc-border);
    border-radius: var(--dc-radius);
    box-shadow: var(--dc-shadow-lg);
    padding: 1rem;
    z-index: 10;
    min-width: 280px;
}

.fb-transition-dialog h5 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
}

/* ── Phase settings summary chips ── */
.fb-chips {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    margin-top: 0.375rem;
}

.fb-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 500;
    background: var(--dc-slate-100);
    color: var(--dc-slate-700);
    border: 1px solid var(--dc-slate-200);
}

/* ── Empty state for groups ── */
.fb-empty-groups {
    padding: 0.75rem;
    text-align: center;
    color: var(--dc-text-muted);
    font-size: 0.8125rem;
    font-style: italic;
}
